It is quite common to deploy virtual machines from templates, which means their disks often need to be expanded afterward. I decided to leave this note here as a quick reference with the required commands for extending a partition on Astra Linux 1.8 using LVM.
1) Check the available disks
sudo lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 101G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 29.5G 0 part
├─astra--vg-root 252:0 0 28.6G 0 lvm /
└─astra--vg-swap_1 252:1 0 980M 0 lvm [SWAP]
sr0
2) Force the system to rescan the disk.
This allows the operating system to detect the new virtual disk size.
sudo echo 1 > /sys/class/block/sda/device/rescan
Then verify the disk layout again:
sudo lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 101G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 29.5G 0 part
├─astra--vg-root 252:0 0 28.6G 0 lvm /
└─astra--vg-swap_1 252:1 0 980M 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
3) Install Parted and extend the partition
This step is optional. You can use fdisk instead, but I find parted more convenient.
Install Parted:
sudo apt update && sudo apt -y install parted
Start the utility:
sudo parted
Display the partition table:
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 108GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 512MB 511MB primary ext2 boot
2 513MB 32,2GB 31,7GB extended
5 513MB 32,2GB 31,7GB logical lvm
Resize the partitions:
(parted) resizepart 2 100%
(parted) resizepart 5 100%
(parted) quit
If there are no errors, reload the partition table and verify the changes:
sudo partprobe /dev/sda
sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 101G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 100,5G 0 part
├─astra--vg-root 252:0 0 28,6G 0 lvm /
└─astra--vg-swap_1 252:1 0 980M 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
4) Extend the LVM volume
First, check the physical volumes (PV):
sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 astra-vg lvm2 a-- <29.52g 0
Resize the physical volume:
sudo pvresize /dev/sda5
sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 astra-vg lvm2 a-- <100.52g 71.00g
Next, check the logical volumes (LV):
sudo lvscan
ACTIVE '/dev/astra-vg/root' [28.56 GiB] inherit
ACTIVE '/dev/astra-vg/swap_1' [980.00 MiB] inherit
Extend the root logical volume:
sudo lvextend -l +100%FREE /dev/astra-vg/root
sudo lvs
LV VG Attr LSize
root astra-vg -wi-ao---- 99.56g
swap_1 astra-vg -wi-ao---- 980.00m
5) Resize the filesystem
Finally, resize the filesystem to use the newly allocated space:
resize2fs /dev/astra-vg/root
resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/astra-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 13
The filesystem on /dev/astra-vg/root is now 26099712 (4k) blocks long.
6) Verify the result
df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 824K 1.6G 1% /run
/dev/mapper/astra--vg-root 98G 5.6G 88G 6% /
tmpfs 7.9G 8.0K 7.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda1 455M 164M 267M 39% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/1000z0_0_0x0_0x0
