How to resize LVM running Xen part 1 – increase disk size

Resizing a lvm partition is straight forward if it doesn’t contain a partition table. Simply do a:

lvresize -L disksize /dev/vg/lv
resize2fs /dev/vg/lv

If it is running a virtual machine like xen with a partition table, how to resize the domU, whether to shutdown domU or not depends largely on the partiton structure. In centos, if you do a default install, the default installation uses lvm without doing any proper partitioning, as in unlike traditional partitioning, there is no home, usr, tmp partions..etc. In a virtualised environment and with the default partitioning scheme, if you want to resize the home partition, you have to resize the root (/) partition. It is not easy to do it in domU so the best way is to do it is from domO.

Resizing domU from dom0 is more involved. So do yourself a favour by having a proper partition scheme like:

/boot
/
/usr
/var
/tmp
swap space which is 2 times your ram

Having partitioning scheme like this means that you don’t need to touch / when resizing ‘/home’ or ‘/usr’ which is quite common.

Ok, its time to do the dirty job. This article is to show how to resize domU from dom0 in case you need to do it. Shutdown my domU first.

[root@bpehhome2 mapper]# xm shutdown web

This is a quick overview of my web domU.

[root@bpehhome2 mapper]# fdisk -l /dev/xenvg/XenWeb

Disk /dev/xenvg/XenWeb: 10.5 GB, 10502537216 bytes
255 heads, 63 sectors/track, 1276 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

            Device Boot      Start         End      Blocks   Id  System
/dev/xenvg/XenWeb1   *           1          13      104391   83  Linux
/dev/xenvg/XenWeb2              47        1276     9879975   83  Linux
/dev/xenvg/XenWeb3              14          46      265072+  82  Linux swap / Solaris

If you try to resizefs /dev/xenvg/XenWeb straight away, resize2fs doesn’t like the MBR and will throw out error like so:

resize2fs: Bad magic number in super-block while trying to open /dev/xenvg/XenWeb
Couldn't find valid filesystem superblock.

To overcome that, we need to split the partition up and resizefs them separately. Let us go through the steps in detail.

1) In domO, check that you have enough disk space. In this example, I have about 3G more. I will add 1G to the xenweb logical volume

[root@bpehhome2 mapper]# vgdisplay
--- Volume group ---
VG Name               xenvg
System ID
Format                lvm2
Metadata Areas        1
Metadata Sequence No  90
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                7
Open LV               3
Max PV                0
Cur PV                1
Act PV                1
VG Size               37.16 GB
PE Size               32.00 MB
Total PE              1189
Alloc PE / Size       1066 / 33.31 GB
Free  PE / Size       123 / 3.84 GB
VG UUID               3vcgz5-1O2N-Oj89-o7KK-Tl51-wZbT-z32pgQ

2. I checked my current logical volume and resize xenweb to 1000M.

[root@bpehhome2 mapper]# lvscan
ACTIVE            '/dev/xenvg/root' [4.50 GB] inherit
ACTIVE            '/dev/xenvg/XenAuth' [8.00 GB] inherit
ACTIVE            '/dev/xenvg/XenDebianDefault' [2.00 GB] inherit
ACTIVE            '/dev/xenvg/swap' [1.00 GB] inherit
ACTIVE            '/dev/xenvg/XenCentOSInstall' [3.00 GB] inherit
ACTIVE            '/dev/xenvg/XenWeb1' [5.03 GB] inherit
ACTIVE            '/dev/xenvg/XenWeb' [9.78 GB] inherit

[root@bpehhome2 ~]# lvresize -L 10000M /dev/xenvg/XenWeb
  Rounding up size to full physical extent 9.78 GB
  Extending logical volume XenWeb to 9.78 GB
  Logical volume XenWeb successfully resized

3. Now I resize the partition in XenWeb2 in /dev/xenvg/XenWeb

[root@bpehhome2 mapper]# fdisk /dev/xenvg/XenWeb

The number of cylinders for this disk is set to 1276.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk xenvg-XenWeb: 10.5 GB, 10502537216 bytes
255 heads, 63 sectors/track, 1276 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

       Device Boot      Start         End      Blocks   Id  System
xenvg-XenWeb1   *           1          13      104391   83  Linux
xenvg-XenWeb2              47        1150     8867880   83  Linux
xenvg-XenWeb3              14          46      265072+  82  Linux swap / Solaris

Partition table entries are not in disk order

Command (m for help): d
Partition number (1-4): 2

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (47-1276, default 47):
Using default value 47
Last cylinder or +size or +sizeM or +sizeK (47-1276, default 1276):
Using default value 1276

Command (m for help): p

Disk xenvg-XenWeb: 10.5 GB, 10502537216 bytes
255 heads, 63 sectors/track, 1276 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

       Device Boot      Start         End      Blocks   Id  System
xenvg-XenWeb1   *           1          13      104391   83  Linux
xenvg-XenWeb2              47        1276     9879975   83  Linux
xenvg-XenWeb3              14          46      265072+  82  Linux swap / Solaris

Partition table entries are not in disk order

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 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

4. Now, its time to split the partition up. The partitions can be viewed in /dev/mapper. I want to resize2fs partition 2 only.

[root@bpehhome2 mapper]# kpartx -a /dev/xenvg/XenWeb
[root@bpehhome2 ~]# cd /dev/mapper
[root@bpehhome2 mapper]# ls
control     xenvg-XenAuth           xenvg-XenWeb    xenvg-XenWebp2  XenWeb2
xenvg-root  xenvg-XenCentOSInstall  xenvg-XenWeb1   xenvg-XenWebp3  XenWeb3
xenvg-swap  xenvg-XenDebianDefault  xenvg-XenWebp1  XenWeb1

[root@bpehhome2 mapper]# resize2fs XenWeb2
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f XenWeb2' first.

[root@bpehhome2 mapper]# e2fsck -f XenWeb2
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/: ***** FILE SYSTEM WAS MODIFIED *****
/: 246443/2143360 files (1.0% non-contiguous), 1037188/2216970 blocks

5. Do some cleaning up.

[root@bpehhome2 mapper]# kpartx -d /dev/xenvg/XenWeb

6. boot up domU and check if everything is working

[root@bpehhome2 mapper]# xm create /etc/xen/web.cfg

I will blog about shrinking lvm with partition next which is slightly more complex.

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.

3 thoughts on “How to resize LVM running Xen part 1 – increase disk size”

Comments are closed.