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 |
- Make a backup.
- Preparation: copy old disk to new disk (using
ddcommand). 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. - 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.
- Open the encrypted block device with
cryptsetup open /dev/<resized-partition> mydisk - Check with
pvscan,vgscan,lvscanthat LVM objects are found - resize physical volume with
pvresize - resize volume group with
vgextend -l+100%FREE ... - resize logical volume with
lvextend -l+100%FREE <LV-Path> - Run
e2fsck -f <LV-Path>on resized LV - resize filesystem with
resize2fs <LV-Path> - mount new disk and check that filesystem grew in size.