Using Dump and Restore to migrate FreeBSD to ESX server

I’ve a number of ¬†legacy machines which need virtualising with Vmware Vsphere5. Mainly they are old servers running software and websites that cannot be ported to modern OS’s and hardware. I thought to get the ball rolling, I’d migrate our old Cacti server in. The process will be done in a few stages;

  1. Create a new VM in Vsphere
  2. Boot into the FreeBSD 9.0 LiveCD
  3. Setup the server for SSH
  4. Prepare the storage
  5. Dump and Restore the data over an SSH tunnel
  6. Final adjustments

Create a new VM in Vsphere

I’m using Vmware Vcenter with my ‘head’ servers, but you can do this with the Vsphere client just as well. Select the size of disk needed – i checked to see if i could reduce the overhead with a ‘df -h’ on the source server. Add the FreeBSD 9.0 CD and ensure its connected when the VM is powered on.

Boot into the LiveCD

Let the installed run until you get a blue screen inviting you to create a LiveCD or carry on with an install. Choose LiveCD, and login as root. there is no password at this point, and as the OS is on a read only disk (ie the CD) it can’t be changed – yet. Before we go much further we need to increase the size of the /tmp partition which by default is very small and is a RAM disk. To do this we’ll drop the mount and create a larger RAM disk:

umount /tmp
mdmfs -M -s256m md1 /tmp

Setup the server for SSH

Firstly, to enable us to contact the server as root we need to make the /etc partition writable. This is done with:

mkdir /tmp/etc
mount_unionfs /tmp/etc /etc

Edit the sshd config file and permit root login:

ee /etc/ssh/sshd_config
==/==
PermitRootLogin yes
==/==

Now start the daemon:

/etc/rc.d/sshd onestart

Now add a root password with the passwd command. Next we’ll add some IP address information. On the vsphere5 freebsd install the driver is the em0 driver, so:

ifconfig em0 inet 192.168.1.90 netmask 255.255.255.0 up
route add default 192.168.1.1

No we can ssh to the vm and stop all the annoying typing at the console.

Prepare the Storage

This can be done in one of 2 methods; the complicated way and the easy way. I chose the easy way which is to use sysinstall.

Type ‘sysinstall’

Select configure, then Fdisk

Were using the whole disk (press A) and the ‘W’ to write, then the boot manager screen follows:

Then back to the config menu to select ‘Label’:

First create the swap partition (4G for this server) with ‘C’, the ‘4G’ then ‘Swap’. After that press ‘C’ again and accept the rest of the disk,¬†select ‘File system’ and make the mount point ‘/’ (root). At this point arrow down to highlight the root partition and change the mount point using the ‘M’ to ‘/mnt’. Now we are ready to go to the source server…

Dump and Restore via an SSH tunnel

Assuming there are 3 partitions that are needed (/, /var, /usr) them we need to do 3 of these:

dump -0 -L -f - / | ssh -l root 192.168.1.90 "cd /mnt ;restore -rf -"
dump -0 -L -f - /var | ssh -l root 192.168.1.90 "cd /mnt/var ;restore -rf -"
dump -0 -L -f - /usr | ssh -l root 192.168.1.90 "cd /mnt/usr ;restore -rf -"

There are a few things to note here on the dump command:

-0 Full backup
-L The system is live so use a snapshot
-f - send the output to stdout

On the restore

-r rebuild filesystem
-f - output to stdout

It’s very important that the restore is done from the destination partition, hence the ‘cd xxx;’ in the restore command.

Final Adjustments

We need to modify the ‘/etc/fstab’ file to ensure the device names are correct and the number of partitions is correct. In my example i’ve moved from a multi partition setup with separate /var, /usr etc to a single root partition. My old fstab looked like this:

# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/amrd0s1b            none            swap    sw              0       0
/dev/amrd0s1a           /               ufs     rw              1       1
/dev/amrd0s1e           /tmp            ufs     rw              2       2
/dev/amrd0s1f           /usr            ufs     rw              2       2
/dev/amrd0s1d           /var            ufs     rw              2       2
/dev/acd0               /cdrom          cd9660  ro,noauto       0       0

which I modified (on the VM so its ‘/mnt/etc/fstab’) to this:

# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/da0s1b             none            swap    sw              0       0
/dev/da0s1a             /               ufs     rw              1       1
/dev/acd0               /cdrom          cd9660  ro,noauto       0       0

In addition, the network cards will probably have different device names, but in my case they both used ’em0′, however if you need to change them, edit ‘/mnt/etc/rc.conf’

Then reboot!

Footnotes

The MySQL instance would not start on my VM, but i found this was because the /tmp volume had incorrect permissions. I change this with:

chmod 777 /tmp
This entry was posted in FreeBSD Administration, MySQL and tagged , , , , . Bookmark the permalink.