0

I have increased the size of the extended and logical partitions in my Ubuntu VM as described here: Adding free unpartitioned space to the main Ubuntu partition

Now I want to add these new sectors to my current file system. My disk filesystems are (as seen by using df -h ):

Filesystem                    Size  Used Avail Use% Mounted on
udev                          2.0G     0  2.0G   0% /dev
tmpfs                         396M  8.1M  388M   3% /run
/dev/mapper/vagrant--vg-root   38G   14G   23G  37% /
tmpfs                         2.0G     0  2.0G   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                         2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1                     472M   48M  401M  11% /boot
vagrant                       477G  399G   78G  84% /vagrant
shared_directory              477G  399G   78G  84% /shared_directory
tmpfs                         396M     0  396M   0% /run/user/1000

The file system that I need to increase in size in order to make use of this space is /dev/mapper/vagrant--vg-root.

The corresponding devices are sda2 and sda5

sudo fdisk /dev/sda <<< "p"

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sda1  *       2048    999423    997376   487M 83 Linux
/dev/sda2       1001470 230195199 229193730 109.3G  5 Extended
/dev/sda5       1001472 230195199 229193728 109.3G 83 Linux

I tried using resize2fs on these, but with no effect:

vagrant@dsvm:~$ sudo resize2fs /dev/mapper/vagrant--vg-root
resize2fs 1.42.13 (17-May-2015)
The filesystem is already 10097664 (4k) blocks long.  Nothing to do!


vagrant@dsvm:~$ sudo resize2fs /dev/mapper/vagrant--vg-root 26214400
resize2fs 1.42.13 (17-May-2015)
The containing partition (or device) is only 10097664 (4k) blocks.
You requested a new size of 26214400 blocks.


vagrant@dsvm:~$ sudo resize2fs /dev/sda2
resize2fs 1.42.13 (17-May-2015)
resize2fs: Attempt to read block from filesystem resulted in short read while trying to open /dev/sda2
Couldn't find valid filesystem superblock.


vagrant@dsvm:~$ sudo resize2fs /dev/sda5
resize2fs 1.42.13 (17-May-2015)
resize2fs: Device or resource busy while trying to open /dev/sda5
Couldn't find valid filesystem superblock.

What should I do to incorporate this space into my filesystem?


As per the request in the comments, the results of pvdisplay and lvdisplay after performing the suggested actions.

pvdisplay

  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               vagrant-vg
  PV Size               109.29 GiB / not usable 2.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              27977
  Free PE               9861
  Allocated PE          18116
  PV UUID               rsXeaK-LWoy-XJGD-ZfCK-BjFM-3zvn-nqMD14

lvdisplay

  --- Logical volume ---
  LV Path                /dev/vagrant-vg/root
  LV Name                root
  VG Name                vagrant-vg
  LV UUID                zkQ8lz-Ghpb-gCGi-WO5Y-m7Ga-JUeH-8hy5Ds
  LV Write Access        read/write
  LV Creation host, time vagrant, 2017-10-27 20:31:10 +0000
  LV Status              available
  # open                 1
  LV Size                69.77 GiB
  Current LE             17860
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0 
4
  • Thanks for following me on this saga ;) For sudo lvextend -l /dev/mapper/vagrant--vg-root I get New size of 0 not permitted
    – Lafayette
    Commented Mar 14, 2018 at 14:55
  • Curiously /dev/sda5's type was Linux LVM before I deleted it and rewrote it, now its type is Linux. Should I be worried?
    – Lafayette
    Commented Mar 14, 2018 at 14:57
  • Linux doesn't mind too much about partition types... but it would be worth setting it back properly (use fdisk --> t --> 8e - I updated the other answer)
    – Attie
    Commented Mar 14, 2018 at 15:01
  • Sorry, sudo lvextend -l 100%FREE /dev/mapper/vagrant--vg-root was what I used (and got that message), I just incorrectly copied it here at first. (I get a command parsing error if I input the command without 100%FREE)
    – Lafayette
    Commented Mar 14, 2018 at 15:01

1 Answer 1

2

As the partition size has changed, you'll need to update the size of the Physical Volume:

pvresize /dev/sda5

This should output a value that is approximately the same size as the partition.

Then, resize the Logical Volume:

lvresize -l +100%FREE /dev/mapper/vagrant--vg-root

If the filesystem is not mounted, you should do a full filesystem check: (you can probably skip this)

e2fsck -f /dev/mapper/vagrant--vg-root

And finally resize the filesystem:

resize2fs /dev/mapper/vagrant--vg-root
7
  • For pvresize /dev/mapper/vagrant--vg-root I got Failed to find physical volume "/dev/vagrant-vg/root". So I tried a physical volume instead: pvresize /dev/sda5 I got ` Physical volume "/dev/sda5" changed 1 physical volume(s) resized / 0 physical volume(s) not resized` I continued as per your instructions from that point and it worked - the size was indeed increased! df -h yielded: /dev/mapper/vagrant--vg-root 69G 14G 53G 20% / Although I wonder why I got only 69G as the size of /dev/sda2 and /dev/sda2 is 109.3G ...
    – Lafayette
    Commented Mar 14, 2018 at 15:41
  • Regarding the 69GB vs 109GB... that sounds odd.. can you run pvdisplay and lvdisplay and post the output in your question?
    – Attie
    Commented Mar 14, 2018 at 16:15
  • Gladly! (Added to original question as space is insufficient)
    – Lafayette
    Commented Mar 14, 2018 at 16:19
  • I managed to drop a + from the command... specifying 100%FREE will set the size of the logical volume to the free space (you had ~70GiB free)... we actually wanted +100%FREE to extend the lv by 100% of the free space.
    – Attie
    Commented Mar 14, 2018 at 16:52
  • 1
    Tried it from the clone with the "+": ` Size of logical volume vagrant-vg/root changed from 69.77 GiB (17860 extents) to 108.29 GiB (27721 extents). Logical volume root successfully resized.` ` resize2fs /dev/mapper/vagrant--vg-root resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/mapper/vagrant--vg-root is mounted on /; on-line resizing required old_desc_blocks = 5, new_desc_blocks = 7 The filesystem on /dev/mapper/vagrant--vg-root is now 28386304 (4k) blocks long.` df -h : /dev/mapper/vagrant--vg-root 107G 14G 89G 13% / Success! Thank you very much :)
    – Lafayette
    Commented Mar 14, 2018 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .