I would like to describe how i expand the current partition to a new added hard drive under ESXi (not expanding the running hard drive/partition).
Because i saw to many tutorials, it was not clear for me how does this works.
What we have:
– 2 hard drives
– 1 of 10 GB
– 1 of 50 GB
– third one just added of 100GB (the new one)
– there is a running partition of 60 GB (aprox)
– want to expand the running partition to 150-160 GB (maximum aprox).
Using vgdisplay, i can see the current volume group:
root@librenms:~# vgdisplay
--- Volume group ---
VG Name librenms-vg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 59.52 GiB
PE Size 4.00 MiB
Total PE 15236
Alloc PE / Size 15236 / 59.52 GiB
Free PE / Size 0 / 0
VG UUID PJpe4d-WCd8-xuMZ-FWDy-hfR6-mr1A-kg1dtP
The current VG Size is 59.52 GiB and what we want is to add another 100 GiB to it.
Using the command lsblk, i can see all running partition, size and also my new added disk.
root@librenms:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 50G 0 disk
└─sdb1 8:17 0 50G 0 part
└─librenms--vg-root 253:0 0 58.5G 0 lvm /
sr0 11:0 1 1024M 0 rom
fd0 2:0 1 4K 0 disk
sdc 8:32 0 100G 0 disk
sda 8:0 0 10G 0 disk
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 9.5G 0 part
│ ├─librenms--vg-swap_1 253:1 0 1020M 0 lvm [SWAP]
│ └─librenms--vg-root 253:0 0 58.5G 0 lvm /
└─sda1 8:1 0 487M 0 part /boot
root@librenms:~# fdisk /dev/sdc
Summary here:
– sda have 10G
– sdb have 50G
– sdc is my new added hdd of 100G
Using fdisk we have to create a partition to the new added disk.
To do this we use: fdisk /dev/sdc
root@librenms:~# fdisk /dev/sdc Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognised partition table. Created a new DOS disklabel with disk identifier 0x55e0ecda. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): e Partition number (1-4, default 1): 3 First sector (2048-209715199, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): Created a new partition 3 of type 'Extended' and of size 100 GiB. Command (m for help): t Selected partition 3 Partition type (type L to list all types): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT 10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/ 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux RAID auto 1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep 1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT Partition type (type L to list all types): 8e Changed type of partition 'Extended' to 'Linux LVM'. Command (m for help): p Disk /dev/sdc: 100 GiB, 107374182400 bytes, 209715200 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: 0x55e0ecda Device Boot Start End Sectors Size Id Type /dev/sdc3 2048 209715199 209713152 100G 8e Linux LVM Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Synching disks.
Now that we have the disk create, we have to added to the current Volume Group and extend it.
root@librenms:~# pvcreate /dev/sdc3
Physical volume "/dev/sdc3" successfully created
root@librenms:~# vgextend librenms-vg /dev/sdc3
Volume group "librenms-vg" successfully extended
Now it’s added to the volume group but no extended to the partition:
root@librenms:~# vgdisplay
--- Volume group ---
VG Name librenms-vg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 159.51 GiB
PE Size 4.00 MiB
Total PE 40835
Alloc PE / Size 15236 / 59.52 GiB
Free PE / Size 25599 / 100.00 GiB
VG UUID PJpe4d-WCd8-xuMZ-FWDy-hfR6-mr1A-kg1dtP
And not extended:
root@librenms:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 798M 11M 787M 2% /run
/dev/mapper/librenms--vg-root 58G 54G 1.3G 98% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 472M 471M 0 100% /boot
tmpfs 798M 0 798M 0% /run/user/1000
Now, the magical command:
root@librenms:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 798M 11M 787M 2% /run
/dev/mapper/librenms--vg-root 156G 54G 96G 36% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 472M 471M 0 100% /boot
tmpfs 798M 0 798M 0% /run/user/1000
root@librenms:~# lvextend -r -l +100%FREE librenms-vg/root
Size of logical volume librenms-vg/root changed from 58.52 GiB (14981 extents) to 158.52 GiB (40580 extents).
Logical volume root successfully resized.
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/librenms--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 10
The filesystem on /dev/mapper/librenms--vg-root is now 41553920 (4k) blocks long.
And then reboot the system just to make sure that everything is set.
root@librenms:~# shutdown -r now
After reboot:
Last login: Sun Jan 26 09:21:33 2020 from 192.168.5.73
librenms@librenms:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 798M 8.9M 789M 2% /run
/dev/mapper/librenms--vg-root 156G 54G 96G 36% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 472M 471M 0 100% /boot
tmpfs 798M 0 798M 0% /run/user/1000
We are happy that our librenms partition is now bigger and doesn’t have only 1.3 GiB disk space left.
Later edit:
Because not all the time root is the volume group, you have to check and write down the exact one.
lvextend -r -l +100%FREE ubuntu-vg/root
Logical volume root not found in volume group ubuntu-vg.
And to check the volume group, is LV Name from the down command:
lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID dOf9NM-1Ify-Hf75-kWWI-91QJ-6FTb-vcL69A
LV Write Access read/write
LV Creation host, time ubuntu-server, 2020-02-12 17:01:11 +0000
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
currently set to 256
Block device 253:0
Back to our command:
lvextend -r -l +100%FREE ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 4.00 GiB (1024 extents) to <39.00 GiB (9983 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 5
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 10222592 (4k) blocks long.