This post assumes you are running the Xen hypervisor and are using a partitions based filesystems for you Xen guest you would like to re-size. I have previously written on Installing Xen on CentOS 6 from source and another blog entry that describes how to create partition based Xen guests on Creating Debian guests on Xen using partition based filesystem if you would like to see how to get started running Xen.
To resize, first shutdown the guest instance:
$ sudo xm shutdown Wheezy
$ sudo lvresize /dev/VolGroup00/Wheezy -L +10GB
Extending logical volume Wheezy to 20.00 GiB
Logical volume Wheezy successfully resized
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup00/Wheezy
LV Name Wheezy
VG Name VolGroup00
LV UUID jQqEFZ-sd39-siY6-kqCZ-l8Lq-UWWk-3f4oh5
LV Write Access read/write
LV Creation host, time host.localdomain, 2013-05-14 12:32:00 -0400
LV Status available
# open 0
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
I would first backup the partition that is going to be modified. This is going to sound weird; but this process uses fdisk to delete and recreate the partition.
List you partition:
$ sudo fdisk -l /dev/VolGroup00/Wheezy
Disk /dev/VolGroup00/Wheezy: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00081c29
Device Boot Start End Blocks Id System
/dev/VolGroup00/Wheezy1 1 63 498688 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/VolGroup00/Wheezy2 63 1306 9985024 83 Linux
When trying to directly re-size, an error occurs.
$ sudo resize2fs /dev/VolGroup00/Wheezy
resize2fs 1.41.12 (17-May-2010)
resize2fs: Bad magic number in super-block while trying to open /dev/VolGroup00/Wheezy
Couldn't find valid filesystem superblock.
We are now going to delete the partition, as warned before, make sure you have backups.
$ sudo fdisk /dev/VolGroup00/Wheezy
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): p
Disk /dev/VolGroup00/Wheezy: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00081c29
Device Boot Start End Blocks Id System
/dev/VolGroup00/Wheezy1 1 63 498688 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/VolGroup00/Wheezy2 63 1306 9985024 83 Linux
Command (m for help): d
Partition number (1-4): 2
Command (m for help): p
Disk /dev/VolGroup00/Wheezy: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00081c29
Device Boot Start End Blocks Id System
/dev/VolGroup00/Wheezy1 1 63 498688 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
Recreate the partition with the new size.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (63-2610, default 63):
Using default value 63
Last cylinder, +cylinders or +size{K,M,G} (63-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/VolGroup00/Wheezy: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00081c29
Device Boot Start End Blocks Id System
/dev/VolGroup00/Wheezy1 1 63 498688 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/VolGroup00/Wheezy2 63 2610 20465113 83 Linux
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
The follow command splits the partitions apart as using the simple Debian partitioning scheme may combine them.
$ sudo kpartx -a /dev/VolGroup00/Wheezy
$ cd /dev/mapper/
$ ls
control VolGroup00-Wheezy VolGroup00-Wheezy1 VolGroup00-Wheezy2
Next, check the filesystem for errors.
$ sudo e2fsck -f VolGroup00-Wheezy2
e2fsck 1.41.12 (17-May-2010)
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
VolGroup00-Wheezy2: 29159/624624 files (0.2% non-contiguous), 224352/2496256 blocks
We can now re-size the filesystem.
$ sudo resize2fs VolGroup00-Wheezy2
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on VolGroup00-Wheezy2 to 5116278 (4k) blocks.
The filesystem on VolGroup00-Wheezy2 is now 5116278 blocks long.
Reattach the filesystems that were previously split.
$ sudo kpartx -d /dev/VolGroup00/Wheezy
$ ls
control VolGroup00-Wheezy
A quick look at the logical volume and we can see we grew from 10 to 20 Gigabytes.
$ sudo lvscan
ACTIVE '/dev/VolGroup00/Wheezy' [20.00 GiB] inherit
You should now be able to boot the guest using the larger file system.
To delete the guest filesystem:
sudo vgremove lvmxen
sudo pvremove /dev/sdb1
sudo parted /dev/sdb
(parted) rm 1
(parted) quit
Comments
comments powered by Disqus