Skip to content

Instantly share code, notes, and snippets.

@keilmillerjr
Last active June 24, 2025 13:04
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?

@dcazrael
Copy link

Since I need that, I updated the instructions using EFI and systemd boot

Cloning a Root Disk on Linux (Including systemd-boot and EFI Update)

Preface

You need to create a bootable live disk to clone your root disk. Copying a mounted partition is not possible. If you do not have internet access, use GParted Live. Otherwise, using a live installer like Manjaro is often more versatile. This guide uses a Manjaro live disk for cloning.


Step 1: Create a Bootable Live Disk

  1. Download a Manjaro ISO from the official website.
  2. Insert a USB drive.
  3. Open the Disks application.
  4. Select the USB drive in the left pane.
  5. Click the options menu in the window title bar (Drive Options).
  6. Select Restore Disk Image.
  7. Choose the Manjaro ISO file you downloaded.
  8. Wait for the process to complete.

Step 2: Boot into the Live Disk

  1. Reboot your computer.
  2. Enter BIOS or boot menu.
  3. Boot from the USB live disk.

Step 3: Install Required Tools

Open the terminal and run:

sudo pacman -Syu dosfstools mtools gparted efibootmgr

Step 4: Prepare the Target Disk

  1. Open a terminal and run:
sudo fdisk -l
  1. Identify the target disk and note the partition table type (e.g. gpt).
  2. Open GParted.
  3. Select the target disk.
  4. Navigate to Device > Create Partition Table..., choose the appropriate label (usually gpt).

Step 5: Clone Partitions

Note: The target disk must be at least the same size as the source disk.

  1. In GParted, select the source disk.

  2. Right-click each partition:

    • Select Copy.

    • Take note of:

      • Unallocated space preceding the partition
      • Filesystem size
      • Partition flags
  3. Switch to the target disk:

    • Right-click unallocated space > Paste.
    • Set correct preceding space and size.
    • Right-click > Manage Flags and apply the same flags.
  4. Repeat for all partitions.

  5. Resize the root partition to fill the remaining space (right-click > Resize/Move).

  6. Click the green checkmark to apply all changes.


Step 6: Update UUIDs to Avoid Conflicts

Boot Partition (FAT32)

sudo mkdosfs -i $(hexdump -n 4 -e '4/1 "%02X"' /dev/urandom) /dev/sdX1

Root Partition (EXT4)

sudo tune2fs -U random /dev/sdX2

Step 7: Confirm UUIDs

  1. Open GParted.
  2. Select the target disk.
  3. Right-click each partition > Information.
  4. Note the new UUIDs.

Step 8: Mount the Root Partition

  1. Open Disks.
  2. Select your target disk.
  3. Select the root partition.
  4. Click the Mount button.
  5. Note the mount point (e.g. /mnt/sdX2).

Step 9: Update fstab

  1. Open the terminal:
sudo nano /mnt/sdX2/etc/fstab
  1. Replace the old UUIDs for boot and root with the new values.
  2. Save and exit.

Step 10: Update systemd-boot (if used)

  1. Mount the EFI partition:
sudo mkdir /mnt/boot
sudo mount /dev/sdX1 /mnt/boot
  1. Edit loader entries:
sudo nano /mnt/boot/loader/entries/manjaro.conf
  1. Replace the root= UUID line with the new root UUID.

Example:

options root=UUID=new-root-uuid rw
  1. Confirm or update loader.conf if needed:
sudo nano /mnt/boot/loader/loader.conf

Step 11: Update GRUB (if used)

  1. Open GRUB configuration file:
sudo nano /mnt/sdX2/boot/grub/grub.cfg
  1. Find and replace all occurrences of the old UUIDs with the new ones.
  2. Save and exit.

Optional: Regenerate GRUB configuration

sudo arch-chroot /mnt/sdX2
update-grub
exit

Step 12: Test the New Disk

  1. Reboot the system.
  2. Enter BIOS and set the new disk as the boot device.
  3. Boot into the cloned system.
  4. Verify everything works as expected.

Optional: Wipe Old Disk

Once the new system works flawlessly, you can use GParted or Disks to wipe the original disk if needed.

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