How to add space to /dev/mapper/root_vg-rootdir

Latest response

Hello all. I had one of my programmers ask me to increase the space on the "/" directory. Coming from a windows background I didn't think this would be difficult but I have not had a good time with this. I've been able to increase the size within fdisk to include the space I added via VMware after some time. But now im getting stuck on how to add that space to the filesystem that "/" is listed under, in this case /dev/mapper/root_vg-rootdir.

When running fdisk -l i can see that ive successfully added the new space to /dev/sda5. You can see that here:

[root@slplaygroundt1 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk identifier: 0x00063516

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    12591103     5245952   8e  Linux LVM
/dev/sda3        12591104    16793599     2101248   8e  Linux LVM
/dev/sda4        16793600   104857599    44032000    5  Extended
/dev/sda5        16795648   104857599    44030976   83  Linux

Disk /dev/mapper/root_vg-rootdir: 18.2 GB, 18241028096 bytes, 35627008 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/swap_vg-swap: 2147 MB, 2147483648 bytes, 4194304 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/home_vg-home: 5368 MB, 5368709120 bytes, 10485760 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

And then you can see the files system im trying to add it to here:

   [root@slplaygroundt1 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/root_vg-rootdir   17G  2.0G   16G  12% /
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  234M  7.6G   3% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                   1014M  180M  835M  18% /boot
/dev/mapper/home_vg-home     5.0G   33M  5.0G   1% /home
tmpfs                        1.6G     0  1.6G   0% /run/user/1648050250   

Ive been pouring over documents, red hat related and not but iv gotten sorta stuck. Anyone have a clue or a pointer in the right direction?

Responses

Hi Josh,

minor detail: Linux allows 4 primary partitions, if you do not need extra partitions in the future

Is /dev/sda5 a new partition or a partition you resized?

Let us assume that /dev/sda5 is brand new.

 vgextend root_vg /dev/sda5
 lvextend -l 100%VG -r /dev/root_vg/rootdir

If not you need to run pvresize

   pvresize /dev/sda5
   lvextend -l 100%VG -r /dev/root_vg/rootdir

now check the new size of the root file system.

df -h /

Regards,

Jan Gerrit Kootstra

So thats the interesting part. Its both new and old. I deleted the both /dev/sda4 and /dev/sda5 and remade them just larger. However i went ahead and ran your commands and this is what I got back.

[root@slplaygroundt1 ~]# vgextend root_vg /dev/sda5
  Can't open /dev/sda5 exclusively.  Mounted filesystem?

[root@slplaygroundt1 ~]# lvextend -l 100%VG -r /dev/root_vg/rootdir
  Size of logical volume root_vg/rootdir unchanged from <16.99 GiB (4349 extents).
  Logical volume root_vg/rootdir successfully resized.

Im sure this is a simplistic statement but I really do feel like im missing something obvious here.

Hi Josh,

The issue we need to fix is the error message created by vgextend

Can't open /dev/sda5 exclusively. Mounted filesystem?

Please run the commands below:

 df -h
 mount | grep sda5
 partprobe /dev/sda5

Regards,

Jan Gerrit

Hi Jan, so running the commands requested returned the following.

[root@slplaygroundt1 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/root_vg-rootdir   17G  2.0G   16G  12% /
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  258M  7.5G   4% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                   1014M  180M  835M  18% /boot
/dev/mapper/home_vg-home     5.0G   33M  5.0G   1% /home
tmpfs                        1.6G     0  1.6G   0% /run/user/1648050250
[root@slplaygroundt1 ~]# mount | grep sda5
[root@slplaygroundt1 ~]# partprobe /dev/sda5

Hi Josh,

try the vgextend once more

if it fails again run pvs and show the output.

If you see a reference to another volumegroup then root_vg on /dev/sda5 the error message is confusing.

It might be good to open a support case, if you have the possibility.

Regards,

Jan Gerrit

Hi Jan, So I went ahead and ran vgextend again. This was the output this time.

[root@slplaygroundt1 ~]# vgextend root_vg /dev/sda5
  Can't open /dev/sda5 exclusively.  Mounted filesystem?

So the return changed but not sure for worse or better. But just for posterity I also ran pvs to see what its going to show. This is what it gave me:

[root@slplaygroundt1 ~]# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda2  home_vg lvm2 a--    5.00g    0 
  /dev/sda3  swap_vg lvm2 a--    2.00g    0 
  /dev/sda5  root_vg lvm2 a--  <16.99g    0 

I dont believe we have the option of opening up a support case but I will double check. I am very appreciative of your assistance though. Its been nice to have a clear head join me on this struggle.

Hi Josh,

We missed a detail, which pvs just showed us.

We try to add a partition that is already part of the volumegroup.

Can you try to run pvresize /dev/sda5?

After that run pvs once more.

Regards,

Jan Gerrit

Worse case you need a reboot to get the new size activated.

Hi Jan, It looks like the pvresize command did the trick.

[root@slplaygroundt1 ~]# pvs
  PV         VG      Fmt  Attr PSize   PFree 
  /dev/sda2  home_vg lvm2 a--    5.00g     0 
  /dev/sda3  swap_vg lvm2 a--    2.00g     0 
  /dev/sda5  root_vg lvm2 a--  <41.99g 25.00g

The next question I have is how to get that space added to the / directory. df -h shows this:

[root@slplaygroundt1 ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/root_vg-rootdir   17G  2.0G   16G  12% /
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  9.4M  7.8G   1% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                   1014M  180M  835M  18% /boot
/dev/mapper/home_vg-home     5.0G   33M  5.0G   1% /home
tmpfs                        1.6G     0  1.6G   0% /run/user/1648050250

I would like to add the space to the /dev/mapper/root_vg-rootdir filesystem. Thankyou for the assistance on this. You have been extreamly helpful.

Good morning! I got it working. First I had to go back and use the

lvextend -l

Then I tried to use resize2fs but was giving me this error:

[root@slplaygroundt1 ~]# resize2fs /dev/mapper/root_vg-rootdir 
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/root_vg-rootdir
Couldn't find valid filesystem superblock.

So I googled this and it came to this command:

xfs_growfs

So Im all good now. Im just going to replicate the whole process for my documentation and work flow. Thanks for the help!

Hi Josh,

A trick I like to mention to avoid confusion whether to use resize2fs or xfs_growfs.

  • lvextend -L wanted_size -r logical_volume_path
  • lvextend -l number_of_LE -r logical_volume_path
  • lvextend -l VolumeGroupSize% -r logical_volume_path

the -r option resizes the filesystem using the appropriate command based on a detected filesystem structure.

Regards,

Jan Gerrit Kootstra