First of all shutdown the xen image you want to increase the filesystem off.
Then create a empty 10gb tempfile by executing the following command as root user on the XEN host ;
dd if=/dev/zero of=tempfile bs=1024 count=10000000
Now say your root filesystem image is called disk0 and is 4.5 Gb in size. You now need to expand your disk0 image with the newly create tempfile. Todo so , you can “cat” the empty file behind the disk0 by using this command;
cat tempfile >> disk0
After this action the “disk size” is increased up to 4.5 gb + 10gb = 14.5 Gb but not yet the partition which is created on this disk itself. For that to be increase aswell we need to follow these steps ; Also note that i am not using a disk with more than 1 ” real” partition and that the end partition is the one we need to expand ! Other senario’s need to be followed when dealing with more complex disk setups. In a nutshell, we are deleting the existing partition from the partition table and recreating a new one starting from the same blockpointer as where the old one started. By doing this the data on the partition we are deleting is not lost but again available in the newly created partition !
You can now start the image again, once started login as root and start fdisk.
xxx:/home/oracle # fdisk /dev/xvda
The number of cylinders for this disk is set to 1767.
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 /dev/xvda: 14.5 GB, 14534967296 bytes
255 heads, 63 sectors/track, 1767 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvda1 1 66 530113+ 82 Linux swap / Solaris
/dev/xvda2 67 522 3662820 83 Linux
Command (m for help): d
Partition number (1-4): 2
Command (m for help): p
Disk /dev/xvda: 14.5 GB, 14534967296 bytes
255 heads, 63 sectors/track, 1767 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvda1 1 66 530113+ 82 Linux swap / Solaris
Command (m for help): n
Command action
e extended
p primary partition (1-4) p
Partition number (1-4): 2
First cylinder (67-1767, default 67): 67
Last cylinder or +size or +sizeM or +sizeK (67-1767, default 1767): 1767
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.
Syncing disks.
Before we shutdown the XEN Guest again, we must determine the filesystem type with the command “mount”
xx:~ # mount
/dev/xvda2 on / type ext3 (rw,acl,user_xattr)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
debugfs on /sys/kernel/debug type debugfs (rw)
udev on /dev type tmpfs (rw)
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
securityfs on /sys/kernel/security type securityfs (rw)
/dev/mapper/oracle-u01 on /u01 type ext3 (rw)
xxx:~ #
Now that we know the filesystem type is ext3 we can continue the following steps after we shutdown the XEN guest.
In order to expand the size in the partition we need to execute one more command.
Depending on what filesystem we are dealing with, you can use either resize_reiserfs or resize2fs ( ext3)
First we need to add this disk to another XEN guest so that you have a non mounted filesystem disk available. You cannot execute these commands from within the XEN guest you are trying to expand ! Therefor you need to add the disk to another XEN guest in order to have full access to the disk.
When added to another XEN Guest , you don’t need to restart this guest ! Just type
“fdisk -l” and locate the disk you just added. Mostly this is the last disk displayed. Check this by comparing the disk size.
example :
x:/u01 # fdisk -l
…
..
Disk /dev/xvdd: 14.5 GB, 14534967296 bytes
255 heads, 63 sectors/track, 3855 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvdd1 1 66 530113+ 82 Linux swap / Solaris
/dev/xvdd2 67 1767 13663282+ 83 Linux
Now we have 2 chooses, for reiserfs execute the following ( this might also be done ONLINE ! ) :
x:~ # resize_reiserfs /dev/xvdd2
resize_reiserfs 3.6.19 (2003 www.namesys.com)
resize_reiserfs: On-line resizing finished successfully.
For Ext3 execute chkdisk when needed and then resize2fs;
x:~ # e2fsck -f /dev/xvdd2
e2fsck 1.38 (30-Jun-2005)
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
/dev/xvdd2: 133866/525888 files (0.7% non-contiguous), 782580/1050249 blocks
x:~ # resize2fs /dev/xvdd2
resize2fs 1.38 (30-Jun-2005)
Resizing the filesystem on /dev/xvdd2 to 3415820 (4k) blocks.
The filesystem on /dev/xvdd2 is now 3415820 blocks long.
After a reboot your root filesystem is increased !