How to Migrate Linux to a New Disk

27 Nov 2026, 12:35:46
Migrating Linux to a new disk may be necessary when increasing the available disk space on a server, replacing a faulty drive, upgrading to a faster SSD, or changing the partition layout. Reinstalling the operating system is not required.
This article covers two methods: copying files using rsync (the primary method) and cloning an entire disk using dd (an alternative method).
Important. Back up your data before starting. Using the wrong disk name in a command will result in data loss. Perform the migration from Rescue Mode or a Live system so that the source filesystem is not modified during the copy process. Run all commands as root.

Which Method Should You Choose?

rsyncdd
New disk sizeAny size, provided it has enough space for the dataMust be at least as large as the source disk
Partition layoutCreated manuallyCopied as is
BootloaderMust be reinstalledCopied along with the disk
Main riskMore steps; easier to make mistakes in fstab and GRUBOverwriting the wrong disk, UUID conflicts
Best suited forDisks of different sizes or a new partition layoutDisks of the same size when an exact copy is required

1. Preparation

First, identify the connected disks, locate the operating system, and determine the boot mode.
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID
df -hT
[ -d /sys/firmware/efi ] && echo 'UEFI' || echo 'BIOS'
The last command shows the boot mode of the currently running system. In Rescue Mode, this mode may differ from the server's actual boot mode. Therefore, check the partition layout as well: the presence of a 100–500 MB partition with a vfat filesystem and a /boot/efi mount point in /etc/fstab indicates UEFI.
Example of the source disk layout:
PartitionPurposeSize
/dev/sda1EFI System Partition (ESP)512 MB
/dev/sda2Root partition /40 GB
/dev/sda3Swap4 GB
In the examples, the new disk is /dev/sdb with a capacity of 100 GB.
Warning. Device names in this article are examples. Before running any destructive command, verify the disk using lsblk: the new disk must be empty, have no mount points, and have sufficient capacity.
If the TYPE column contains lvm, crypt, or raid, the system uses LVM, encryption, or software RAID.

2. Partitioning the New Disk

The partition layout depends on the boot mode. Choose one of the following three options.

Option A. UEFI

Two partitions are required: ESP (FAT32) and the root partition.
parted /dev/sdb --script mklabel gpt
parted /dev/sdb --script mkpart ESP fat32 1MiB 513MiB
parted /dev/sdb --script set 1 esp on
parted /dev/sdb --script mkpart root ext4 513MiB 100%
mkfs.vfat -F32 /dev/sdb1
mkfs.ext4 /dev/sdb2

Option B. BIOS + GPT

With this layout, GRUB stores part of its code in a small bios_grub partition. Without it, grub-install will fail.
parted /dev/sdb --script mklabel gpt
parted /dev/sdb --script mkpart biosboot 1MiB 2MiB
parted /dev/sdb --script set 1 bios_grub on
parted /dev/sdb --script mkpart root ext4 2MiB 100%
mkfs.ext4 /dev/sdb2

Option C. BIOS + MBR

Suitable for disks up to 2 TB.
parted /dev/sdb --script mklabel msdos
parted /dev/sdb --script mkpart primary ext4 1MiB 100%
parted /dev/sdb --script set 1 boot on
mkfs.ext4 /dev/sdb1
From this point onward, the root partition on the new disk is /dev/sdb2 (Options A and B) or /dev/sdb1 (Option C). The examples use /dev/sdb2; replace it with the appropriate value for your setup.
We will not create a separate swap partition. It is easier to add a swap file after the first boot (see Section 5). If the source system has separate /boot, /home, or /var partitions, create corresponding partitions on the new disk as well.
Verify the result:
lsblk -f /dev/sdb

3. Mounting the Partitions

