Moving a linux (debian12) installation from an old drive to a new one.

1. create the new partitions with GParted to mirror the old (but larger)

root + boot, efi, usr, var, home, tmp, swap, and a remaining data partition.

All ext4 except the efi partition which must be FAT32 and the swap, as linux-swap.

set the flags for both the efi partition and root to be bootable. They will have both the esp and boot flags set.


2. mount and rsync the files from the old partitions to the new, to mirror them.

create mount points in /mnt/

To make things easier, mount everything separately initially.

/mnt/1root/

/mnt/1var/

/mnt/1home/

/mnt/1usr/

/mnt/1efi/

eg mount for each

#mount UUID=<get uuid from gparted information> /mnt/1root/

mount the new partions separately.

/mnt/2root/

/mnt/2var/

/mnt/2home/

/mnt/2usr/

/mnt/2efi/

for each rsync all the files across

#rsync -avxHAX --progress /mnt/1root/ /mnt/2root/

Note: rsync -avxHAX --progress /source/ /destination/. 

-a (archive mode): This is a shorthand for several options that preserve file attributes (permissions, ownership, timestamps, etc.). 

-v (verbose): Shows you the files being transferred. 

-x (one file system): Prevents rsync from crossing filesystem boundaries, useful when copying a partition to avoid copying mounted special filesystems like /proc or /sys. 

-H (hard links): Preserves hard links. 

-A (ACLs): Preserves Access Control Lists. 

-X (extended attributes): Preserves extended attributes. 

--progress: Shows the progress of the transfer. 

Important: Note the trailing slashes on the source and destination paths. For example, /source/ will copy the contents of the source directory into the destination directory, while /source (without a trailing slash) would copy the source directory itself into the destination. 


3. Use a live image/alternative OS (if dual boot) to access the new installation.

Again mount the partitions /mnt/1root/ /mnt/2root/ and rsync again to ensure all the files are copied and at their latest version.

Update the fstab (as root) to the new UUIDs for the new partitions.

#nano /mnt/2root/etc/fstab

mount the usr, efi, home (not really necessary), var, and tmp partitions into the new 2root to ensure a working installation.

E.g. (usr) 

#mount UUID=<get uuid from gparted information> /mnt/2root/usr/

E.g. (efi)

#mount UUID=<get uuid from gparted information> /mnt/2root/boot/efi/


4. Chroot to update the GRUB bootloader

#mount --bind /proc /mnt/2root/proc
#mount --bind /sys /mnt/2root/sys
#mount --bind /dev /mnt/2root/dev
#mount --bind /run /mnt/2root/run
... then chroot into the system.

#chroot /mnt/2root
Once in, run commands to update the grub bootloader.

#update-grub
** it might be necessary to install grub to the device (not the partition)

#install-grub /dev/<device>
Then
 
update-initramfs -u -k all
To update all the installed kernel images.

Finally, exit chroot and umount proc, sys, run, and dev

#umount /mnt/2root/proc

5. Reboot and select the new drive as the default boot drive.

Comments

Popular posts from this blog

Cannot remove or edit file (even as root) [solved]