lv root drive full on CentOS - how can I extend the partition?

8,396

One way you could do this (assuming you don't have any unused space) would be to shrink /home and allocate it to /

Shrinking a logical volume is harder then growing it (because of the filesystem), so you would want to back up first. You may be able to get away with the following command to "free up" 100GB of space for the lvm:

lvreduce --resizefs --size -100G /dev/mapper/vg_mycentos-lv_home

If this works, you can then grow the root lvm as follows:

lvextend -L+100G /dev/mapper/vg_mycentos-lv_root

to extend the LV by 100GB, then:

resize4fs /dev/mapper/vg_mycentos-lv_root

to grow the filesystem. This can be done online. Note that some operating systems use resize2fs to resize ext4 partitions, so you might need to use that instead. This all assumes you are using EXT4 volumes - a reasonable, but not guaranteed assumption.

If you need to use /dev/sdb - you are going to need to:

  1. Copy /var/www to (for example) /home/var/www
  2. unmount /var/www
  3. Allocate /dev/sdb1 to the lvm (Something like pvcreate /dev/sdb1)
  4. Allocate the resource to the volume group (vgextend vg_mycentos /dev/sdb1)
  5. Use lvextend and resize2fs as above to grow the root partition.
  6. Move /home/var/www to /var/www (which is now in the LVM root partition)

You could - if you really wanted to - create another partition for /var/www and mount that using fstab rather then go through step 6.

Share:
8,396

Related videos on Youtube

user3265051
Author by

user3265051

Updated on September 18, 2022

Comments

  • user3265051
    user3265051 over 1 year

    My lv_root drive is full - I believe it's 50GB. I couldn't find an option to extend it when I installed CentOS.

    I've installed a second drive where I have my /var/www which mounted fine.

    How can I increase the size of the /dev/mapper/vg_mycentos-lv_root parition without crashing my server? I can't do any more backups because I have no other disks left to back up to (I live in a very poor country).

    I searched for this issue a lot on Super User and each setup seems different. I really want to ensure I don't crash the server and end up deleting things I'm not supposed to.

    Below are the results of df:

    [root@mycentos ~]# df
    
    Filesystem                     1K-blocks      Used Available Use% Mounted on
    /dev/mapper/vg_mycentos-lv_root  51606140  51589756         0 100% /
    tmpfs                            1943564        68   1943496   1% /dev/shm
    /dev/sda1                         495844    125974    344270  27% /boot
    /dev/mapper/vg_mycentos-lv_home 905319440  80408528 778923280  10% /home
    /dev/sdb1                      961432232 221911100 690683124  25% /var/www
    
    • Paul
      Paul about 10 years
      Your home and var/www partitions are separate, so it is difficult to see what might be using all that space. Have you checked you don't have a runaway log in /var/log ?
    • davidgo
      davidgo about 10 years
      Can you provide the output of the following command[s] pvs;vgs;lvs - This will tell us how your LVM is structured, and if this is possible.
    • user3265051
      user3265051 about 10 years
      Hi Paul, i deleted all logs, i dont know Centos would make it so confusing and give very little space for var on default let alone the root drive. and make it very confusing to change things, windows server was very easy, even straight forward linux was easy.
    • davidgo
      davidgo about 10 years
      A simpler alternative to resizing LVM partitions could be to move parts of the filesystem. If the logs are taking up space, you can always move that directory to /home/var/log - for example by using the commands /etc/init.d/syslog stop; mkdir /home/var; mv /var/log /home/; ln -s /home/var/log /var/log - I've not tried this, and you may need to stop syslog (or rsyslog) before you do this and restart it afterwards.
  • user3265051
    user3265051 about 10 years
    thanK you but /var/www is already on a different drive i believe, i mount it each time i boot. when ever i try to resize i get this error lvextend -L +6G /dev/mapper/vg_mycentos-lv_root Extending logical volume lv_root to 56.00 GiB Insufficient free space: 1536 extents needed, but only 0 available
  • davidgo
    davidgo about 10 years
    You appear to be confusing free space on the filesystem with unallocated space on the volume group. If you reread my posts you will see that I have (a) requested information about your LVM setup which you did not provide - which will confirm that your space is totally allocated - and what resources your OS sees and (b) told you 2 ways to juggle things around so you can re-allocate space to your root partition - either by shrinking another partition under control of LVM or by adding /dev/sdb into the LVM
  • user3265051
    user3265051 about 10 years
    if i didnt provide anything sorry- i got confused - i find people over complicate things (you didnt) so my brain power was used up from s reading a ton of docs. i will figure th out what you want and post it.
  • user3265051
    user3265051 about 10 years
    i have located your request David- it was in the comment section, remember im new so i didnt notice where that was.
  • user3265051
    user3265051 about 10 years
    # pvs;vgs;lvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_mycentos lvm2 a-- 931.02g 0 VG #PV #LV #SN Attr VSize VFree vg_mycentos 1 3 0 wz--n- 931.02g 0 LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_home vg_mycentos -wi-ao---- 877.14g lv_root vg_mycentos -wi-ao---- 50.00g lv_swap vg_mycentos -wi-ao---- 3.88g
  • davidgo
    davidgo about 10 years
    This output does indeed show that you have no space free on the Volume Group (and only /dev/sda2 in the volume group), which explains why you can't expand the root volume without either expanding the LVM or reclaiming the space.