In Rescue Mode, the root directory / belongs to the rescue system, not to your server. Therefore, mount both disks explicitly: the old root partition at /mnt/oldroot and the new one at /mnt/newroot.
mkdir -p /mnt/oldroot /mnt/newroot
mount /dev/sda2 /mnt/oldroot
mount /dev/sdb2 /mnt/newroot
df -hT /mnt/oldroot /mnt/newroot
If the Rescue system has mounted the old disk automatically, find its mount point using the findmnt command and use it instead of /mnt/oldroot.
There is no need to mount the old ESP: the bootloader will be installed on the new disk from scratch. We will mount the new ESP later, before installing GRUB. This is intentional: FAT does not support file permissions and ownership, so rsync with the -aAX options would generate errors on this filesystem.
If the source system has a separate /boot partition formatted with ext4, mount it at /mnt/oldroot/boot, and mount the corresponding new partition at /mnt/newroot/boot before starting the copy process. The same principle applies to /home and /var.

4. Copying Files Using rsync

rsync preserves file permissions, ownership, symbolic and hard links, ACLs, and extended attributes.

Option A. From Rescue Mode (Recommended)

rsync -aAXH --numeric-ids --info=progress2 /mnt/oldroot/ /mnt/newroot/No exclusions are needed here: /dev, /proc, and /sys on the old system are ordinary empty directories in Rescue Mode. They will be copied and will be useful as mount points for chroot.
Options:
  • -a — recursive copying while preserving permissions, timestamps, ownership, and symbolic links;
  • -A — preserve ACLs;
  • -X — preserve extended attributes;
  • -H — preserve hard links;
  • --numeric-ids — use numeric UID and GID values without mapping usernames;
  • --info=progress2 — display overall progress instead of a line-by-line file list.
After copying, make sure the required directories exist:
mkdir -p /mnt/newroot/{dev,proc,sys,run,tmp,mnt,media}
chmod 1777 /mnt/newroot/tmp

Option B. From a Running System

If Rescue Mode is unavailable, you can copy files directly from the running system. Exclusions are mandatory in this case; otherwise, rsync will start copying virtual filesystems and the target disk itself.
rsync -aAXH --numeric-ids --info=progress2 \
  --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' \
  --exclude='/run/*' --exclude='/tmp/*' --exclude='/mnt/*' \
  --exclude='/media/*' --exclude='/lost+found' \
  / /mnt/newroot/
While the system is running, databases and applications continue modifying files, so the resulting copy may be inconsistent. Stop such services (systemctl stop mysql postgresql, etc.) and run the command again: the second pass will transfer only the changes.
This command is intended for a system with a single root partition. Separate /boot, /home, and other mount points must be copied separately after mounting their corresponding partitions under /mnt/newroot.

5. Updating fstab and UUIDs

The new partition has a new UUID, while the copied /etc/fstab still references the old ones. If this is not corrected, two problems may occur: the system may fail to boot, or, while the old disk is connected, it may mount the old partitions and silently continue using them.
Find the UUIDs of the new partitions:
blkid /dev/sdb1 /dev/sdb2Open the file and replace the relevant entries:
nano /mnt/newroot/etc/fstabExample for UEFI:
UUID= / ext4 errors=remount-ro 0 1
UUID= /boot/efi vfat umask=0077 0 1
What you need to check:
  • Root / — the new UUID of the root partition.
  • ESP (/boot/efi) — the new UUID of the FAT32 partition. This entry is not required for BIOS and should be removed.
  • Swap — remove or comment out the entry for the old swap partition. Otherwise, the system may wait for a nonexistent device, delaying boot by 90 seconds.
  • Separate /boot, /home, /var — update their UUIDs.
  • /etc/initramfs-tools/conf.d/resume (Debian and Ubuntu) — if it contains RESUME=UUID=... referencing the old swap partition, replace the value with RESUME=none.
  • /etc/crypttab — if this file exists, check the UUIDs of encrypted partitions.
You can quickly find any remaining references to the old UUID using the following command (replace the placeholder with the old partition's UUID):
grep -rI '' /mnt/newroot/etcYou can add swap after the first boot from the new disk:
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab

6. Installing the Bootloader in chroot

Mount the system directories:
mount --bind /dev /mnt/newroot/dev
mount --bind /dev/pts /mnt/newroot/dev/pts
mount --bind /proc /mnt/newroot/proc
mount --rbind /sys /mnt/newroot/sys
mount --bind /run /mnt/newroot/run
The /sys directory is mounted using --rbind so that /sys/firmware/efi/efivars is accessible inside chroot. GRUB needs it to work with UEFI.
For UEFI, mount the new disk's ESP:
mkdir -p /mnt/newroot/boot/efi
mount /dev/sdb1 /mnt/newroot/boot/efi
Enter the new system:
chroot /mnt/newroot /bin/bashThe following commands are executed relative to the new disk. Choose the section for your distribution.

Debian and Ubuntu

Rebuild initramfs. It contains drivers and settings used during the early boot process (resume, LVM, RAID, crypttab), so it must be updated after changing the configuration:
update-initramfs -u -k allBIOS. Install GRUB to the entire disk, not to a partition:
grub-install /dev/sdb
update-grub
If update-grub is unavailable, use grub-mkconfig -o /boot/grub/grub.cfg.
UEFI:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu
update-grub
On Debian, replace ubuntu with debian. This command creates an entry in NVRAM. In virtual environments and Rescue Mode, access to EFI variables is often unavailable. In that case, install the bootloader to the fallback path EFI/BOOT/BOOTX64.EFI, which the firmware can detect automatically:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable
update-grub

AlmaLinux, Rocky Linux, Fedora

This section depends more heavily on the distribution version, so check the documentation for your specific release.
dracut --regenerate-all --forceBIOS:
grub2-install /dev/sdb
grub2-mkconfig -o /boot/grub2/grub.cfg
UEFI. In this case, grub2-install is not used: bootloader files are supplied by packages. To make them available on the new ESP, reinstall the packages (working DNS will be required inside chroot):
dnf reinstall shim-x64 grub2-efi-x64
grub2-mkconfig -o /boot/grub2/grub.cfg
On RHEL 8 and its derivatives, the UEFI configuration is located at /boot/efi/EFI//grub.cfg, and grub2-mkconfig must write to that location. In newer versions, this file remains a small stub containing the UUID of the partition with /boot. Check it and replace the UUID with the new one.
On these systems, the root UUID is also stored in kernel parameters (/boot/loader/entries/*.conf, /etc/kernel/cmdline, grubenv). grub2-mkconfig does not update these entries:
grubby --info=ALL | grep root
grubby --update-kernel=ALL --args='root=UUID='
If SELinux is enabled on the system, create a marker file to trigger a full relabel on the first boot:
touch /.autorelabel

Exiting chroot

exit

7. Pre-Reboot Checks

Before disconnecting the disks, check the following:
cat /mnt/newroot/etc/fstab
blkid
ls -lah /mnt/newroot/boot
grep -c '' /mnt/newroot/boot/grub/grub.cfg
ls -lah /mnt/newroot/boot/efi/EFI
The last two commands apply to Debian and Ubuntu, and to UEFI, respectively. Make sure that:
  • /boot contains a kernel (vmlinuz-) and initramfs (initrd.img- or initramfs-**);
  • grub.cfg contains the UUID of the new root partition;
  • fstab contains no UUIDs of the old partitions;
  • the ESP contains the distribution directory or the BOOT directory (when using --removable).
Unmount the temporary mount points:
umount -R /mnt/newroot
umount /mnt/oldroot

8. Booting from the New Disk

On a physical server, set the new disk as the first boot device in the BIOS or UEFI boot order.
If possible, disconnect the old disk during the first boot. This makes it easier to identify any remaining references to it. If disconnecting it is not possible, verify the result using the commands below.
rebootAfter booting, make sure the system is running from the new disk:
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT
findmnt /
df -hT
swapon --show
systemctl --failed
If swap is required, add a swap file (see the commands in Section 5). Also check the network: when the virtual configuration changes, network interface names may change, while settings in /etc/netplan, /etc/network/interfaces, or NetworkManager may still refer to the old names.
Do not delete or format the source disk immediately after the first successful boot. Keep it unchanged for several days or weeks so that you can revert to the previous configuration if necessary.

9. Possible Problems After Migration

ProblemPossible cause
GRUB does not startThe bootloader was not installed on the new disk, the wrong boot mode (BIOS or UEFI) was selected, or the boot order is incorrect
grub-install reports an error on GPT with BIOSThe bios_grub partition is missing
The old system bootsThe boot order points to the old disk, or its UUIDs remain in fstab and GRUB
The system drops into initramfsIncorrect root UUID, initramfs was not rebuilt, or required drivers are missing
Unable to mount root filesystemIncorrect boot configuration or missing drivers in initramfs
Emergency modeErrors in /etc/fstab
Boot is delayed by up to 90 secondsfstab still contains the UUID of the old swap partition or another partition, or RESUME points to the old swap
The network does not startNetwork interface names have changed
Individual services do not workRequired directories were not copied or mount points have changed
For diagnostics after booting:
journalctl -xb
systemctl --failed
ip addr
If the system does not boot, return to Rescue Mode, mount the new disk, and check fstab, UUIDs, and the bootloader again (Sections 5–7).

10. Alternative Method: Cloning a Disk Using dd

dd creates a byte-for-byte copy of a disk, including the partition table and bootloader. This method is suitable when an exact copy is required on a disk of the same or larger size.
Requirements:
  • The source disk must not be mounted. Therefore, work from Rescue Mode or a Live system: copying a running filesystem may produce an inconsistent copy.
  • The target disk must be at least as large as the source disk.
  • All data on the target disk will be destroyed.
dd if=/dev/sda of=/dev/sdb bs=4M status=progress conv=fsyncWhere:
  • if — source disk;
  • of — target disk;
  • bs=4M — block size;
  • status=progress — display progress;
  • conv=fsync — flush data to the disk before completion.
The conv=noerror,sync options are not required for ordinary cloning. They are intended for recovering data from a faulty disk: when a read error occurs, the affected block is silently replaced with zeros, resulting in a copy with data loss.

If the New Disk Is Larger

After cloning, the partition table and filesystem still occupy the original disk space. Extend them as follows:
sgdisk -e /dev/sdb
growpart /dev/sdb 2
e2fsck -f /dev/sdb2
resize2fs /dev/sdb2
The first command moves the backup GPT table to the end of the disk (required only for GPT), the second extends the partition (requires the cloud-guest-utils or cloud-utils-growpart package), and the remaining commands check and expand the ext4 filesystem.
For XFS, use xfs_growfs on the mounted filesystem.

UUID Conflict

A clone completely duplicates identifiers: filesystem UUIDs, and, for GPT, the disk identifier and PARTUUID as well. Do not boot with both disks connected simultaneously.
If both disks need to remain connected, change the identifiers on the copy and update fstab and GRUB, as described in Sections 5 and 6:
tune2fs -U random /dev/sdb2
sgdisk -G /dev/sdb

Conclusion

Migrating Linux to a new disk allows you to preserve the operating system, settings, users, applications, and data without reinstalling the system.
For disks of different sizes or when changing the partition layout, use rsync: you create the partition layout yourself and transfer only the required data.
For an exact copy of a disk of the same or larger size, dd is suitable, but it requires careful selection of the source and target devices.
Before completing the migration, check the following:
  • the new disk's partition layout and boot mode (BIOS or UEFI);
  • UUIDs in /etc/fstab and the absence of references to old partitions;
  • GRUB installation and the updated initramfs;
  • successful booting from the new disk (findmnt /);
  • network connectivity and service status (ip addr, systemctl --failed).

VPS in the Netherlands

Browse Configurations

Premium Dedicated Servers

Browse Configurations