1

I recently upgraded my VPS's HDD space from 80 > 160gb, but it is not showing the changes other than when viewing it in fdisks.

root@localhost:~# df -h
Filesystem             Size  Used Avail Use% Mounted on
udev                   3.9G     0  3.9G   0% /dev
tmpfs                  794M  1.2M  793M   1% /run
/dev/mapper/vg00-lv01   77G   31G   43G  43% /
tmpfs                  3.9G   16K  3.9G   1% /dev/shm
tmpfs                  5.0M     0  5.0M   0% /run/lock
tmpfs                  3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1              456M  145M  278M  35% /boot
tmpfs                  794M     0  794M   0% /run/user/0

root@localhost:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 160 GiB, 171798691840 bytes, 335544320 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: dos
Disk identifier: 0x520f1760

Device     Boot  Start       End   Sectors   Size Id Type
/dev/sda1  *      2048    999423    997376   487M 83 Linux
/dev/sda2       999424 335544286 334544863 159.5G 8e Linux LVM

I have tried to use resize2fs but I get:

root@localhost:~# resize2fs /dev/mapper/vg00-lv01 
resize2fs 1.45.5 (07-Jan-2020)
The filesystem is already 20345856 (4k) blocks long.  Nothing to do!

I've a feeling I needed to create a new partition to be able to do this?

To make matters more confusing for me vgdisplay shows that there is no free space:

root@localhost:~# vgdisplay vg00
  --- Volume group ---
  VG Name               vg00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <79.52 GiB
  PE Size               4.00 MiB
  Total PE              20357
  Alloc PE / Size       20357 / <79.52 GiB
  Free  PE / Size       0 / 0   
  VG UUID               ZRC0sL-qOeU-Uyfp-Qbo4-m06c-CwEt-xpFTsO
Jamie Hutber
  • 121
  • 3
  • 7
  • 17

2 Answers2

1

When you extend the disk for your OS, you need to do some tasks for extendig it for lvm:

  1. If you don't want to reboot the system, you need to rescan disk for seek new size, e.g for /dev/sda:

    echo 1 > /sys/block/sda/device/rescan

you'll see new space for disk (160G)

  1. Next, you need to extend partition, which belongs pv

    parted /dev/sda 2 resizepart 100%

  2. After that, resize pv:

    pvresize /dev/sda2

And just resize your lv and fs:

lvextend -l+100%FREE -r /dev/mapper/vg00-lv01

NOTE: Flag '-r' for lvextend:

-r|--resizefs
         Resize underlying filesystem together with the LV using fsadm(8).

But you can resize underlying fs yourself, depend of your fs-type:

xfs: xfs_growfs /
ext: resize2fs /
spybull
  • 408
  • 4
  • 5
  • Thanks @spybull. `parted /dev/sda 2 resizepart 100%` actually just outputs gparted help menu as its not a valid command it seems. So I tried `$ parted; $ (parted) resizepart 100% Error: /dev/sda2: unrecognised disk label ` – Jamie Hutber Jan 07 '22 at 22:49
0

From inside your VM you have to check whether you can see the new space availlable.

fdisk -l /dev/sda  #or whatever your main device is

so you will see if you have some more space than your original 80G, sometimes you need to stop your VM and restart it, most of the time a reboot may be enough for the kernel to detect space changes, but if you can't try one of these solution:

sfdisk -R /dev/sda
partx -a /dev/sda
kpartx -a /dev/sda
hdparm -z /dev/sda
blockdev --rereadpt /dev/sda
partprobe  /dev/sda

from now you may have some free space on your device and you got two way to exploit them, (1)you can extend your original partition or (2)you can add a new one.

to extend your partition(1)

pvs #this will give you the used partitions here 2 for the example 
parted /dev/sda resizepart 2      159GB
       ^disk    ^cmd       ^part# ^pos.last.sector

last number should be the desired end position so the max size you will be able to use.

to add a second partition(2) just use fdisk sfdisk gdisk or like, and add a partition at the end and tag it 8e or 8E00 if using GPT partition table format. Then add this second partition to your LVM.

pvcreate /dev/sda3
vgextend  vg00 /dev/sda3 

from now you may have some free space reported on your Volume group by vgs or vgdisplay and you can just extend your volumes.

dominix
  • 524
  • 1
  • 5
  • 14