$Id: moveFreeBSDintoVM.txt,v 1.5 2010/09/06 08:20:52 guru Exp $ How to move a complete FreeBSD installation into a VM Matthias Apitz 1. Preparations in the running FreeBSD system Save the current FreeBSD partition layout to paper, i.e. print: - /etc/fstab - output of 'df -kh' - output of 'bsdlabel ad8s4' (or whatever your disk is) so you later know the sizes you will need in the new VM. Reboot the system to single user mode, run fsck(8) in all file systems and mount them read only, while staying single user. Do dump(8) of all the partitions to some external media you later can use in the VM a) physically and b) could be mounted in FreeBSD. I used an USB disk with an UFS file system on it as /dev/da0s1a: # mount -t ufs /dev/da0s1a /mnt # dump -0au -f /mnt/usr.dump /usr # dump -0au -f /mnt/var.dump /var # dump -0au -f /mnt/root.dump / Finally shutdown the system. 2. Prepare the VM Attach resources big enough to reflect your real system to the VM. I used: RAM: 2 GByte IDE: 164 GByte (as one file in the host) Make sure that the VM's boot order is: 1st CD/DVD, 2nd disk, so you later can easy decide from where to boot by just attaching or not the CD/DVD to the VM, even if the disk has already a MBR. Copy an ISO image of the so called "FreeBSD livefs" to the host and attach this as CD/DVD to the VM 3. Partitioning of the disk This part is a bit tricky because the "FreeBSD livefs" does not really guide through it. Boot from "FreeBSD livefs" and - define country and keyboard - run "standard installation" from the menu - fdisk(8) the disk, use entire disk for FreeBSD - let it install FreeBSD's boot manager - partition the slice to the layout of your old system, i.e. to the following result: /dev/ad0s1a 1 GByte / /dev/ad0s1b 4 GByte swap /dev/ad0s1d 2 GByte /var /dev/ad0s1e 6 GByte /tmp /dev/ad0s1f (rest 146 GByte) /usr - commit the "last chance before scribbling on disk" The installer will now do the real fdisk(8) and BSD-label of the partitions. It will newfs(8) the above file system and try to install FreeBSD in it, which is not on the CD/DVD and which is not what we want. Answer all questions as "NO" to get finally back to the main menu of sysinstall(8) tool. Reboot again into the "FreeBSD livefs" and go to the fixit repair mode menu, start a shell. The above mentioned file systems are created fine and even the boot manager is fine in place (ofc it would not find anything to boot). The file systems are already polluted which things we don't want (because we later will restore from dumps). Run newfs(8) in all file system devices again: # newfs -m 0 -o space /dev/ad0s1a # newfs -m 0 -o space /dev/ad0s1b # newfs -m 0 -o space /dev/ad0s1d # newfs -m 0 -o space /dev/ad0s1e # newfs -m 0 -o space /dev/ad0s1f We now have clean file systems (and boot manager installed). 4. Restore the dumps First restore the old root file system using the booted "FreeBSD livefs", mount the new root as /mnt and the USB disk containing the dumps as /usb: # mount /dev/ad0s1a /mnt # mkdir /usb # mount -t usf -o ro /dev/da0s1a /usb # cd /mnt # restore rf /usb/root.dump # cd / # umount /mnt One could as well restore the other dumps the same way, but it's better to see if the new root file system already boot fine, because restoring the /usr dump will take many hours (in my case 9 hours for 120 GByte), Reset the VM (no need to worry, nothing is mounted), detach the CD/DVD and reboot the old/new root file system into single user mode. Remount the /root writable and restore the /usr dump: # mount -o rw / # mount -t usf -o ro /dev/da0s1a /mnt # mount /dev/ad0s1f /usr # cd /usr # restore rf /mnt/usr.dump (after 9 hours) # mount /dev/ad0s1d /var # cd /var # restore rf /mnt/var.dump Check and edit the /etc/fstab to reflect the new device names (in my original system the disk was /dev/ad0s8 and not /dev/ad0s1). Make /tmp writable for all users # mount /dev/ad0s1e /tmp # chmod 1777 /tmp The system is now installed and should be boot up fine to normal multi user mode, just reboot normally. 5. Final changes Edit some system files to reflect the new VM environment: /etc/rc.conf: The network interface is now em0, and not wlan0. /boot/loader.conf The sound driver which fits with the virtual device provided by VM is snd_es137x, i.e. put the corresponding line snd_es137x_load="YES" into the file /boot/loader.conf Install the vmware-tools for FreeBSD: I've updated the port emulators/open-vm-tools to version open-vm-tools-253928 which compiles, installs and works fine; it provides high resolutions for the Xorg server (diver 'vmware'), just recreate the xorg.conf the normal way: # X -configure # cp /root/xorg.conf.new /etc/X11/xorg.conf STILL TO SOLVE: 1) How to connect the USB video cam, or use the build in in the laptop? The USB video cam is just working out of the box as native. Only Skype does not produce a local picture, neither in the probe window in Options, nor in a call. Remote partner sees me fine. 2) How to configure WLAN in Win7? 3) ... 6. Some notes about performance The host is Dell Precision M4400 with Dual Core CPU of 3.09 GHz and runs Windows 7 Professional. It took 9h to restore a dump of /usr which was produced in ~2h. The compared write performance for a copy of a 8 GByte file is: native in the same hardware as well: $ date ; dd if=XPdisk of=XPdisk.copy ; date jueves, 2 de septiembre de 2010, 08:25:53 CEST 16777216+0 records in 16777216+0 records out 8589934592 bytes transferred in 419.996931 secs (20452375 bytes/sec) jueves, 2 de septiembre de 2010, 08:32:53 CEST VM: $ date ; dd if=XPdisk of=XPdisk.copy ; date jueves, 2 de septiembre de 2010, 08:25:17 CEST 16777216+0 records in 16777216+0 records out 8589934592 bytes transferred in 1491.054456 secs (5760980 bytes/sec) jueves, 2 de septiembre de 2010, 08:50:08 CEST i.e. 7 minutes ./. 25 minutes, three times slower. The boot times are like this (min:secs): 0:56 Windows 7 is ready for login 1:22 Windows desktop is up to launch VM 3:15 FreeBSD is booted to login: 4:42 KDE-3 desktop is up The felt performance in KDE (start of windows, terminals, Evolution, Firefox) is reasonable well.