Skip to content

Instantly share code, notes, and snippets.

@keilmillerjr
Last active February 19, 2024 14:34
Show Gist options
  • Save keilmillerjr/fc0d8ecdead22a6ce35a2719c58e165f to your computer and use it in GitHub Desktop.
Save keilmillerjr/fc0d8ecdead22a6ce35a2719c58e165f to your computer and use it in GitHub Desktop.
Cloning a Root Disk (Linux)

Cloning a Root Disk (Linux)

Preface

You need to create a bootable live disk to clone your disk. You can not copy a partition that is mounted. If you do not have internet access, use gparted. Otherwise, it might be better to use your operating systems live installer, such as Manjaro. We can download gparted and still have things like a web browser incase we get stuck. We will be using the Manjaro live disk for this guide.

Create a bootable live disk

  1. Download Manjaro.
  2. Insert USB disk.
  3. Open "Disks" application.
  4. Select your USB Disk in the left pane.
  5. Click the right options menu in the window title bar (Drive Options), and select "Restore Disk Image...)
  6. Select the disk image (.iso) file you previously downloaded.

Copy disk

Enter your bios and force boot into your live disk.

Update and install tools

  1. Open the terminal.
  2. sudo pacman -Syu dosfstools mtools gparted.

Create partition table

  1. Open the terminal.
  2. sudo fdisk -l
  3. Within the terminal output, find the disk you wish to clone and remember the disklabel type. This is most likely gpt.
  4. Open gparted.
  5. Select target disk.
  6. Device > Create Partition Table... > disklabel type

Clone partitions

The target disk must be the same size or larger than the disk you wish to clone. If it is not, you need to resize your partitions.

  1. Open gparted.
  2. Select clone disk.
  3. Select your boot partition.
  4. Partition > copy.
  5. Take note of the unallocated space preceeding the partition, filesystem size, and flags.
  6. Select target disk.
  7. Partition > paste.
  8. Enter free space preceeding and new size.
  9. Partition > manage flags > select same flags as clone disk.
  10. Repeat for all other partitions.
  11. Select your root partition.
  12. Partition > resize.
  13. Use slider to expand it to the rest of the disk.
  14. Click the checkmark to start the process of cloning the disk.

Retaining both disks

The new disk is a clone of the previous disk. If you keep the old disk installed, this will cause issues as the UUID of each disk is the same.

Generate new UUID's

  1. Open terminal
  2. Generate a random serial number for boot partition (fat32), sudo mkdosfs -i /dev/[partition 1].
  3. Generate a random serial number for root partition (ext), sudo tune2fs -U random /dev/[partition 2].

Confirm UUID's

  1. Open gparted.
  2. Select target disk.
  3. Select your boot partition.
  4. Partition > Information > Take note of UUID.
  5. Select your root partition.
  6. Partition > Information > Take note of UUID.

Mount root disk

  1. Open Disks.
  2. Select your target disk in the left pane.
  3. Select your root partition.
  4. Click the plus symbol to mount the disk.
  5. Take note of the location the partition is mounted at.

Edit fstab

  1. Open Terminal.
  2. sudo gedit /mnt/[your mounted partition]/etc/fstab
  3. Replace the UUID's of your boot and root partition with the new values.
  4. Save file, ctrl + s.

Edit grub manually

  1. Open Terminal.
  2. sudo gedit /mnt/[your mounted partition]/boot/grub/grub.cfg
  3. Replace the UUID's of your boot and root partition with the new values. Use find and replace.
  4. Save file, ctrl + s.

Edit grub automatically

  1. Open Terminal.
  2. sudo update-grub ref

Testing

You should now be able to reboot, enter bios, and change your boot disk to your new disk. Test the computer for a while before using Disks or gparted to wipe out the clone disk.

@djhunter67
Copy link

Could you update the instruction to include updating systemd boot, please and thank you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment