installing FreeBSD in VMWare-player

Matthias Apitz guru at unixarea.de
Thu Sep 2 13:19:16 UTC 2010


I wrote a small howTo for such a migration for others in the same
situation. Comments/Impromvements are welcome;

Thanks

	matthias


$Id: moveFreeBSDintoVM.txt,v 1.2 2010/09/02 10:55:29 guru Exp $



   How to move a complete FreeBSD installation into a VM
                Matthias Apitz <guru at unixarea.de>


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:

   - network interface is now em0, and not wlan0

/boot/loader.conf

   - sound (still not working)

/etc/X11/xorg.conf

   - recreate the X11 config file the normal way

install the vmware-tools for FreeBSD (still pending)




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.

-- 
Matthias Apitz
t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211
e <guru at unixarea.de> - w http://www.unixarea.de/
Solidarity with the zionistic pirates of Israel?   Not in my  name!
¿Solidaridad con los piratas sionistas de Israel? ¡No en mi nombre!


More information about the freebsd-questions mailing list