XenServer Resize CentOS LVM


XenServer Resize CentOS LVM

оригинальная ссылка

The disk size of a CentOS virtual machine on XenServer can be increased with the following steps. The current VM contains one disk of 8 GB which is divided into a boot partition and an LVM partition:

   # fdisk -l
       Device Boot      Start         End      Blocks   Id  System
   /dev/xvda1   *           1          64      512000   83  Linux
   /dev/xvda2              64        1045     7875584   8e  Linux LVM
   # pvscan  
   PV /dev/xvda2   VG VolGroup   lvm2 [7.51 GiB / 0    free]
   Total: 1 [7.51 GiB] / in use: 1 [7.51 GiB] / in no VG: 0 [0   ]
   # df -h
   Filesystem            Size  Used Avail Use% Mounted on
   /dev/mapper/VolGroup-lv_root
                         3.6G  714M  2.7G  21% /
   tmpfs                1000M     0 1000M   0% /dev/shm
   /dev/xvda1            485M   68M  392M  15% /boot

We will boot into single user mode in the VM. Within XenCenter open the host console and type the following:

   # xe vm-list | grep "Name of VM" -b1
   1622-uuid ( RO)           : 573530fb-fbb5-67f8-8d45-43671faa2574
   1682:     name-label ( RW): Name of VM
   1715-    power-state ( RO): running

Note the UUID of the VM and use that in the following command:

   xe vm-param-set uuid=573530fb-fbb5-67f8-8d45-43671faa2574 PV-args=single

Now shutdown the VM and resize the disk of the VM in XenCenter, e.g. to 12 GB. Start the VM and create a new partition of type Linux LVM:

   # fdisk /dev/xvda
   n
   p
   3
   Enter
   Enter
   t
   3
   8e
   w

Reboot the VM and increase the disk size in the VM:

   # pvcreate /dev/xvda3
   # vgextend VolGroup /dev/xvda3
   # lvextend -L+3.99G /dev/VolGroup/lv_root
   # resize2fs /dev/VolGroup/lv_root

Open the host console again and revert to the standard VM arguments:

   xe vm-param-set uuid=573530fb-fbb5-67f8-8d45-43671faa2574 PV-args=

Finally, reboot the VM and check the new size:

   # df -h
   Filesystem            Size  Used Avail Use% Mounted on
   /dev/mapper/VolGroup-lv_root
                         7.5G  715M  6.4G  10% /
   tmpfs                1000M     0 1000M   0% /dev/shm
   /dev/xvda1            485M   68M  392M  15% /boot