T
T
Tail Cats2021-12-09 11:43:34
LVM
Tail Cats, 2021-12-09 11:43:34

How to expand an encrypted system drive in Ubuntu?

How to expand a system encrypted disk in Ubuntu 20.04 encrypted with LUCS + dm_crypt?

disk 500 GB, of which only 300
can be seen can this be done on the fly or do I have to boot from livecd
and not break anything

[email protected]:~$ sudo fdisk -l

Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B71D4376-398B-4D04-8182-2E50624B9520

Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/ dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 1048424447 1046323200 498.9G Linux filesystem

Disk /dev/mapper/dm_crypt-0: 498.93 GiB, 535700701184 bytes, 103229 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/ubuntu--vg-ubuntu --lv: 299.94 GiB, 322038661120 bytes, 628981760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tail Kotov, 2021-12-09
@dikiykot

I asked myself, I will answer.
preliminary situation. Booted livecd kubuntu, and through KDE Partition Manager unlocked the partition, increased it. the initial picture turned out - there was a 500 GB partition 300 on the disk.
The same can be done through the command line, booting from another system, something like this:

cryptsetup luksOpen /dev/sda3 crypt-volume
parted /dev/sda
    p
    resizepart 1
    yes
    p
    quit
vgchange -a n ubuntu-vg 
cryptsetup luksClose crypt-volume
cryptsetup luksOpen /dev/sda3 crypt-volume
cryptsetup resize crypt-volume
vgchange -a y ubuntu-vg

Next, the disk was enlarged on an ubuntu running from the same disk: Let's
look at the name of the physical volume:
[email protected]:~$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/mapper/dm_crypt-0
  VG Name               ubuntu-vg
  PV Size               <299.93 GiB / not usable 2.00 MiB

We increase it to all the free space, check
[email protected]:~$ sudo pvresize /dev/mapper/dm_crypt-0
  Physical volume "/dev/mapper/dm_crypt-0" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

We look at the result and what Volume Groups we have
[email protected]:~$ sudo pvdisplay -m
  --- Physical volume ---
  PV Name               /dev/mapper/dm_crypt-0
  VG Name               ubuntu-vg
  PV Size               <498.91 GiB / not usable 3.00 MiB

  --- Physical Segments ---
    Logical volume      /dev/ubuntu-vg/ubuntu-lv

We increase the Volume Group to the maximum
[email protected]:~$ sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <299.93 GiB (76781 extents) to <498.91 GiB (127720 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

Increasing the size of the file system
[email protected]:~$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 38, new_desc_blocks = 63
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 130785280 (4k) blocks long.

Look, everything is ready
[email protected]:~$ sudo df -h
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv  <b>491G</b>  125G  344G  27% /

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question