Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #248056

Re: Copying one drive to a smaller one.

From Michael Stone <mstone@debian.org>
Newsgroups linux.debian.user
Subject Re: Copying one drive to a smaller one.
Date 2022-05-10 00:10 +0200
Message-ID <EljJL-epCt-1@gated-at.bofh.it> (permalink)
References <El0QN-ed6f-3@gated-at.bofh.it> <ElgLT-enyM-15@gated-at.bofh.it> <EliNH-eoXH-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Copying one drive to a smaller one. <paulf@quillandmouse.com> - 2022-05-09 04:00 +0200
  Re: Copying one drive to a smaller one. Felix Miata <mrmazda@earthlink.net> - 2022-05-09 04:40 +0200
  Re: Copying one drive to a smaller one. David Christensen <dpchrist@holgerdanske.com> - 2022-05-09 21:00 +0200
    Re: Copying one drive to a smaller one. "Andrew M.A. Cater" <amacater@einval.com> - 2022-05-09 21:20 +0200
      Re: Copying one drive to a smaller one. Tixy <tixy@yxit.co.uk> - 2022-05-09 22:10 +0200
      Re: Copying one drive to a smaller one. The Wanderer <wanderer@fastmail.fm> - 2022-05-09 23:00 +0200
    Re: Copying one drive to a smaller one. <paulf@quillandmouse.com> - 2022-05-09 23:10 +0200
      Re: Copying one drive to a smaller one. Michael Stone <mstone@debian.org> - 2022-05-10 00:10 +0200
        Re: Copying one drive to a smaller one. Stefan Monnier <monnier@iro.umontreal.ca> - 2022-05-10 04:40 +0200
    Re: Copying one drive to a smaller one. "stepore@gmail.com" <stepore@gmail.com> - 2022-05-10 07:10 +0200
    Re: Copying one drive to a smaller one. <paulf@quillandmouse.com> - 2022-05-10 14:40 +0200
      Re: Copying one drive to a smaller one. Michael Stone <mstone@debian.org> - 2022-05-10 18:30 +0200
      Re: Copying one drive to a smaller one. Michael Stone <mstone@debian.org> - 2022-05-10 21:20 +0200
      Re: Copying one drive to a smaller one. <paulf@quillandmouse.com> - 2022-05-10 21:30 +0200

csiph-web