1 (edited by mfleetwo 2022-03-08 11:09:31)

Topic: How do I resize file system inside encrypted, LVM on Thinkpad W530

I need to resize my partitions to create more space for the /boot partition to allow for large software updates.
The /boot partition (ext2) is approximately 500MB with about 382MB free space after a cleanup of old files.
The / partition is ext4

The W530 has a 960GB SSD HD with 32GB of memory, running Ubuntu 20.04.2 LTS with LUKS encryption on the drive.
I can get gparted live to run from the DVD drive, but cannot seem to change the partitions.
I've been able to open the encryption, but still cannot change the partition sizes.

The LVM2 PV device is /dev/mapper/sda5_crypt
The extended partition (partition 2) is /dev/sda.
The encrypted partition is /dev/sda5.
The primary partition (partition 1) is /dev/sda1.

I do have some basic screenshots but am unfamiliar with how to include them. I can see the tagging example, but the img files are on other computer, not at a URL.

2

Re: How do I resize file system inside encrypted, LVM on Thinkpad W530

Please provide the output from the following commands:

sudo parted /dev/sda unit s print
sudo fdisk -l /dev/sda
sudo gdisk -l /dev/sda
sudo lsblk -o name,maj:min,rm,size,ro,type,fstype,label,mountpoint
sudo lvm pvs -v --segments

3 (edited by mfleetwo 2022-03-08 10:11:08)

Re: How do I resize file system inside encrypted, LVM on Thinkpad W530

Thanks for the prompt reply.
Below is the output from the commands as requested.

sudo parted /dev/sda unit s print:

Model: ATA SanDisk SD8TN8U5 (scsi)
Disk /dev/sda: 1000215216s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start     End          Size        File system  Name                   Flags
 1      2048s     585727s      583680s     fat32        EFI System Partition   boot, esp
 3      585728s   1953791s     1368064s    xfs          System Boot Partition
 2      2050048s  1000214527s  998164480s               Linux filesystem

sudo fdisk -l /dev/sda:

Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 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
Disklabel type: gpt
Disk identifier: 15F2D102-6F7C-445F-8BB9-2F8F6E141CCB

Device       Start        End   Sectors  Size Type
/dev/sda1     2048     585727    583680  285M EFI System
/dev/sda2  2050048 1000214527 998164480  476G Linux filesystem
/dev/sda3   585728    1953791   1368064  668M Linux filesystem

Partition table entries are not in disk order.

sudo gdisk -l /dev/sda:

GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 1000215216 sectors, 476.9 GiB
Model: SanDisk SD8TN8U5
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 15F2D102-6F7C-445F-8BB9-2F8F6E141CCB
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 1000215182
Partitions will be aligned on 2048-sector boundaries
Total free space is 98925 sectors (48.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          585727   285.0 MiB   EF00  EFI System Partition
   2         2050048      1000214527   476.0 GiB   8300  Linux filesystem
   3          585728         1953791   668.0 MiB   8300  System Boot Partition

sudo lsblk -o name,maj:min,rm,size,ro,type,fstype,label,mountpoint:

NAME                          MAJ:MIN RM   SIZE RO TYPE  FSTYPE LABEL MOUNTPOINT
sda                             8:0    0   477G  0 disk               
├─sda1                          8:1    0   285M  0 part  vfat         /boot/efi
├─sda2                          8:2    0   476G  0 part  crypto       
│ └─luks-37263259-b3dc-40c7-bbaa-af0f7b9c9e8c
│                             253:0    0   476G  0 crypt LVM2_m       
│   ├─vg_oc2832061462-lv_swap 253:1    0  30.7G  0 lvm   swap         [SWAP]
│   └─vg_oc2832061462-lv_root 253:2    0 445.3G  0 lvm   ext4         /
└─sda3                          8:3    0   668M  0 part  xfs          /boot

sudo lvm pvs -v --segments:

  PV                                                    VG              Fmt  Attr PSize    PFree Start SSize  LV      Start Type   PE Ranges                                                        
  /dev/mapper/luks-37263259-b3dc-40c7-bbaa-af0f7b9c9e8c vg_oc2832061462 lvm2 a--  <475.96g    0      0   7856 lv_swap     0 linear /dev/mapper/luks-37263259-b3dc-40c7-bbaa-af0f7b9c9e8c:0-7855     
  /dev/mapper/luks-37263259-b3dc-40c7-bbaa-af0f7b9c9e8c vg_oc2832061462 lvm2 a--  <475.96g    0   7856 113989 lv_root     0 linear /dev/mapper/luks-37263259-b3dc-40c7-bbaa-af0f7b9c9e8c:7856-121844

4

Re: How do I resize file system inside encrypted, LVM on Thinkpad W530

I've re-titled the thread and moved it to the "GParted" forum because your issue is that the GParted application doesn't support examining or resizing LVM Logical Volumes and the file systems they contain.  Your issue is not specific to the GParted Live distribution.

Your sda3 (/boot) file system is 668 MiB and you now say it has 382 MB free, so about 50% free.  /boot file system only contains files needed to boot Linux using the latest and a few earlier versions of the installed Linux kernel.  Do you really need to make it larger?  Instead can you just delete old, unneeded packages of linux-image-*?

I ask because, as mentioned above, GParted doesn't support some of the necessary actions you need to perform so that means you will have to perform those steps manually on the Linux command line.

An overview of the steps are:
1. Boot from GParted Live or other live Linux distribution
2. Open encryption
3. Shrink / (root) file system
4. Shrink lv_root LVM Logical Volume
5. Shrink encrypted LVM Physical Volume
6. Move the start of sda3 (/boot) to the left

5 (edited by digitaldruid 2022-03-09 22:04:50)

Re: How do I resize file system inside encrypted, LVM on Thinkpad W530

Thanks. I thought the LVM might be the issue. Seem to recall reading that somwhere...
And thanks for the listing of steps that will do this manually.
Are you aware of anyplace where these steps are spelled out in detail with commands?
I'll search, but though your expertise may shorten my search...
Thanks again.

The software updater function in Unbuntu is telling me that I need more space for updates.
I've run "sudo apt autoremove" and manually checked the contents.
I deleted some older initrd.img files and related config files.
With this second effort and manual deletion, I can get the software updater to run.
We'll see how it goes...

6 (edited by mfleetwo 2022-03-10 10:10:06)

Re: How do I resize file system inside encrypted, LVM on Thinkpad W530

Please remember to backup data you care about.  This is especially important with encrypted data which can become permanently inaccessible after a failure.
https://gitlab.gnome.org/GNOME/gparted/ … /NEWS#L587
https://gitlab.com/cryptsetup/cryptsetu … a-recovery


Detailed steps:


1. Boot live media

Use GParted Live or other live Linux distribution with GParted.
(Because you can't shrink an ext4 file system while it is being used and the root file system can't be unmounted to make it unused).


2. Open LUKS encryption

Run GParted.
Select sda2, Partition > Open Encryption, enter passphrase.
Close GParted.


3. Start LVM

sudo lvm vgscan
sudo lvm vgchange -ay vg_oc2832061462

(This is just in case the LVM Volume Group was not automatically started when it appeared after the encryption mapping was create above).


4. Shrink root file system and lv_root Logical Volume

Shrink root file system and lv_root LV by 1 GiB.  Adjust shrink amount if needed.

sudo lvm lvresize --resizefs -L -1G /dev/vg_oc2832061462/lv_root

Edit: Add missing --resizefs option.


5. Shrink and move encrypted sda2 LVM Physical Volume

5.1. Run GParted.
5.2. Deactivate LVM in encrypted sda2: Partition > Deactivate.
5.3. Shrink encrypted sda2 by available 1 GiB and apply.

(There is a chance that shrinking will fail with "Cannot resize to NNNNN extents as later extents are allocated".  If so run the following so I can see the exact layout).

sudo lvm pvdisplay -m

Carry on if successful.

5.4. Close LUKS in sda2: Partition > Close Encryption
5.5. Move encrypted sda2 to the right by available 1 GiB and apply.

(This is moving 475 GiB of data so will take a while.
WARNING: If this step fails or is interrupted there is a high probability that all the encrypted data will be lost.  Heed the backup warning at the top of this post).
Edit: Add new step 5.4. to close LUKS.  Add data loss warning.


Now you can use GParted to grow sda3 /boot file system by available 1 GiB.

7

Re: How do I resize file system inside encrypted, LVM on Thinkpad W530

Thanks. I'll give it a try this weekend. I have an external USB drive that I can backup to.
I usually just backup (copy) everything in my /home directory to get all my user data.
What about a system backup? Any recommendations on tooling or methods?
I suppose I could always create a startup disk an do a re-install if I had to...

Side issue: The /boot "folder" contains a number of initrd.img files and related (by release number) config, system.map and vmlinuz files.
I assume the numerical naming scheme is that the lower numbers are older files.
For example (listing them from what I believe is newest to oldest):
File names are:

initrd.img.5.13.0-35-generic
config-5.13.0-35-generic
system.map-5.13.0-35-generic
vmlinuz-5.13.0-35-generic

initrd.img.5.13.0-30-generic
config-5.13.0-30-generic
system.map-5.13.0-30-generic
vmlinuz-5.13.0-30-generic

initrd.img.5.8.0-55-generic
config-5.8.0-55-generic
system.map-5.8.0-55-generic
vmlinuz-5.8.0-55-generic

I also have an "orphan" initrd.img.5.4.0.115-generic file as well as a vmlinuz symbolic link to the latest (5.13.0-35-generic) vmlinuz file, a vmlinuz.old file and 3 memtest86+.xxx files.

Can you tell me what "best practices" are in terms of the older files?
For instance, how many iterations of these sets of the older files should I keep around?
It seem that Ubuntu wants to keep at least 3 of them...
I'll leave the memtest86.xxx files alone.

Thanks again for all the assistance. Really appreciate it!

8

Re: How do I resize file system inside encrypted, LVM on Thinkpad W530

Re-installing and restoring personal files from backup of /home/$MYUSER is an OK solution.  That way the installer can boot the machine and recreate the storage layout.  Just make sure your backup includes all the files you want.

Keeping the 3 most recent copies of the Linux kernel installed seems to be what a number of Linux distributions do automatically when installing newer kernels.  I don't use Ubuntu, except for testing in a VM, so I'm not really sure what it does automatically.