It happened just the day before yesterday that I switched a system to a new UFS system disk. I did it as follows:
1. Partitioning the target using gpart(8)
Execute as user
root the following sequence, where
adaX is the device identifier of the new disk
(!!! verify !!! -- in my case it was
ada1):
gpart destroy -F adaX
gpart create -s gpt 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 filesystems of the current disk to the new SYSTEM partition
Mount the new SYSTEM partition onto a temporary mount point:
mount -o noatime /dev/adaXp3 /mnt
For cloning the filesystems, I use the tool
sysutils/clone from the ports. Others like more
net/rsync or
sysutils/cpdup or even
dump(8)|
restore(8), here I show the use of
clone(1):
pkg install clone
clone -x .snap:.sujournal / /mnt
clone -x .snap:.sujournal /usr /mnt/usr
clone -x .snap:.sujournal /var /mnt/var
The
swap partition must not be cloned, and instead of cloning the
tmp partition, it is sufficient to create the respective directory:
mkdir -p -m 1777 /mnt/tmp
Then I 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 I unmont the new SYSTEM disk from its temporary mount location:
cd
umount /mnt
I power down the computer
shutdown -p now
, and replace the old startup disk by the new one.