DEV Community

loading...

Discussion on: Extending LVM partition in Linux?

Collapse
cdemont007 profile image
Christophe Demont

A full detailed steps to resize a /var partition with LVM and VMware vdisk

1) Shutdown VM and delete snapshots
2) Extend the virtual disk to the desired size
3) Reboot the VM
4) Resize /sda2 extended partition
5) Resize /sda5 (virtual) LVM accordingly
6) Use LVM tools to resize the desired logical volume (ex /var)


BEFORE RESIZE OF VDISK

root@lnxvoicalendar01:~# fdisk -l
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: dos
Disk identifier: 0xd52d11a4

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   499711   497664  243M 83 Linux
/dev/sda2       501758 83884031 83382274 39.8G  5 Extended
/dev/sda5       501760 83884031 83382272 39.8G 8e Linux LVM


Disk /dev/mapper/uctoolbox--vg-root: 7.8 GiB, 8308916224 bytes, 16228352 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/uctoolbox--vg-swap_1: 1020 MiB, 1069547520 bytes, 2088960 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/uctoolbox--vg-tmp: 576 MiB, 603979776 bytes, 1179648 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/uctoolbox--vg-home: 4.7 GiB, 4999610368 bytes, 9764864 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/uctoolbox--vg-var: 25.8 GiB, 27707572224 bytes, 54116352 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


AFTER RESIZE OF VDISK and reboot

root@uctoolbox:~# fdisk -l
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: dos
Disk identifier: 0xd52d11a4

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   499711   497664  243M 83 Linux
/dev/sda2       501758 83884031 83382274 39.8G  5 Extended
/dev/sda5       501760 83884031 83382272 39.8G 8e Linux LVM




Disk /dev/mapper/uctoolbox--vg-root: 7.8 GiB, 8308916224 bytes, 16228352 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/uctoolbox--vg-swap_1: 1020 MiB, 1069547520 bytes, 2088960 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/uctoolbox--vg-tmp: 576 MiB, 603979776 bytes, 1179648 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/uctoolbox--vg-home: 4.7 GiB, 4999610368 bytes, 9764864 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/uctoolbox--vg-var: 25.8 GiB, 27707572224 bytes, 54116352 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

Need to resize the filesystem to extend /var

apt-get install parted

parted /dev/sda
(parted) print free

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 256MB 255MB primary ext2 boot
256MB 257MB 1048kB Free Space
2 257MB 42.9GB 42.7GB extended
5 257MB 42.9GB 42.7GB logical lvm
42.9GB 85.9GB 43.0GB Free Space

(parted) resizepart 2

End? [42.9GB]? 80GB

(parted)

(parted) print free

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 256MB 255MB primary ext2 boot
256MB 257MB 1048kB Free Space
2 257MB 80.0GB 79.7GB extended
5 257MB 42.9GB 42.7GB logical lvm
42.9GB 80.0GB 37.1GB Free Space
80.0GB 85.9GB 5899MB Free Space

(parted) resizepart 5
End? [42.9GB]? 80GB

(parted)

(parted) print free

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 256MB 255MB primary ext2 boot
256MB 257MB 1048kB Free Space
2 257MB 80.0GB 79.7GB extended
5 257MB 80.0GB 79.7GB logical lvm
80.0GB 85.9GB 5899MB Free Space
quit

pvresize /dev/sda5
Physical volume "/dev/sda5" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

then use 'lvdisplay' to get the LV path

lvdisplay
--- Logical volume ---
LV Path /dev/uctoolbox-vg/root
LV Name root
VG Name uctoolbox-vg
LV UUID THOVSb-Zh9S-wGCc-dWwf-Onl1-tbSo-UxCHTo
LV Write Access read/write
LV Creation host, time uctoolbox-dev, 2019-04-06 20:29:13 +0200
LV Status available
# open 1
LV Size 7.74 GiB
Current LE 1981
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 256 Block device 254:0

--- Logical volume ---
LV Path /dev/uctoolbox-vg/swap_1
LV Name swap_1
VG Name uctoolbox-vg
LV UUID 19bh25-4Egk-Xeij-k95D-LJkw-sO6w-ebl4R3
LV Write Access read/write
LV Creation host, time uctoolbox-dev, 2019-04-06 20:29:14 +0200
LV Status available
# open 2
LV Size 1020.00 MiB
Current LE 255
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 256 Block device 254:1

--- Logical volume ---
LV Path /dev/uctoolbox-vg/tmp
LV Name tmp
VG Name uctoolbox-vg
LV UUID hF1NTE-9YBh-VTZo-mMcT-Zfpd-WZ4O-WBl070
LV Write Access read/write
LV Creation host, time uctoolbox-dev, 2019-04-06 20:29:14 +0200
LV Status available
# open 1
LV Size 576.00 MiB
Current LE 144
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 256 Block device 254:2

--- Logical volume ---
LV Path /dev/uctoolbox-vg/home
LV Name home
VG Name uctoolbox-vg
LV UUID EDngfk-tjZ0-FHwZ-kPtN-hHDH-VaYQ-yN5wvv
LV Write Access read/write
LV Creation host, time uctoolbox-dev, 2019-04-06 20:42:16 +0200
LV Status available
# open 1
LV Size 4.66 GiB
Current LE 1192
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 256 Block device 254:3

--- Logical volume ---
LV Path /dev/uctoolbox-vg/var
LV Name var
VG Name uctoolbox-vg
LV UUID 44f7qf-VlUF-7U7Z-VZA9-l9ht-XwsD-pCYQfy
LV Write Access read/write
LV Creation host, time uctoolbox-dev, 2019-04-06 20:42:42 +0200
LV Status available
# open 1
LV Size 25.80 GiB
Current LE 6606
Segments 2
Allocation inherit
Read ahead sectors auto

  • currently set to 256 Block device 254:4

lvextend -L+34G /dev/uctoolbox-vg/var
Size of logical volume uctoolbox-vg/var changed from 25.80 GiB (6606 extents) to 59.80 GiB (15310 extents).
Logical volume uctoolbox-vg/var successfully resized.

resize2fs -p /dev/uctoolbox-vg/var
resize2fs 1.43.4 (31-Jan-2017)
Filesystem at /dev/uctoolbox-vg/var is mounted on /var; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 8
The filesystem on /dev/uctoolbox-vg/var is now 15677440 (4k) blocks long.

AFTER ALL OPERATIONS:

root@uctoolbox:~# fdisk -l
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: dos
Disk identifier: 0xd52d11a4

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 156250000 155748243 74.3G 5 Extended
/dev/sda5 501760 156250000 155748241 74.3G 8e Linux LVM

Disk /dev/mapper/uctoolbox--vg-root: 7.8 GiB, 8308916224 bytes, 16228352 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/uctoolbox--vg-swap_1: 1020 MiB, 1069547520 bytes, 2088960 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/uctoolbox--vg-tmp: 576 MiB, 603979776 bytes, 1179648 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/uctoolbox--vg-home: 4.7 GiB, 4999610368 bytes, 9764864 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/uctoolbox--vg-var: 59.8 GiB, 64214794240 bytes, 125419520 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