LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Expand disk size on centos VM? (https://www.linuxquestions.org/questions/linux-newbie-8/expand-disk-size-on-centos-vm-4175416556/)

jbennett 07-13-2012 11:46 AM

Expand disk size on centos VM?
 
I have a VM with only 10GB of disk size avaliable.

I have expanded the disk size to 120GB from the VM tools, however, I only see 10GB of space from within Linux.

I have everything already installed on this VM as I need it and would like ot expand the logical volume to the entire 120GB that's now avaliable to it without losing everything on the disk.

Do I need to use the 'lvextend' tool as described on this page?

Kustom42 07-13-2012 12:01 PM

Maybe yes, maybe no. We need to figure out your config first.


Run the following commands as root or via sudo and give us the output:

Code:

fdisk -l
pvs
vgs
lvs
df -h


jbennett 07-13-2012 12:08 PM

Code:

[root@system ~]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00024a62

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          13      102400  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        1306    10382336  8e  Linux LVM

Disk /dev/mapper/VolGroup00-LogVol01: 268 MB, 268435456 bytes
255 heads, 63 sectors/track, 32 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup00-LogVol01 doesn't contain a valid partition table

Disk /dev/mapper/VolGroup00-LogVol00: 10.4 GB, 10359930880 bytes
255 heads, 63 sectors/track, 1259 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup00-LogVol00 doesn't contain a valid partition table
[root@system ~]# pvs
  PV        VG        Fmt  Attr PSize PFree
  /dev/sda2  VolGroup00 lvm2 a--  9.90g    0
[root@system ~]# vgs
  VG        #PV #LV #SN Attr  VSize VFree
  VolGroup00  1  2  0 wz--n- 9.90g    0
[root@system ~]# lvs
  LV      VG        Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  LogVol00 VolGroup00 -wi-ao  9.65g
  LogVol01 VolGroup00 -wi-ao 256.00m
[root@system ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      9.5G  9.5G    0 100% /
tmpfs                376M    0  376M  0% /dev/shm
/dev/sda1              97M  82M  11M  89% /boot

I hope this gives the necessary information!

Kustom42 07-13-2012 12:14 PM

Your good to go, you will need to create a new partition, /dev/sda3, use pvcreate to make it a physical volume, use vgextend to extend your volume group, then use lvextend to extend your logical volume.

http://www.howtoforge.com/logical-vo...a-volume-group

http://linuxconfig.org/Linux_lvm_-_L...ate-partitions


MAKE SURE YOU SET THE PARTITION TYPE TO "8e" WHEN CREATING IT!


If you have specific questions about any of the commands or the syntax just let me know and I'll give you some examples

jbennett 07-13-2012 12:31 PM

Before I dive off into this, I'm getting the following notification:

Code:

[root@system~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').

Command (m for help):

Am I to assume I need to do as suggested?

Thanks agian.

Kustom42 07-13-2012 12:48 PM

Not a big deal on that warning, just follow the steps.

Code:

fdisk /dev/sda
p
t
3
8e
w

Those will create the necessary partition for you. Then do a:

Code:

pvcreate /dev/sda3
Now yo have another physical volume, lets add it to your volume group

Code:


vgextend /dev/VolGroup00 /dev/sda3

Now you should have that extra space as free in your volume group, you can verify it with vgdisplay.


Finally, extend your current logical volume.

Code:

lvextend -L +100G /dev/VolGroup00/LogVol01
And to make the space available to the OS, resize the filesystem:

Code:

resize2fs /dev/VolGroup00/LogVol01

jbennett 07-13-2012 12:51 PM

Quote:

Originally Posted by Kustom42 (Post 4727253)
Not a big deal on that warning, just follow the steps.

Code:

fdisk /dev/sda
p
t
3
8e
w


As seems to be the case just about any time I touch Linux, it's never straight forward.

Code:

Command (m for help): p

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00024a62

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          13      102400  83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        1306    10382336  8e  Linux LVM

Command (m for help): t
Partition number (1-4): 3
Partition 3 does not exist yet!

1) Do I need to be worried about the note: Partition 1 does not end on cylinder boundary.
2) No Partition 3...I don't think I missed a step, did I?

Or, should the order be?

Code:

fdisk /dev/sda
n
p
3
t
8e
w


Kustom42 07-13-2012 01:14 PM

Yes, I usually use cfdisk so the commands were a bit out of order. The cylinder boundary error you can ignore as well. Plenty of info on google about it that explains why that happens.


So fdisk /dev/sda

n -- Create new partition
p -- make it a primary partition(you would want to make it an extended one if this was your 4th partition so you don't limit yourself)
3 - Set the partition number
Enter through to get the default sizes which should take up all the free space.
t - modify type
3 - select partition three
8e - make it a linux lvm type partition
w - write the partition

jbennett 07-13-2012 01:31 PM

OK, done, and I get the following:

Code:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

I rebooted the machine and was able to do everything else without error, until I reached resizing the filesystem:

Code:

[root@system ~]# resize2fs /dev/VolGroup00/LogVol01
resize2fs 1.41.12 (17-May-2010)
resize2fs: Bad magic number in super-block while trying to open /dev/VolGroup00/LogVol01
Couldn't find valid filesystem superblock.

I'm not sure where to go at this point. A quick search tells me it might be a different file system type?

Code:

[root@system ~]# pvdisplay
  --- Physical volume ---
  PV Name              /dev/sda2
  VG Name              VolGroup00
  PV Size              9.90 GiB / not usable 3.00 MiB
  Allocatable          yes (but full)
  PE Size              4.00 MiB
  Total PE              2534
  Free PE              0
  Allocated PE          2534
  PV UUID              RVurOl-tESz-BgZd-M3g1-6ny4-UQaL-L7Hc0s

  --- Physical volume ---
  PV Name              /dev/sda3
  VG Name              VolGroup00
  PV Size              110.00 GiB / not usable 3.99 MiB
  Allocatable          yes
  PE Size              4.00 MiB
  Total PE              28159
  Free PE              2559
  Allocated PE          25600
  PV UUID              mhwHl3-8Ni2-RCYT-TefS-1GU3-GYA1-5ctfjK

[root@system ~]# vgdisplay
  --- Volume group ---
  VG Name              VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size              119.89 GiB
  PE Size              4.00 MiB
  Total PE              30693
  Alloc PE / Size      28134 / 109.90 GiB
  Free  PE / Size      2559 / 10.00 GiB
  VG UUID              ehy4a2-1hOw-VBqL-0TNL-i9JN-BJEh-ErOhwH

[root@system ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                x3ddq2-pUcu-u3JS-vUPQ-bNIj-XlzG-EhbT0Y
  LV Write Access        read/write
  LV Status              available
  # open                1
  LV Size                100.25 GiB
  Current LE            25664
  Segments              2
  Allocation            inherit
  Read ahead sectors    auto
  - currently set to    256
  Block device          253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                gD7mVs-PygF-XxPy-MM6m-zncd-g2nw-MxtQiM
  LV Write Access        read/write
  LV Status              available
  # open                1
  LV Size                9.65 GiB
  Current LE            2470
  Segments              1
  Allocation            inherit
  Read ahead sectors    auto
  - currently set to    256
  Block device          253:1

[root@system ~]# df -T
Filesystem    Type  1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
              ext4    9958240  9947624        0 100% /
tmpfs        tmpfs      384396        0    384396  0% /dev/shm
/dev/sda1    ext2      99150    83574    10456  89% /boot

Thanks so much for your continued help. If you were local, I would buy you a beer...or two.

Kustom42 07-13-2012 03:42 PM

Wait a second! We extended the wrong lv here...

Do the following:

Code:

lvremove /dev/VolGroup00/LogVol01
lvextend -L +100G /dev/VolGroup00/LogVol00
resize2fs /dev/VolGroup00/LogVol00

If that gives you an error then you will need to resize the filesystem off of a rescue CD, as you may get an error that you can't resize a file system that is mounted.

Kustom42 07-13-2012 04:32 PM

I think this was my fault as I told you do the lvextend on your 01 lv and not the 00 lv which doesnt appear to be in use or have a filesystem on it, it's was only 256MB before you added the other 100GB.

jbennett 07-16-2012 08:17 AM

Quote:

Originally Posted by Kustom42 (Post 4727391)
Wait a second! We extended the wrong lv here...

Do the following:

Code:

lvremove /dev/VolGroup00/LogVol01

Code:

Can't remove open logical volume "LogVol01"
:(

Quote:

If that gives you an error then you will need to resize the filesystem off of a rescue CD, as you may get an error that you can't resize a file system that is mounted.
Do I just need to follow the same methods as you listed above?

Kustom42 07-16-2012 10:53 AM

Try running lvremove with the -f option, you're not going to break anything here..

lvremove -f /dev/VolGroup00/LogVol01

If that doesn't work, add the -vvvv option and give us the output.

jbennett 07-16-2012 11:00 AM

Quote:

Originally Posted by Kustom42 (Post 4729619)
Try running lvremove with the -f option, you're not going to break anything here..

Code:

lvremove -f /dev/VolGroup00/LogVol01

I did this and it returned the following

Code:

Can't remove open logical volume "LogVol01"

Quote:

If that doesn't work, add the -vvvv option and give us the output.
I ran the following:

Code:

lvremove -f /dev/VolGroup00/LogVol01 -vvvv
and a whole bunch of text populated the screen. Unfortunately, this is on a VM and I can't copy the text over (since i'm not able to putty in while it's running from the rescue cd).

Is there a particular part that you are looking for?

Kustom42 07-16-2012 11:34 AM

Try doing:

Code:

lsof | grep -i LogVol01
See if there are any processes that have a lock on it. You don't have it mounted, so it shouldn't be giving you this error. Did you see anything in the verbose output in regards to the cause of the error? I know the -vvvv gives you alot of output but it should tell us at what point it errors.

Kustom42 07-16-2012 11:38 AM

If you don't see any open file locks run the following:

Code:


dmsetup info -c VolGroup00-LogVol01

If it shows a number "1" for the open status run the following:

Code:


dmsetup remove VolGroup00-LogVol01

You should then be able to execute the lvremove.

whizzit 07-16-2012 11:52 AM

Is LogVol01 mounted by any chance?

Code:

# lvcreate -L100M -n test /dev/vg0
  Logical volume "test" created
# mkfs -t ext3 /dev/vg0/test
mke2fs 1.42 (29-Nov-2011)
...
Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

# lvs -a /dev/vg0/test
  LV  VG  Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  test vg0  -wi-a- 100.00m                                     
# mount /dev/vg0/test /mnt/
# lvs -a /dev/vg0/test
  LV  VG  Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  test vg0  -wi-ao 100.00m                                     

# lvremove /dev/vg0/test
  Can't remove open logical volume "test"
# umount /dev/vg0/test
# lvremove /dev/vg0/test
Do you really want to remove active logical volume test? [y/n]: y
  Logical volume "test" successfully removed
# lvs -a /dev/vg0/test
  One or more specified logical volume(s) not found.


Kustom42 07-16-2012 11:56 AM

It shouldnt be mounted, from the discussion we had this new lv got created. Unless it got mounted, which I can't see it from the steps the issue here is likely a file lock or the dmsetup.

jbennett 07-16-2012 01:36 PM

Quote:

Originally Posted by Kustom42 (Post 4729656)
Try doing:

Code:

lsof | grep -i LogVol01

Code:

bash: lsof : command not found
Quote:

See if there are any processes that have a lock on it. You don't have it mounted, so it shouldn't be giving you this error. Did you see anything in the verbose output in regards to the cause of the error? I know the -vvvv gives you alot of output but it should tell us at what point it errors.
I do see the following:

Code:

Can't remove open logical volume "LogVol01"

jbennett 07-16-2012 01:43 PM

Quote:

Originally Posted by Kustom42 (Post 4729661)
If you don't see any open file locks run the following:

I'm not sure how to check if I have any open file locks, but in the output of the previous command, I do see the following:

Code:

#mm/memlock.c:389                Unlock : Memlock counters: locked:0 critical:0 daemon:0 suspended:0
#locking/file_locking.c:74        Unlocking /var/lock/lvm/V_VolGroup00
#locking/file_locking.c:51        _undo_flock /var/lock/lvm/V_VolGroup00
#device/dev-io.c:588              Closed /dev/sda2
#device/dev-io.c:588              Closed /dev/sda3


jbennett 07-16-2012 01:46 PM

Quote:

Originally Posted by whizzit (Post 4729673)
Is LogVol01 mounted by any chance?

Sorry if this might seem dense, is the code you inserted to be followed? It seems that you're creating a 'test' logical volume and mounting it to /mnt then removing it. I'm not sure I understand the purpose (just trying to learn).

When I run df -h, I don't have LogVol01, I only have LogVol00, along with some other partitions. LogVol00 is still at 9.5G in size and is at 100% use.

Also, /dev/loop0 is at 100% of 130M in use. I'm not sure if that matters?

Thank you again for all of the help.

Kustom42 07-16-2012 02:00 PM

Did you run the dmsetup commands I provided? What was the output of those? I think that is the issue here preventing the LV from being removed.

whizzit 07-16-2012 02:23 PM

Quote:

Originally Posted by jbennett (Post 4729762)
Sorry if this might seem dense, is the code you inserted to be followed? It seems that you're creating a 'test' logical volume and mounting it to /mnt then removing it. I'm not sure I understand the purpose (just trying to learn).

I apologise for the confusion - the commands were not meant to be run (but is good that you questioned it rather than blindly running commands). It was merely to demonstrate that trying to lvremove a volume whilst it was mounted produced the same error you were/are having.

I'll take a step back and allow the thread to continue with Kustom42.

Regards

jbennett 07-16-2012 02:23 PM

Quote:

Originally Posted by Kustom42 (Post 4729661)
If you don't see any open file locks run the following:

Code:


dmsetup info -c VolGroup00-LogVol01


Code:

Name                Maj Min Stat Open Targ Event UUID
VolGroup00-LogVol01 253 1  L--w 1    2    0    LVM-.....

Quote:

If it shows a number "1" for the open status run the following:

Code:


dmsetup remove VolGroup00-LogVol01


Code:

device-mapper: remove ioctl failed: Device or resource busy
Command failed

Now, I suppose I need to know how to check for locked files. I found a few references to 'lsof' and 'lslk', however, being that I'm running on a LiveCD, I cannot install these. :(

Kustom42 07-16-2012 03:35 PM

Well, this is interesting...

That should allow you to remove it, add the -f option to the remove command.

dmsetup remove -f VolGroup00-LogVol01

jbennett 07-16-2012 03:53 PM

result as follows:

Code:

device-mapper: remove ioctl failed: Device or resource busy
Command Failed


Kustom42 07-16-2012 03:59 PM

Ok, well since you don't have access to lsof try this:

Code:

ps auxww | grep -i LogVol01
Let us know what the output of that is, something is locking this device and in all honesty it shouldnt unless you mounted it or started a process within that directory. This may be something related to the multipath daemon or udev but I'm not sure at this point. The ps command should show us whats happening.

jbennett 07-16-2012 04:03 PM

Code:

root 1618 0.0 0.1 4328 784 tty1 S+ 21:02 0:00 grep -i LogVol01
I'm guessing this means that there is something locking it as root, but I'm not sure how to figure out what? is it pid 1618?

if I do the following:

Code:

ps ax | grep 1618
I get the following:

Code:

1624 tty1 S+ 0:00 grep 1618
Which I'm assuming is saying essentially the same as the previous output, that tty1 is using it?

When I do 'df -H', I don't see LogVol01 listed, only LogVol00??

Kustom42 07-16-2012 06:51 PM

The ps output you are getting is for the grep process you are running. This is very odd, there are no processes with a file open so you should have no issue removing the logical volume.

I have seen this is in wierd situation before where the device was suspended, not sure if thats the case but its something to try.

Code:


dmsetup resume VolGroup00-LogVol01
dmsetup remove VolGroup00-LogVol01


jbennett 07-17-2012 07:57 AM

result as follows:

Code:

device-mapper: remove ioctl failed: Device or resource busy
Command Failed

If I understood more about what was happening I would attempt to research, but I'm not even sure what's causing this at this point. :(

whizzit 07-17-2012 08:31 AM

Actually, I just had a thought that LogVol01 could be the swap volume for your CentOS system. It's possible that the LiveCD you are using has automatically started using it as swap and could explain why it wasn't able to be removed. This might be shown by:

Code:

blkid -t TYPE=swap        # show volumes/partitions of type swap
cat /proc/swaps            # show swap volumes/partitions in use

For now, I'd say forget about LogVol01 and simply carry on with extending the main volume LogVol00 as Kustom42 previously described. Unless you have already extended LogVol01 (lvs will show LVM volume sizes).

jbennett 07-17-2012 09:28 AM

Quote:

Originally Posted by whizzit (Post 4730562)
Code:

blkid -t TYPE=swap        # show volumes/partitions of type swap

Code:

/dev/mapper/VolGroup00-LogVol01: UUID="............" TYPE="swap"
Quote:

Code:

cat /proc/swaps            # show swap volumes/partitions in use

Code:

Filename  Type      Size    Used Priority
/dev/dm-1 partition 262136  0    -1

Quote:

For now, I'd say forget about LogVol01 and simply carry on with extending the main volume LogVol00 as Kustom42 previously described. Unless you have already extended LogVol01 (lvs will show LVM volume sizes).
If I do a 'lvdisplay', I see where LogVol01 has a LV size of 100.24 GB while LogVol00 has a LV size of 9.65 GB. Is this showing that the LogVol01 has already been extended?


If all looks ok, at this point, I need to stay in recovery and do the following:

Code:

lvextend -L +100G /dev/VolGroup00/LogVol00
resize2fs /dev/VolGroup00/LogVol00

?

whizzit 07-17-2012 09:59 AM

Quote:

Originally Posted by jbennett (Post 4730609)
If I do a 'lvdisplay', I see where LogVol01 has a LV size of 100.24 GB while LogVol00 has a LV size of 9.65 GB. Is this showing that the LogVol01 has already been extended?

So this will need to be undone first with lvreduce to reclaim the space. To be thorough I propose the following commands, checking progress as you go ( at a pinch just the lvreduce would suffice for now ):

Code:

/sbin/swapoff    /dev/VolGroup00/LogVol01      # stop using this volume as swap.
lvreduce -L 256M /dev/VolGroup00/LogVol01      # reduce LogVol01 to 256M
/sbin/mkswap    /dev/VolGroup00/LogVol01      # initialise the swap space, to be on the safe side
/sbin/swapon    /dev/VolGroup00/LogVol01      # start using LogVol01 as swap again (not strictly necessary in this environment but good practice)

( Note: that it is not '-L -100G' because the original lvextend must have been executed as '-L 100G'. Subtle, but important if using other commands like lvresize, for example )

You can check progress with vgs (or vgdisplay) to ensure that the volume group has enough free storage.

Quote:

Originally Posted by jbennett (Post 4730609)
If all looks ok, at this point, I need to stay in recovery and do the following:

Code:

lvextend -L +100G /dev/VolGroup00/LogVol00
resize2fs /dev/VolGroup00/LogVol00

?

That looks correct.

jbennett 07-17-2012 10:12 AM

Code:

/sbin/swapoff    /dev/VolGroup00/LogVol01      # stop using this volume as swap.
bash: /sbin/swapoff: No such file or directory
lvreduce -L 256M /dev/VolGroup00/LogVol01      # reduce LogVol01 to 256M
WARNING: Reducing active and open logical volume to 256.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)

I'm assuming I want to hit yes, but the fact that it couldn't find swapoff makes me want to verify before I go through with this.

whizzit 07-17-2012 10:20 AM

Can you try just swapoff on it's own (in case the path is different in your evironment) ?

The warning is great (!) since the command is a sure way to kill a system if typos are ever made in the volume name :). In this case we will be ok since we know there isn't anything important on LogVol01 ( /proc/swaps show Used = 0 ) but I would prefer swapoff to work first.

jbennett 07-17-2012 10:24 AM

that seems to have worked (no errors).

I have successfully extended the LV to 109.65 GB and am now able to see that /VolGroup00-LogVol00 has a size of 108G with only 9.6G used!

Now I get to see if I can restore a Nagios install to this VM.

THANK YOU!!! This forum has been invaluable!!

Kustom42 07-17-2012 11:36 AM

Glad to see you go there, thanks for your eyes whizzit I was hitting the wall on this one. didn't think about it being set up as swap by the rescue CD, I'll have to keep that in mind.

jbennett 07-17-2012 11:43 AM

Thanks for all of your help as well Kustom!


All times are GMT -5. The time now is 07:14 AM.