Resizing a disk in existing VM without loosing data is daunting task. I spent hours finding the correct way to resize the disk without loosing data. This might save some on lot of time.
A. Allotting additional disk to the VM:
a) Shut down the VM
b) Increase the physical disk size using the Xen Center. I recommend using Xen Center
Once the physical disk is increased it does not appear in VM once booted.
B. Boot into Rescue mode by inserting a Linux OS Dvd or the ISO image from your Xen ISO Library which i recommed.
a) Boot into Resuce mode by Selecting VM -> Start / Shutdown -> Start in Recovery Mode
b) Enter linux resuce in command prompt at boot time
c). Resize the physical disk. Please note this is most important follow exactly or you will loose data
fdisk /dev/sda then press p
Disk /dev/hda: 40.0 GB, 40020664320 bytes 255 heads, 63 sectors/track, 4865 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1188 9438187+ 8e Linux LVM
2. Press d then 2 to remove the partition
3. Press n then primary p then 2 start cylinder 14 last cylinder 4865 to add the newly re-sized partition. WARNING: Make sure the old and new partition start at the same cylinder position, not doing so will destroy your data.
4. Press t partition 2 Hex code 8e
5. Press p
Disk /dev/sda: 40.0 GB, 40020664320 bytes 255 heads, 63 sectors/track, 4865 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 4865 38973690 8e Linux LVM
6. Finally press w write table to disk.
d) Take a break you crossed the mine field now its easy.
We will use the lvm commands to resize the disk. Please note vgscan, vgchange etc will not work as these are sym link to lvm to run these command use lvm vgscan, lvm pvscan, lvm vgchange -ay
e) Lets run these LVM command
1) Resize the LVM physical volume, e.g.: lvm pvresize /dev/hda2
2) Run lvm vgscan, lvm vgchange -ay
3) Resize the LVM logical volume, e.g.: lvm lvresize /dev/VolGroup00/LogVol00 -l+100%FREE
4) Run e2fsck -f /dev/VolGroup00/LogVol00
5) Resize the filesystem, e.g.: resize2fs /dev/VolGroup00/LogVol00
6) Reboot. And pat your back, you are done.
Do not mount the Filesystem in rescue mode
This command in step 3 in last section: lvm lvresize /dev/VolGroup00/LogVol00 -l+100%FREE is run together. It should be lvm lvresize /dev/VolGroup00/LogVol00 -l +100%FREE that is a dash lowercase L for anyone looking at this. Yes, that +100%FREE is part of the command, not some funky characters either as my coworker thought…lol. Otherwise, nice guide to a pain in the ass process. Your logical volume group names may be different than this article, so adjust accordingly as well.
Thanks
Your instructions saved me I think…
The only thing is, now in my CentOS 6.5 Disk Utility I see the new space extended, but in my shell when i issue the command “df -h” I see the old storage info:
[root@c1]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_cy1-lv_root 4.0G 3.5G 287M 93% /
tmpfs 2.7G 232K 2.7G 1% /dev/shm
/dev/sda1 485M 58M 402M 13% /boot
Disk Utility ScreenShot: http://www.mydigia.com/images/ImG/2014-02-11_2021.png
What is wrong?
And here is more details:
[root@c1]# fdisk -l
Disk /dev/sda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 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: 0x000322e1
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1566 12065871 83 Linux
Disk /dev/mapper/vg_cy1-lv_root: 11.8 GB, 11815354368 bytes
48 heads, 36 sectors/track, 13354 cylinders
Units = cylinders of 1728 * 512 = 884736 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x406731ef
Device Boot Start End Blocks Id System
/dev/mapper/vg_cy1-lv_rootp1 2 4864 4201472 5 Extended
Disk /dev/mapper/vg_cy1-lv_swap: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 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
I think the steps regarding the resizing of partition has not been run properly. You need to boot into rescue mode from CD Image then do the steps for resizing the file system.
Once logged in check the lvm size and ensure it is showing the update volume. You need to build the lvm as it will not be mounted. I got stuck at same situation a double check and running the last commands helped. And off course Do not mount the Filesystem in rescue mode. You get this option while booting in rescue mode. Avoid that. And Run things from step 3 again