Resize Disk Partition
디스크 파티션 크기 늘리기.
[개요]
VM의 OS파티션이 10G인 VM이 있다. 이 VM의 qcow2이미지는 30G이다.
os파티션의 크기를 30G로 늘리고 싶다면 어떻게 해야할까.
먼저 해당 VM을 종료한다.
root@thomas:/home/orchard# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 4071 2 r----- 573560.3
nextmkt-apm 23 1024 1 -b---- 42417.3
ppms 26 5109 8 -b---- 704284.1
tinydns 28 1019 2 -b---- 35981.9
wingwings 30 1020 1 -b---- 40479.9
odom 527 2048 2 -b---- 230738.5
asp 528 2044 2 -b---- 296544.6
youjin1 529 4092 8 r----- 841041.0
swrc 535 7168 8 r----- 2537291.7
pm 538 2048 2 -b---- 84.5
root@thomas:/home/orchard# xl shutdown 538
디스크에 접근
root@thomas:/data/domu# qemu-nbd -c /dev/nbd0 pm.qcow2
Failed to open /dev/nbd0: No such file or directory
/build/qemu-1000/qemu-2.5+dfsg/nbd.c:nbd_receive_request():L857: read failed
실패. 모듈 업로드 후 다시 접근
root@thomas:/data/domu# modprobe nbd
root@thomas:/data/domu# lsmod |grep nbd
nbd 16851 0
root@thomas:/data/domu# qemu-nbd -c /dev/nbd0 pm.qcow2
성공
Disk /dev/nbd0: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5d03c8ba
Device Boot Start End Sectors Size Id Type
/dev/nbd0p1 2048 1953791 1951744 953M 82 Linux swap / Solaris
/dev/nbd0p2 * 1953792 21485567 19531776 9.3G 83 Linux
파티트 명령어로 파티션 리사이즈
root@thomas:/data/domu# parted /dev/nbd0
GNU Parted 3.2
Using /dev/nbd0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: Unknown (unknown)
Disk /dev/nbd0: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1000MB 999MB primary linux-swap(v1)
2 1000MB 11.0GB 10.0GB primary ext4 boot
(parted) resize 2
Error: The resize command has been removed in parted 3.0
????
(parted) resizepart 2
End? [11.0GB]? 32.2GB
(parted) p
Model: Unknown (unknown)
Disk /dev/nbd0: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1000MB 999MB primary linux-swap(v1)
2 1000MB 32.2GB 31.2GB primary ext4 boot
resize명령어가 3.0 버전 부터는 없어졌음에 주의.
파티션 테이블 매핑.
root@thomas:/dev# kpartx -dv /dev/nbd0
리사이즈 명령어로 늘린 부분에 파일시스템 적용.
root@thomas:/data/domu# resize2fs /dev/mapper/nbd0p2
resize2fs 1.42.12 (29-Aug-2014)
resize2fs: Filesystem has unsupported read-only feature(s) while trying to open /dev/mapper/nbd0p2
Couldn't find valid filesystem superblock.
알수없는 오류 발생.
삽질 1시간 반정도 소요 후 발견.
마운트를 시켜주고 해당 명령어를 실행시켜줘야한다……..
root@thomas:/dev# mount /dev/mapper/nbd0p2 /mnt
root@thomas:/dev# resize2fs /dev/mapper/nbd0p2
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/mapper/nbd0p2 is mounted on /mnt; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/mapper/nbd0p2 is now 7617104 (4k) blocks long.
용량 확인.
root@thomas:/dev# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md0 146G 3.9G 135G 3% /
udev 10M 0 10M 0% /dev
tmpfs 790M 82M 708M 11% /run
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/md127 3.7T 1.3T 2.4T 35% /data
/dev/mapper/nbd0p2 29G 1023M 27G 4% /mnt
디스크 해제.
root@thomas:/dev# umount /mnt
root@thomas:/dev# kpartx -dv /dev/ndb0
failed to stat() /dev/ndb0
root@thomas:/dev# kpartx -dv /dev/nbd0
del devmap : nbd0p2
del devmap : nbd0p1
root@thomas:/dev# qemu-nbd -d /dev/nbd0
/dev/nbd0 disconnected
해당 vm실행.
root@thomas:/data/config.bak/config.new# xl create pm.cfg
Parsing config from pm.cfg
접속 후 디스크 용량 확인.
dev/mapper/nbd0p2 29G 1023M 27G 4% /mnt
root@pm:/home/orchard# fdisk -l
Disk /dev/xvda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5d03c8ba
Device Boot Start End Sectors Size Id Type
/dev/xvda1 2048 1953791 1951744 953M 82 Linux swap / Solaris
/dev/xvda2 * 1953792 62890625 60936834 29.1G 83 Linux
정상적으로 29기가 확장 확인.
완료.