Skip to content

Migrating FreeBSD to another disk under VMware

Task: Reduce the FreeBSD 9.2 virtual host (Exim relay, 1 GB RAM) HDD from 40 GB to 10 GB because only 5 GB plus 2 GB swap is used. The UFS filesystem cannot be reduced by the OS. Attach a new 10 GB HDD and migrate everything to it.

Lesson from the first attempt: 512 MB swap was insufficient; ClamAV killed mysqld. Use 1 GB.

  1. Create an additional disk for the VM host at the required size.
  2. Reboot.
  3. Create partitions on the new disk.
bsdconfig 

Partition the new disk exactly like the old one:

-------------------Partition Editor--------------------¬
¦ Create partitions for FreeBSD. No changes will be    ¦
¦ made until you select Finish.                        ¦
¦-----------------------------------------------------¬¦
¦¦da0             40 GB   GPT                         ¦¦
¦¦  da0p1         64 KB   freebsd-boot                ¦¦
¦¦  da0p2         38 GB   freebsd-ufs    /            ¦¦
¦¦  da0p3         2.0 GB  freebsd-swap                ¦¦
¦¦da1             10.0 GB  GPT                        ¦¦
¦¦  da1p1         64 KB   freebsd-boot                ¦¦
¦¦  da1p2         9 GB  freebsd-ufs    /              ¦¦
¦¦  da1p3         1024 MB  freebsd-swap   none        ¦¦
¦L-----------------------------------------------------¦
+------------------------------------------------------+
¦    < Auto >  ¦
L-------------------------------------------------------

4. Enter Single User Mode. Run:

tunefs -J disable /dev/da0p2
tunefs -n disable /dev/da0p2
tunefs -j disable /dev/da0p2

5. Reboot.

6. Mount the new partition.

mount /dev/da1p2 /mnt

7. Start the data migration on the running server.

( dump -0Lf - / ) | ( cd /mnt ; restore -rf - )

The process took 33 minutes.

8. Disconnect the old disk from the virtual machine. The new disk was named da1, and after removing the old disk it became da0. Therefore, do not change /etc/fstab.

9. Boot up.