Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mcarbonneaux/976dd76051afe38ec046f56d112270a1 to your computer and use it in GitHub Desktop.
Save mcarbonneaux/976dd76051afe38ec046f56d112270a1 to your computer and use it in GitHub Desktop.
vg resize in xen guest

on domU resize the volume with lvm.

# lvs
  LV               VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vm-centos-hvm-lv sharevg -wi-ao---- 450.00g
# lvextend -L +100G /dev/sharevg/vm-centos-hvm-lv
# lvs
  LV               VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  vm-centos-hvm-lv sharevg -wi-ao---- 550.00g

from this point the guest vm have seen the new size in fdisk:

# fdisk -l /dev/xvda
Disk /dev/xvda: 590.6 GB, 590558003200 bytes
255 heads, 63 sectors/track, 71797 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: 0x0006804f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       58743   471340123+  8e  Linux LVM

but the pv xvda are not resized, and vg also:

#  vgs
  VG          #PV #LV #SN Attr   VSize   VFree
  vg_hotpoint   1  11   0 wz--n- 449.50g 44.00g

you must resize the partition of the pv first (remove the old partition, recreate it with new size with the same start and type):

# fdisk  /dev/xvda

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/xvda: 590.6 GB, 590558003200 bytes
255 heads, 63 sectors/track, 71797 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: 0x0006804f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       58743   471340123+  8e  Linux LVM

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 (64-71797, default 64):
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-71797, default 71797):
Using default value 71797

Command (m for help): p

Disk /dev/xvda: 590.6 GB, 590558003200 bytes
255 heads, 63 sectors/track, 71797 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: 0x0006804f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       71797   576196378+  83  Linux

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8E
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/xvda: 590.6 GB, 590558003200 bytes
255 heads, 63 sectors/track, 71797 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: 0x0006804f

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       71797   576196378+  8e  Linux LVM

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 or after you run partprobe(8) or kpartx(8)
Syncing disks.

after that if you have the warning that ioctl fail, you must reboot the vm to seen the new size.

after you must resize the pv:

# pvresize /dev/xvda2
  Physical volume "/dev/xvda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

and the vgs are automaticly resized !

# vgs
  VG          #PV #LV #SN Attr   VSize   VFree
  vg_hotpoint   1  11   0 wz--n- 549.50g 143.99g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment