BLog

ImprintImpressum
PrivacyDatenschutz
DisclaimerHaftung
Downloads 

FreeBSD UFS: Clone the System to another disk

This and then, we need to create a clone of a FreeBSD system. Either for replacing the old disk by a new one, or for quickly setting up another FreeBSD box using a cloned disk of well running system, or simply for having some executable backups for fast disaster recovery. Here comes a brief transcript of how I do this employing sysutils/clone.

  1. Become system admin (root):
      sudo -s
  2. Find the device identifier of the target disk, maybe ada1, in the following adaX needs to be replaced by the actual ID:
      ls -l /dev/ada*
      gpart show
  3. Partition the target disk:
      gpart destroy -F adaX
      gpart create -s GPT adaX
      gpart add -b 40 -s 128 -t freebsd-boot adaX
      gpart add -s 81752 -t efi adaX
      gpart add -s 8G -t freebsd-swap -l swap adaX
      gpart add -t freebsd-ufs -l system adaX
  4. View the new partitions -- this should look more or less like this:
      gpart show -l adaX
    =>    40  937703008  adaX  GPT  (447G)
          40        128     1  (null)  (64K)
         168      81752     2  (null)  (40M)
       81920   16777216     3  swap    (8.0G)
    16859136  920843912     4  system  (439G)
  5. Make the disk bootable for both BIOS and UEFI:
      gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 adaX
      gpart set -a bootme -i 4 adaX

      newfs_msdos -F 32 -c 1 /dev/adaXp2
      mount -t msdosfs /dev/adaXp2 /mnt
      mkdir -p /mnt/EFI/BOOT
      cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
      umount /mnt

    Note: The following tells the computer to boot the disk in BIOS mode, for UEFI mode omit this:
      gpart set -a active adaX
  6. Format the FreeBSD system partition:
      newfs -njtEU /dev/adaXp4
      tunefs -a enable /dev/adaXp4
  7. Mount the FreeBSD system partition to the /mnt mount point:
      mount -o noatime /dev/adaXp4 /mnt
  8. The clone(1) command - depending on the speed of the drives, this may take some time:
      clone -c rwoff -x .sujournal / /mnt

    Note: In backup cases, we use the -s option for synchronizing an already exiting backup clone with the original file system.
  9. Edit the file /mnt/etc/fstab. Once the whole thing looks like this, save and exit:
    # Device            Mountpoint      FStype  Options Dump    Pass#
    /dev/gpt/system     /               ufs     rw      1       1
    /dev/gpt/swap       none            swap    sw      0       0
    proc                /proc           procfs  rw      0       0
  10. Remove the finished clone from the mount point:
      umount /mnt
  11. Become a normal user and DONE!!!
      exit

Copyright © Dr. Rolf Jansen - 2022-01-29 01:09:11

Discussion on Twitter: 1487228528932306950