- e.g.) Default 8GB(orig.img) -> 20GB(test.img) any..
- Both Single-Image and BackingType-Image
- Test format: qcow2
- Tools: parted, qemu-img, qemu-nbd
- Test Platform: Ubuntu 13.04 x86_64
[Start]
- Check Image
# qemu-img info orig.img
image: orig.img
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 883M
cluster_size: 65536
# qemu-img create -b /home/orig.img -f qcow2 test.img
# qemu-img info test.img
image: test.img
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 196K
cluster_size: 65536
backing file: /home/orig.img
- Connect NBD & Check partitions
# modprobe nbd
# qemu-nbd -c /dev/nbd0 /home/test.img
# ls -al /dev/nbd0*
brw-rw---- 1 root disk 43, 0 Sep 28 23:18 /dev/nbd0
brw-rw---- 1 root disk 43, 1 Sep 28 23:18 /dev/nbd0p1
# parted /dev/nbd0 --script print free
Model: Unknown (unknown)
Disk /dev/nbd0: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 8589MB 8588MB primary ext4 boot
8589MB 8590MB 1049kB Free Space
- Disconnect NBD & Resize image
# qemu-nbd -d /dev/nbd0
/dev/nbd0 disconnected
# qemu-img resize test.img 20G
Image resized.
- Check image
# qemu-img info test.img
image: test.img
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 200K
cluster_size: 65536
backing file: /home/orig.img
- Connect NBD & Check partitions
# qemu-nbd -c /dev/nbd0 /home/test.img
# parted /dev/nbd0 --script print free
Model: Unknown (unknown)
Disk /dev/nbd0: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 8589MB 8588MB primary ext4 boot
8589MB 21.5GB 12.9GB Free Space
- Re-Partitioning (Remove Partition and Create Partition) ("1" is partition-number)
# parted /dev/nbd0 --script rm 1
# parted /dev/nbd0 --script print free
Model: Unknown (unknown)
Disk /dev/nbd0: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 21.5GB 21.5GB Free Space
# parted -a optimal /dev/nbd0 --script mkpart primary ext4 0% 100%
# parted /dev/nbd0 --script print free
Model: Unknown (unknown)
Disk /dev/nbd0: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
32.3kB 1049kB 1016kB Free Space
1 1049kB 21.5GB 21.5GB primary ext4
- Mount image's Partition (to edit boot-script :: rc.local)
# kpartx -a /dev/nbd0
# mount /dev/mapper/nbd0p1 /mnt/
- Apply Parition to VM (by resize2fs)
# echo 'resize2fs /dev/vda1; sed -i \"/resize2fs/d\" /etc/rc.local' >> /mnt/etc/rc.local
[End]
Booting VM with new image
[Appendix]
- Disconnect kpartx & NBD
# umount /mnt
# kpartx -d /dev/nbd0
# qemu-nbd -d /dev/nbd0
'Cloud > KVM' 카테고리의 다른 글
KVM/QEMU Guide #1 (Intro & Basic) (0) | 2012.06.22 |
---|---|
KVM/QEMU - How to Migration(include LIve) (0) | 2012.05.13 |
[KVM] CentOS 5.x에서 qcow2 이미지파일 직접 마운트/접근 (with LVM) (1) | 2011.04.01 |
[IaaS] - CloudStack CE 2.1.7 설치 (1) | 2011.02.22 |