out of space? howto upgrade and grow lvm2 luks encrypted root home harddisk

  • the process is like this: lvm2 can use a new empty partition or even harddisk to extend an existing logical volume group and logical volumes inside those volume groups: very handy eh?
  • so use lvm2 when it is expected that filesystems might fill up soon
  • WARNING! extending a ext4 filesystems over 2x disks increases the possibility of failure (if no RAID1 is used) by 50%
  • WARNING! MAKE A BACKUP OF ALL DATA!
  • connect the new (bigger) harddisk via usb-to-sata adapter
  • boot from a live-usb-stick idealy: IdealLinux2 (Debian 10.9 64Bit)
  • SIMPLIFY: DISCONNECT UNMOUNT ALL POSSIBLE PARTITIONS AND (USB)HARDDISKS!
# tested via 
su - root
apt update
apt install lvm2 cryptsetup

# first thing: find the partition in question
lsblk -fs

# might help too
alias harddisks='lsblk -o '\''NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID'\'''

# run the alias to check what is there
harddisks
# or
lsblk

# unlock luks encrypted lvm2 logical volume
cryptsetup open /dev/sda5 encrypted

# WARNING! DANGEROUS STEP!
# TRIPPLE DOUBLE CHECK THE DRIVE LETTERS ARE CORRECT! OTHERWISE: IRREVERSIBLE DATALOSS!
# clone bit-by-bit everything from
# current hd (1TB)
# new hd with more space (2TB)
dd if=/dev/sdA of=/devB; sync;

# this may take a while
# (in the case of USB 2.0 and 1TB ~6h?)
# open 2nd consoleB to monitor progress (it will be displayed in consoleA)
while true; do kill -USR1 $(pgrep ^dd) sleep 1; clear; done;

# create new partition on free space with the user's favorite tool
/dev/sda3

# init 
pvcreate /dev/sda3

vgscan

# check what is there
harddisks
lsblk
fdisk -l

# extend the volume group that holds the logical volume that user wants to extend
vgextend toplap-vg /dev/sda3

# check what is there
vgdisplay 
lvdisplay

# extend the logical volume
lvextend -l +100%FREE /dev/toplap-vg/root

# run filesystem check before ext4 resize
e2fsck -f /dev/toplap-vg/root

# resize (grow) ext4
resize2fs /dev/toplap-vg/root

# run filesystem check after ext4 resize
e2fsck -f /dev/toplap-vg/root
# also the other variant
fsck -y -v -f /dev/toplap-vg/root
# check what is there
lsblk

# test mount
mount /dev/mapper/toplap--vg-root /media/user/toplap-vg/root/
df -h|grep -E 'Filesystem|toplap'
Filesystem                           Size  Used Avail Use% Mounted on
/dev/mapper/toplap--vg-root          1.8T  833G  878G  49% / <- HURRAY! :D IT WOKRED :D

# a final sync all buffers to harddisk
sync; sync; sync; 

# reboot
shutdown -r now

# now it might look like this
harddisks
NAME                    MAJ:MIN RM   SIZE RO FSTYPE      MOUNTPOINT                  UUID
sda                       8:0    0   1.8T  0                                         
├─sda1                    8:1    0   487M  0 ext2        /boot                       8baf3fd9-xxxx...
├─sda2                    8:2    0     1K  0                                         
├─sda3                    8:3    0 931.5G  0 LVM2_member                             VoEz8O--xxxx...
│ └─toplap--vg-root     253:1    0   1.8T  0 ext4        /                           a1316d57-xxxx...
└─sda5                    8:5    0   931G  0 crypto_LUKS                             5a60122b-xxxx...
  └─sda5_crypt          253:0    0   931G  0 LVM2_member                             6mgdNm-xxxx...
    ├─toplap--vg-root   253:1    0   1.8T  0 ext4        /                           a1316d57-xxxx...
    └─toplap--vg-swap_1 253:2    0    31G  0 swap        [SWAP]                      0bbf186c-xxxx....

# celebrate 😀

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin