1

Scenario

I have an SSD in my computer (250GiB), with both /boot and ///home partitions on it.

I'd like to move that into a new M.2 NVME drive which is much larger (1TiB).

The distro I'm using is Fedora 37.

my /etc/fstab looks like this:


#
# /etc/fstab
# Created by anaconda on Tue Jun 28 05:26:41 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=5ed1bf26-ab2f-4e5a-ab5e-d2d56f5f3803 /                       btrfs   subvol=root,compress=zstd:1 0 0
UUID=a14f6d42-3a64-4f96-856c-51e0f4344481 /boot                   ext4    defaults        1 2
UUID=5ed1bf26-ab2f-4e5a-ab5e-d2d56f5f3803 /home                   btrfs   subvol=home,compress=zstd:1 0 0

lsblk looks like this:

NAME   KNAME PATH       TYPE MODEL                     STATE   RO RM HOTPLUG FSTYPE FSVER LABEL                 PTTYPE PARTTYPE PARTTYPENAME PARTLABEL PARTFLAGS   SIZE FSSIZE FSAVAIL
sda    sda   /dev/sda   disk Samsung SSD 850 EVO 250GB running  0  0       0                                    dos                                              232.9G        
├─sda1 sda1  /dev/sda1  part                                    0  0       0 ext4   1.0                         dos    0x83     Linux                  0x80          1G 973.4M  608.1M
└─sda2 sda2  /dev/sda2  part                                    0  0       0 btrfs        fedora_localhost-live dos    0x83     Linux                            231.9G 231.9G  108.3G
zram0  zram0 /dev/zram0 disk                                    0  0       0                                                                                       7.5G        

Note: both / and /home/ are subvolumes of the same partition! They're not on individual partitions as such.

Problem

How would I go about doing this, with minimal interruption to my work time? I thought I'd boot up a live distro with gparted and then move partitions over, but since there are UUIDs scattered all over my current setup, I think I might run into problems, also I'm not sure this is the preferred method.

As a bonus, I suppose, I'd like a swap partition on my hard drive, that is larger than my current amount of RAM (8GB). Currently, I only use ZRAM, but I'd like to have a swap partition that is larger (perhaps twice in size) than my current amount of RAM, so that I can safely put my computer into hibernation. Also, more swap would be quite good for my VMs, and I'm struggling running more than around two VMs, currently.

This is roughly how I think I should go about this:

  1. I thought I'd clone the current layout onto my 1TB drive, however I'm not sure which tool to use would be best, leaving a large chunk of the drive empty.
  2. I'd then create a swap partition towards the end of the un-allocated space.
  3. And then enlarge my /dev/sda2 partition, so that I can use the entirety of my drive, etc.

Please advise the order of procedure (step 0 would be to create a backup, obviously), as well as the tools I should perhaps try out, etc.

0

2 Answers 2

0

The simplest method would be to:

  1. Boot a live ISO like gparted
  2. Bare-metal copy the 250G SATA SSD to the NVMe SSD
  3. Unplug the SATA SSD
  4. Boot from the NVMe
  5. Verify everything still works
  6. Resize the partition to max
  7. btrfs filesystem resize max /

Optional but recommended further steps:

  1. Reboot to live ISO again
  2. Plug the SSD in again
  3. blkdiscard the SATA SSD
  4. Format the SATA SSD with something new

Important gotchas:

  1. After cloning, do not mount the filesystem while both disks are connected. (A boot will mount the filesystem!)
  2. It doesn't matter how you clone the disk. You could even use cp. All that matters is that it's a 1:1 copy
  3. Use /dev/disk/by-id/ nodes whenever you need to enter a disk on the CLI. Makes it much less error-prone.
0

or

  1. Add another target disk if you don't have enough local space for the Clone file:
sudo mkdir /media/disk
sudo mount /dev/sdb1 /media/disk
sudo chmod ugo+wx /media/disk
  1. Zero out free space https://unix.stackexchange.com/a/506097/518235

    then Clone used space only

 sudo dd if=/dev/xvda bs=16M conv=sparse,noerror | pv | sudo pigz -c > /media/disk/TargetImg.dd.gz

Alternative dd option if no pv: status=progress

  1. Transfer locally using cp / rsync see 8) or a remote Target:
 sshpass -p "xxxxxxxxx" scp TargetImg.dd.gz [email protected]:/home/fedora | pv -lep -s 42
  1. Restore (locally or remotely):
 sudo pigz -cdk TargetImg.dd.gz | pv | sudo dd of=/dev/sdb bs=16M
  1. or optionally convert disk format to e.g Virtual Machine of choice:
 sudo dnf install qemu 
 sudo qemu-img convert -O vmdk TargetImg.dd TargetImg.vmdk -p
  1. Optional HD resize e.g on an ESXi host:
 vmkfstools -X 100G "TargetImg.vmdk"
  1. Local sync between 1st & 2nd or old & new drives is also possible:
sudo rsync -aHAXS \
--filter='-x security.selinux' \
--no-compress \
--no-inc-recursive \
--stats \
--numeric-ids \
--info=progress2 \
/media/disk/ \
/

source: stackoverflow et al

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .