0

These are the steps I am trying from this answer:

Steps I ran:

  1. Run below command to get PV (Physical Volume) name (Ex: /dev/sda1)
sudo pvs
tini-wini # pvs
  PV         VG        Fmt  Attr PSize  PFree
  /dev/sda3  ubuntu-vg lvm2 a--  <9,00g    0
tini-wini #
  1. Resize the PV
sudo pvresize /dev/sda3
tini-wini # sudo pvresize /dev/sda3
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
tini-wini #
  1. Run below command to get root logical volume name (Filesystem value of / row; ex: /dev/mapper/ubuntu--vg-root)
df -h
tini-wini # df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               948M     0  948M   0% /dev
tmpfs                              199M  1,1M  198M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  8,8G  8,2G  211M  98% /
tmpfs                              992M     0  992M   0% /dev/shm
tmpfs                              5,0M     0  5,0M   0% /run/lock
tmpfs                              992M     0  992M   0% /sys/fs/cgroup
/dev/loop0                          45M   45M     0 100% /snap/snapd/15314
/dev/loop1                          62M   62M     0 100% /snap/core20/1405
/dev/loop2                          62M   62M     0 100% /snap/core20/1376
/dev/loop3                          68M   68M     0 100% /snap/lxd/22753
/dev/loop4                          56M   56M     0 100% /snap/core18/2344
/dev/loop5                          68M   68M     0 100% /snap/lxd/22526
/dev/loop6                          44M   44M     0 100% /snap/snapd/15177
/dev/loop7                          56M   56M     0 100% /snap/core18/2253
/dev/sda2                          976M  207M  703M  23% /boot
tmpfs                              199M     0  199M   0% /run/user/1000
tini-wini #
  1. Expand logical volume:
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-root
tini-wini # lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv unchanged from <9,00 GiB (2303 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.45.5 (07-Jan-2020)
The filesystem is already 2358272 (4k) blocks long.  Nothing to do!

tini-wini #

With lsblk command it´s show me that the space in disk are there.

tini-wini # lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0 44,7M  1 loop /snap/snapd/15314
loop1                       7:1    0 61,9M  1 loop /snap/core20/1405
loop2                       7:2    0 61,9M  1 loop /snap/core20/1376
loop3                       7:3    0 67,8M  1 loop /snap/lxd/22753
loop4                       7:4    0 55,5M  1 loop /snap/core18/2344
loop5                       7:5    0 67,9M  1 loop /snap/lxd/22526
loop6                       7:6    0 43,6M  1 loop /snap/snapd/15177
loop7                       7:7    0 55,5M  1 loop /snap/core18/2253
sda                         8:0    0   21G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0    1G  0 part /boot
└─sda3                      8:3    0    9G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0    9G  0 lvm  /
sr0                        11:0    1 1024M  0 rom
tini-wini #

What do I need to do in this case?

Update

fdisk -l

Disk /dev/loop0: 55,5 MiB, 58183680 bytes, 113640 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/loop1: 67,94 MiB, 71221248 bytes, 139104 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/loop2: 67,83 MiB, 71106560 bytes, 138880 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/loop3: 44,65 MiB, 46804992 bytes, 91416 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/loop4: 61,92 MiB, 64901120 bytes, 126760 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/loop5: 55,53 MiB, 58212352 bytes, 113696 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/loop6: 43,64 MiB, 45748224 bytes, 89352 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/loop7: 61,92 MiB, 64901120 bytes, 126760 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/sda: 21 GiB, 22548578304 bytes, 44040192 sectors Disk model: VBOX HARDDISK 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: 363D35B2-1971-493B-B67D-6C40297B89AB

Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 2101247 2097152 1G Linux filesystem /dev/sda3 2101248 20969471 18868224 9G Linux filesystem

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 8,102 GiB, 9659482112 bytes, 18866176 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 tini-wini #

Legna
  • 135
  • @doneal24 Done. – Legna Apr 06 '22 at 15:38
  • It looks like nothing is actually being extended, according to the messages. After pvresize, does pvs report free space (under the PFree column)? – Haxiel Apr 06 '22 at 15:46
  • 1
    Did you resize the sda3 partition first? This step is missing in your question. pvresize resizes only the PV format to size of the underlying block device. – Vojtech Trefny Apr 06 '22 at 15:51
  • @Haxiel No. I have executed these commands several times. 0 appears in the column. – Legna Apr 06 '22 at 15:58
  • @VojtechTrefny I think you mean the second step, right? This command sudo pvresize /dev/sda3. If so, yes I ran it. – Legna Apr 06 '22 at 16:00
  • 1
    No, I mean resizing the partition with fdisk or parted. As I said pvresize doesn't resize the partition (block device), just the PV format. – Vojtech Trefny Apr 06 '22 at 16:08
  • @VojtechTrefny No, I don't know how to do that. – Legna Apr 06 '22 at 16:11
  • Did you resize the harddrive? Where is "more space" supposed to come from? Include output of fdisk -l – Panki Apr 06 '22 at 16:59
  • @Panki Done. Check my update. – Legna Apr 06 '22 at 17:18
  • 1
    You're using LVM on Ubuntu Server, with this entire system running inside VirtualBox hosted on something different? If you are trying to increase the size available to Ubuntu Server, have you increased the size of its virtual disk using the appropriate VirtualBox tool? If not, there's nothing yet inside Ubuntu Server to resize. – Chris Davies Apr 06 '22 at 17:31
  • fdisk output confirms what's mentioned above - you haven't resized the partition. https://unix.stackexchange.com/questions/67095/how-to-expand-ext4-partition-size-using-command-line/67107#67107 – Panki Apr 06 '22 at 17:44
  • @roaima Yes, the change was already made in virtualbox when I executed the mentioned commands. – Legna Apr 06 '22 at 17:47
  • Please add that information to your question. Don't make it hard for people to see what's the issue – Chris Davies Apr 06 '22 at 19:14

1 Answers1

3

Based on the comments, it looks like the procedure was incomplete. This is the sequence of events that need to happen when resizing an LV on a VirtualBox VM.

  1. Start at the VirtualBox level. VirtualBox keeps VM disks as individual files on the host system. Update the size of the disk to the desired value.
  2. On the guest VM, the kernel will recognize the increase in disk size, but it's not usable yet. You need to use a tool such as fdisk, gdisk, or gparted (or other GUI equivalents) to create a partition from the extra space. You can also extend an existing partition, if the free space immediately follows the existing partition.
  3. Next, the lowest LVM level - physical volumes. If a new partition was created, run pvcreate to create a new PV from it. If you extended a partition, run pvresize to pick up the changes.
  4. On to the second layer of the LVM - volume groups. If a PV was added, you'll need to add it to the volume group using vgextend. If a PV was resized, the changes should be picked up automatically.

At this point, you should see some free space available under the target volume group.

  1. Next, the top layer of LVM - logical volumes. Extend the desired LV using lvextend to allocate the free space from your volume group. Use commands such as lsblk to figure out which LV to extend.
  2. The last step is to tell the filesystem on the LV to take up the new space. lvextend can manage this for several filesystems with the --resizefs option. Otherwise, you can use filesystem-specific tools to extend it (resize2fs for ext2/3/4, xfs_growfs for XFS etc).

You should now have a filesystem with the desired amount of extra storage space.

Haxiel
  • 8,361