I assume, we are talking about UFS2 filesystems. In that case, full system cloning is done in two general steps.
1. Partitioning the target using gpart(8)
For this, I usually execute as user
root the following sequence, where
adaX is the device identifier of the new disk (!!! verify !!!):
gpart destroy -F adaX
gpart add -s 128 -a 4k -t freebsd-boot adaX
gpart add -s 4G -a 4k -t freebsd-swap -l SWAP adaX
(Note: if you need more swap space then use 8G or 16G, instead of 4G)
gpart add -a 4k -t freebsd-ufs -l SYSTEM adaX
Place the boodcode:
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 adaX
Set the bootme attribute:
gpart set -a bootme -i 3 adaX
Set the entire disk active in order the disk can be recognized by some too restrictive BIOS:
gpart set -a active /dev/adaX
Create the UFS2 filesystem:
newfs -j /dev/adaXp3
tunefs -a enable /dev/adaXp3
2. Clone the content of the filesystem(s) to the new SYSTEM partition
Mount the new SYSTEM partition:
mount -o noatime /dev/adaXp3 /mnt
Clone the root partition of the current disk to the new SYSTEM (/dev/adaXp3) partition. The SWAP partition must not be cloned. In general, I use the tool
sysutils/clone from the ports. Others like more
net/rsync or
sysutils/cpdup, here I show the use of
clone(1):
pkg install clone
clone -x .snap:.sujournal / /mnt
Note, before FreeBSD 9, the standard partition scheme placed
/tmp,
/usr and
/var on separate partitions/slices. If this is your case, then you need to clone these slice as well (!!! verify before executing the following !!!)
clone -x .snap:.sujournal /usr /mnt/usr
clone -x .snap:.sujournal /var /mnt/var
mkdir -p -m 1777 /mnt/tmp
Finally you need to adjust the file
/etc/fstab on the new SYSTEM partition, so it matches the partition labels as set in the
gpart commands above, for example:
nano /mnt/etc/fstab
Code:
# Device Mountpoint FStype Options Dump Pass#
/dev/gpt/SWAP none swap sw 0 0
/dev/gpt/SYSTEM / ufs rw,noatime 0 1
Finally unmont the new SYSTEM disk from its temporary mount location:
cd
umount /mnt
Power down the computer
shutdown -p now
, and replace the old startup disk by the new one.