Linux disk upgrade procedure - jandelgado/general GitHub Wiki

Once in a while I upgrade disks in my notebook. This is a description of the procedure for my personal reference.

I use encrypted disks and the logical volume manager (LVM).

Layering
Ext4 Filesystem
Logical Volume (LV)
Volume Group (VG)
Physical Volume (PV)
Encrypted Block Device
Partition
Block Device
  1. Make a backup.
  2. Preparation: copy old disk to new disk (using dd command). Since the source disk must not be in used while copying, this is easiest achieved by booting a rescue system from an USB drive or attach the disk to a second computer.
  3. Resize partition: Use e.g. fdisk and delete the partition to be resized and re-create the new partition on the same starting sector, but with more sectors. Alternatively, use a different partitioning tool.
  4. Open the encrypted block device with cryptsetup open /dev/<resized-partition> mydisk
  5. Check with pvscan, vgscan, lvscan that LVM objects are found
  6. resize physical volume with pvresize
  7. resize volume group with vgextend -l+100%FREE ...
  8. resize logical volume with lvextend -l+100%FREE <LV-Path>
  9. Run e2fsck -f <LV-Path> on resized LV
  10. resize filesystem with resize2fs <LV-Path>
  11. mount new disk and check that filesystem grew in size.
⚠️ **GitHub.com Fallback** ⚠️