ddrescue
Example Scanario
In this scanario I have a 120GB drive that is 17% wearing level left that is "hanging" sometimes and its time to write to a brand new
Once we have booted the drive we want to rize the lvm partition from 120GB to 240GB
-
NOTE: Double check so we working on the right drive
```bash parted /dev/sdb -s print Model: KINGSTON SA400S37240G (scsi) Disk /dev/sdb: 240GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags:
Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB 1 bios_grub 2 2097kB 1000MB 998MB fat32 2 boot, esp 3 1000MB 128GB 127GB 3
```
Resize Part
parted /dev/sdb resizepart 3 100%
Information: You may need to update /etc/fstab.
(03:24:13)-[root@localhost] /home/wuseman $ parted /dev/sdb -s print
Model: KINGSTON SA400S37240G (scsi)
Disk /dev/sdb: 240GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB 1 bios_grub
2 2097kB 1000MB 998MB fat32 2 boot, esp
3 1000MB 240GB 239GB 3
The Alignment Trap (LUKS2 + 4K Sectors)
When resizing a LUKS2 partition on a drive with 4K physical sectors, using parted with 100% can lead to a boot failure with the error:
device-mapper: reload ioctl failed: Invalid argument.
This is because the partition must end on a sector that is a multiple of 8 (512B * 8 = 4096B).
Correct Resize Method (Manual Alignment)
Instead of parted, use fdisk to ensure the partition ends on a mathematically "clean" sector.
- Open the drive:
- Delete the LUKS partition (usually 3):
Enter
d, then3. - Create a new partition with the EXACT same start sector:
Enter
n, then3. Use the same start sector as before (e.g.,1953792). - Calculate a safe end sector (Total sectors on disk - 2048 or a number divisible by 8):
For a 240GB Kingston, the magic number is often
468862087. - CRITICAL: When asked to remove the signature, answer N (No).
- Change type to Linux LVM:
Enter
t, then30(or the aliaslvm). - Write and exit:
Enter
w.
Expand the Decrypted Stack
Once the partition table is corrected and the device is opened, expand the layers from the inside out.
# 1. Open the LUKS container
cryptsetup luksOpen /dev/sdb3 rootfs
# 2. Resize the LUKS layer to match the new partition size
cryptsetup resize rootfs
# 3. Inform LVM that the Physical Volume has grown
pvresize /dev/mapper/rootfs
# 4. Expand the Logical Volume and the Filesystem (ext4) in one go
lvextend -l +100%FREE -r /dev/elitedesk/rootfs
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
Invalid argument |
Partition end is not 4K aligned | Delete and recreate partition ending on a sector divisible by 8. |
Device busy |
Stale device-mapper entries | Run dmsetup remove_all --force or reboot the Live-CD. |
Sector size mismatch |
LUKS header expects 4096B | Use cryptsetup luksDump to verify and align partition accordingly. |