게시물 1,376건
   
image resize
글쓴이 : 최고관리자 날짜 : 2017-01-18 (수) 09:58 조회 : 4148
글주소 :
                                
출처 : http://call518.tistory.com/125

[Info]
  • 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



이름 패스워드
비밀글 (체크하면 글쓴이만 내용을 확인할 수 있습니다.)
왼쪽의 글자를 입력하세요.
   

 



 
사이트명 : 모지리네 | 대표 : 이경현 | 개인커뮤니티 : 랭키닷컴 운영체제(OS) | 경기도 성남시 분당구 | 전자우편 : mojily골뱅이chonnom.com Copyright ⓒ www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.