
본문에서는 25G 기본이미지를 20G로 줄이는 작업
작업시에는 VM을 끄고 작업
:: 현재 디스크 크기 확인
# qemu-img info disk
image: disk
file format: qcow2
virtual size: 25G (26843545600 bytes)
disk size: 394M
cluster_size: 65536
backing file: /var/lib/nova/instances/_base/9e2657ababfb190119ce1132e48f4e4ba17db05d
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
:: 패키지 설치
# apt install libguestfs-tools
※ If you're running this on a dedicated Glance server without libvirt, change the setting to bypass libvirt back-end:
$ export LIBGUESTFS_BACKEND=direct
:: 이미지내 파티션 사이즈 확인
# virt-filesystems --long --parts --blkdevs -h -a disk
Name Type MBR Size Parent
/dev/sda1 partition 83 25G /dev/sda
/dev/sda device - 25G -
여기서는 주파티션(/dev/sda1)이 1.2G 사용중
# virt-df disk
Filesystem 1K-blocks Used Available Use%
disk:/dev/sda1 19248060 1245636 17986040 7%
:: gueshfish를 이용해서 메타데이타 값 변경
# guestfish -a disk.img
><fs> run
><fs> list-filesystems
...
><fs> e2fsck-f /dev/sda1
><fs> resize2fs-size /dev/sda1 19G
><fs> exit
※ 실제로 줄이려는 디스크 크기보다는 적게해서 체크
:: 줄이려는 디스크 이미지 생성
# qemu-img create -f qcow2 -o preallocation=metadata newdisk.qcow2 20G
:: 파티션 정보(데이타) 복사
# virt-resize --shrink / dev / sda1 ./disk ./newdisk.qcow2
:: 확인
# qemu-img info newdisk.qcow2
image: disk
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.5G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false
# virt-filesystems --long --parts --blkdevs -h -a disk
Name Type MBR Size Parent
/dev/sda1 partition 83 20G /dev/sda
/dev/sda device - 20G -
# virt-df disk
Filesystem 1K-blocks Used Available Use%
disk:/dev/sda1 20263528 1245896 19001248 7%
참고 URL