This wiki entry will explain how to install FreeBSD as an virtual machine with qemu, and more specific: FreeBSD with zfs on the root partition and then copy it to a real partition. First create the qemu image with this command:

$ qemu-img create bsd.img 6G
Formatting 'bsd.img', fmt=raw, size=6291456 kB

As root, load the kqemu module:

# modprobe kqemu
$ ls -l /dev/kqemu
crw-rw---- 1 root qemu 10, 53 2009-07-26 00:17 /dev/kqemu

Install FreeBSD on the virtual hdd, you created before: $ qemu-system-x86_64 bsd.img -cdrom ~/downloads/8.0-BETA2-amd64-disc1.iso -boot d -m 512

In the FreeBSD sysinstall:

Choose custom installation:

-> 3: Partition
A=Use entire disk
MBR: None
-> 4: Label
C (Create) Leave the size
FS (not swap)
/ (mount point)
Q (finish)
-> 5: Distributions
  (Minimal)
-> 6: Media CD/DVD
-> 7: Commit
No swap: Yes
Visit menu: no

Then go back to the host and do(as root):

# mkdir /etc/zfs
# mount -t ufs bsd.img /mnt/mpt1/ -o loop,ro,offset=$((63*512)),ufstype=ufs2

For these steps you need to have the zfs-fuse package installed on you host(http://www.wizy.org/wiki/ZFS_on_FUSE)(also as root):

This will create the pool that freebsd will be installed to: # zpool create freepool /dev/sdXY (Be sure to use the right partition her) And create new filesystems in this pool:

# zfs create freepool/freebsd
# zfs create freepool/freebsd/home
# zfs create freepool/freebsd/home
# zfs create freepool/freebsd/tmp
# zfs create freepool/freebsd/var

Theh copy everything from the qemu image(be sure to preserve=all):

# cp --preserve=all -r /mnt/mpt1/.??* /freepool/freebsd/
# cp --preserve=all -r /mnt/mpt1/* /freepool/freebsd/
# cp /etc/zfs/zpool.cache /freepool/freebsd/boot/zfs

# zpool export freepool
# zpool import -R /mnt/bsd freepool

Set the right mount point for the pool:

# zfs set mountpoint=/ freepool/freebsd

menuentry "FreeBSD" {
          insmod zfs
          search -s -l freepool
          kfreebsd /freebsd@/boot/kernel/kernel
          kfreebsd_module_elf /freebsd@/boot/kernel/opensolaris.ko
          kfreebsd_module_elf /freebsd@/boot/kernel/zfs.ko
          kfreebsd_module /freebsd@/boot/zfs/zpool.cache type=/boot/zfs/zpool.cache
          set kFreeBSD.vfs.root.mountfrom=zfs:freepool/freebsd
}

You can add some boot flags after "kfreebsd /freebsd@/boot/kernel/kernel" for special purpose,e.g. add "-s" to boot to single user mode.The full boot flags list can be found at boot(8)


GrubWiki: GRUB2FreeBSDZFS (last edited 2010-02-16 14:23:27 by snnn)