[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Copying one drive to a smaller one.



On Mon, May 09, 2022 at 04:47:44PM -0400, paulf@quillandmouse.com wrote:
Unfortunately, this is precisely what I was trying to avoid. For
example, to accommodate the graphics on my CPU, I had to use a later
kernel from backports. That's one of many wrinkles. Under other
circumstances, I probably would do as you advise, but I'm limited on
time and was trying to find a shortcut.

With a modern EFI system with UUIDs in the fstab it's actually not that hard. Boot off an rescue disk or somesuch. Create partitions on the new disk that mirror those of the old disk (except of course that the largest one should be smaller; do not make any of the others smaller). If you're lucky you've just got an EFI partition and a root partition. Assuming you're using ext4, use resize2fs to shrink the large volume to something smaller than the destination partition. (For example, if the new partition is 128G, shrink it to 120G.) Assuming your original drive is sda and the new one is sdb, copy each partition with something like cp /dev/sda1 /dev/sdb1. That's basically it for copying the data. Now this part's important: you don't want to boot from either of these disks while the other is in the system, because the UUIDs on the filesystems are the same. Pull the old one out before booting up. You may need to reconfigure the BIOS to boot of the new disk, depending on how it was configured--if you do, there should be some kind of "add new boot device" option that will let you browse the EFI partition and select "EFI/debian/grubx64.efi". I may be missing something as I type this off the top of my head, but whatever comes up should be fixable as long as you don't copy the new disk onto the old one. :) I think all the current versions of fdisk will show you the disk model when using "fdisk -l" in addition to the partition information, which should help to double check which drive is which. With an old-style PC BIOS boot you'd need additional steps to install grub to the boot sector of the new disk, reconfigure grub's understanding of which linux device corresponds to which bios device, and tell the grub package where to install new bootloaders in the future.

There are also other ways to do this, for example by creating new filesystems, then using cp or rsync to copy the files (but this does require specific flags, and can have issues in [somewhat rare] circumstances) or using filesystem-specific tools like xfs_copy. In this case you'd need to use blkid to determine the UUIDs of the new partitions and update fstab on the new disk to match the new UUIDs.


Reply to: