Subscribe via feed.

Extending a Logical Volume

Posted by Michael on March 15, 2010 – 4:26 pm

When you run out of space and are using LVM its fairly easy to extend your volume. In my case I am using Vsphere 4, FalconStor IPStor 6, and Centos 5. I will show you what to do to get the extra space you need for your Centos 5 machine with out any downtime. Many of the steps in here can be done with out needing Vmware or Falconstor.

The first thing we need to do is log into our FalconStor console and create another LUN. Once that is complete assign it to your ESX host(s). In our environment I use “Read/Write Non Exclusive” this will give a warning, but is required if using Vmotion with VShpere. Be sure if assigning to more than 1 host that you use the same LUN ID for each host. Once the disk has been assigned to VSphere you need to configure any replication or backup settings.

Next we need to move on to Vshpere. Log into your ESX host or VcenterServer using your vsphere client as an Admin user. Select the ESX host that you have assigned the LUN to. Next click the configuration tab. In the Hardware menu select Storage Adapters. Here select the adapter you assigned the LUN to. In my case its vmhba4 Fiberchannel with a nice long WWPN. I right click the adapter and choose “Rescan”. Next I need to look below in the devices view and find the matching LUN ID. If this process doesnt show your disk the first time give it a couple of mins and try again. I have had to disconnect from vshpere and reconnect to it to get the LUN to show up. This is more common of a problem when using an XP host to run your VcenterServer from. Once your LUN shows up you need to edit the settings of your Virtual Machine and add a new Hard disk to it. In my case I am using a raw mapped LUN as the device type. Once this is complete you can now move on to the Centos part. Everything from here on out will need to be done as the root user or as an admin user using sudo, unless otherwise noted.

By default Linux will not just “see” this newly attached disk. We need to rescan the scsi bus first. To do this I use a simple script I wrote. I call it rescan_bus.
#!/bin/bash
echo "Scanning host0"
echo "- - -" > /sys/class/scsi_host/host0/scan
sleep 1;
echo "Done"
exit 0;

Put this into a file called rescan_bus and place the file in /usr/local/sbin then execute the following command:
chmod 700 /usr/local/sbin/rescan_bus && chown root:root /usr/local/sbin/rescan_bus
This will make sure that no one except root can do anything with this file. Once you have completed this you can now execute this file.
=> rescan_bus
Scanning host0
Done

Next you should be able to see the new disk by using fdisk
=> fdisk -l
[... suppressed output...]

Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table

This was the output from my command. As we can see I now have sdc which has no valid partition type. I want to use the whole disk here for my Volume Group. But which volume group do I want to use, and how many are on my system anyway? Well to find out simply run: vgdisplay
=> vgdisplay
[...suppressed output...]
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 5.88 GB
PE Size 32.00 MB
Total PE 188
Alloc PE / Size 160 / 5.00 GB
Free PE / Size 28 / 896.00 MB
VG UUID cg5tC3-Xvr7-Vv6q-LuzB-qPV4-2fqb-2hRv3c

This happens to be the default name for the primary volume group on Centos. Now since I want to use this whole 10G disk for my primary Volume group we can do that now using pvcreate and vgextend.
=> pvcreate /dev/sdc [130]
Physical volume "/dev/sdc" successfully created
=> vgextend VolGroup00 /dev/sdc
/dev/cdrom: open failed: No medium found
Volume group "VolGroup00" successfully extended

Next we can see how the Volume Group was extended by running vgdisplay again

=> vgdisplay
[...suppressed output...]
--- 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 15.84 GB
PE Size 32.00 MB
Total PE 507
Alloc PE / Size 160 / 5.00 GB
Free PE / Size 347 / 10.84 GB
VG UUID cg5tC3-Xvr7-Vv6q-LuzB-qPV4-2fqb-2hRv3c

Now you should see that the Free PE / Size has grown.

Next we need to extend the actual volume that is out of space. Which Volumes are in our group? We can get a list by running lvdisplay

=> lvdisplay
--- Logical volume ---
[...suppressed output...]
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID cJnNf0-nBQ1-8s2W-SV1a-OIC3-mHD1-i0i4eT
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GB
Current LE 128
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0

--- Logical volume ---
[...suppressed output...]

As we can see from this we have a volume named LogVol00. This is the default volume for the Linux root. You can see this from running df

=> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3.9G 3.3G 411M 90% /

At this time the partition is so small we are unable to run yum update to update this server so we have to extend the volume. We also cant take this machine offline as it is the email server for our company. LVM allows from online resizes, so we will do that now. First lets extend the volume by 10G.

=> lvextend -L+10G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 14.00 GB
Logical volume LogVol00 successfully resized

Great, that was successful lets move on. This is the part that can be scary, here we will use an online resize of our disk using resize2fs
=> resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 3670016 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 3670016 blocks long.

Great so it looks like it worked! Lets see:
=> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
14G 3.3G 9.6G 26% /

So it worked, now we can yum update at last!

Tags: , , , ,
This post is under “Systems Administration” and has 2 respond so far.
If you enjoy this article, make sure you subscribe to my RSS Feed.

2 Responds so far- Add one»

  1. 1. Timothykaply Said:

    microsoft office for teachers discount windows xp 32 bit iso google drive Adobe Illustrator CS6 adobe cs6 master collection student and teacher edition pc buy cheap adobe cs6 master collection

  2. 2. xxx porno Said:

    sunny leone xxx videos pornos sxxx xxx xxx

Post a reply