Monday, November 3, 2014

How to re-size a qcow2 image?

#stop VM and from the hypervisor resize its disk
[root@compute-0-0 ~]# qemu-img resize /zone01/image.qcow2 +35G
Image resized.
-----------------------------------------------------------------------------------------------
#start the VM and login to it
#run fdisk -l
[root@dev ~]# fdisk -l

Disk /dev/vda: 69.8 GB, 69793218560 bytes
16 heads, 63 sectors/track, 135233 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00043b46

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_dev-lv_root: 25.4 GB, 25375539200 bytes
255 heads, 63 sectors/track, 3085 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

Disk /dev/mapper/vg_dev-lv_root doesn't contain a valid partition table

Disk /dev/mapper/vg_dev-lv_swap: 6308 MB, 6308233216 bytes
255 heads, 63 sectors/track, 766 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

Disk /dev/mapper/vg_dev-lv_swap doesn't contain a valid partition table
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#run fdisk on the extended dev
[root@dev ~]# fdisk /dev/vda

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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-135233, default 1): 62417
Last cylinder, +cylinders or +size{K,M,G} (62417-135233, default 135233):
Using default value 135233
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/vda: 69.8 GB, 69793218560 bytes
16 heads, 63 sectors/track, 135233 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00043b46

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       62416    30944256   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3           62417      135233    36699768   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.
-----------------------------------------------------------------------------------------------
#reboot the vm
#when the VM goes up:
[root@dev ~]# pvscan
  PV /dev/vda2   VG vg_dev   lvm2 [29.51 GiB / 0    free]
  Total: 1 [29.51 GiB] / in use: 1 [29.51 GiB] / in no VG: 0 [0   ]
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#create Physical volume
[root@dev ~]# pvcreate /dev/vda3
  Writing physical volume data to disk "/dev/vda3"
  Physical volume "/dev/vda3" successfully created
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#extend Volume group
[root@dev ~]# vgextend vg_dev /dev/vda3
  Volume group "vg_dev" successfully extended
[root@dev ~]# pvscan
  PV /dev/vda2   VG vg_dev   lvm2 [29.51 GiB / 0    free]
  PV /dev/vda3   VG vg_dev   lvm2 [35.00 GiB / 35.00 GiB free]
  Total: 2 [64.50 GiB] / in use: 2 [64.50 GiB] / in no VG: 0 [0   ]
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#Extending logical volume
[root@dev ~]# lvextend -L+34G /dev/vg_dev/lv_root
  Extending logical volume lv_root to 57.63 GiB
  Logical volume lv_root successfully resized
[root@dev ~]#
-----------------------------------------------------------------------------------------------
#resizing the file system
[root@dev ~]# resize2fs /dev/vg_dev/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_dev/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/vg_dev/lv_root to 15108096 (4k) blocks.
The filesystem on /dev/vg_dev/lv_root is now 15108096 blocks long.
[root@dev ~]#
[root@dev ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dev-lv_root
                       57G  3.5G   51G   7% /
tmpfs                 1.9G   88K  1.9G   1% /dev/shm
/dev/vda1             485M   36M  424M   8% /boot
[root@dev ~]#


more commands:
#Extend to all free size
lvextend -l+100%FREE /dev/VolGroup/lv_home

#show vol groups
vgdisplay

No comments:

Post a Comment