Debian > ディスク容量の拡張
更新日
2013-11-13
広告
KVM上の仮想マシン(debian) のディスクを増やしてみます。
1. backup kvm image.
2. check information of vm disk
$ sudo pvdisplay --- Physical volume --- PV Name /dev/sda5 VG Name vm-test PV Size 63.76 GiB / not usable 2.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 16322 Free PE 0 Allocated PE 16322 PV UUID x1nhEp-eb1M-yQpB-mg7P-HUVz-A5Zx-wqP3ry
$ sudo vgscan Reading all physical volumes. This may take a while... Found volume group "vm-test" using metadata type lvm2
$ sudo vgdisplay --- Volume group --- VG Name vm-test System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 63.76 GiB PE Size 4.00 MiB Total PE 16322 Alloc PE / Size 16322 / 63.76 GiB Free PE / Size 0 / 0 VG UUID oDIg4a-nsxe-zhWb-gPfu-qSXj-ynYh-wkfi5t
3. shutdown vm
4. check information of image file.
$ qemu-img info my-vm.img image: my-vm.img file format: qcow2 virtual size: 64G (68719476736 bytes) disk size: 40G cluster_size: 655365. resize image by qemu-img use version 1.5.0 because it can resize format qcow2.
qemu-1.5.0$ sudo ./qemu-img resize my-vm.img +384G
$ qemu-img info my-vm.img image: my-vm.img file format: qcow2 virtual size: 512G (549755813888 bytes) disk size: 40G cluster_size: 655366. boot vm
$ dmesg [ 0.997883] sd 0:0:0:0: [sda] 1073741824 512-byte logical blocks: (549 GB/512 GiB)512GBとして認識されてる。 7. partition
$ sudo fdisk /dev/sda Command (m for help): p Disk /dev/sda: 549.8 GB, 549755813888 bytes 255 heads, 63 sectors/track, 66837 cylinders, total 1073741824 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 Disk identifier: 0x00040dc7 Device Boot Start End Blocks Id System /dev/sda1 * 2048 499711 248832 83 Linux /dev/sda2 501758 134215679 66856961 5 Extended /dev/sda5 501760 134215679 66856960 8e Linux LVM1073741824セクタあるのに、134215679しか使ってない状態。 まず、extended partitionを拡張しないといけないようだ。
$ sudo cfdisk /dev/sdaで、Free Space 481GBってなってるところを選択し、[New]を選択 次に [Logical] を選択 Size (in MB): 481037.39 って出るのでクリック で、[Write]をクリック Name: sda6, part type: logical, FS type: Linux となった。 typeを8e (Linux LVM)にして、再度 write で quit
$ sudo fdisk -l /dev/sda Disk /dev/sda: 549.8 GB, 549755813888 bytes 255 heads, 63 sectors/track, 66837 cylinders, total 1073741824 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 Disk identifier: 0x00040dc7 Device Boot Start End Blocks Id System /dev/sda1 * 2048 499711 248832 83 Linux /dev/sda2 501758 1073741823 536620033 5 Extended /dev/sda5 501760 134215679 66856960 8e Linux LVM /dev/sda6 134215743 1073741823 469763040+ 8e Linux LVMパーティションsda6が追加されて、たくさんストレージを持っていることがわかる。
$ reboot/dev/sda6をphysical volumeとして設定する。
~$ sudo pvcreate /dev/sda6 Writing physical volume data to disk "/dev/sda6" Physical volume "/dev/sda6" successfully createdこれで、
~$ sudo pvdisplay --- Physical volume --- PV Name /dev/sda5 VG Name vm-test PV Size 63.76 GiB / not usable 2.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 16322 Free PE 0 Allocated PE 16322 PV UUID x1nhEp-eb1M-yQpB-mg7P-HUVz-A5Zx-wqP3ry "/dev/sda6" is a new physical volume of "448.00 GiB" --- NEW Physical volume --- PV Name /dev/sda6 VG Name PV Size 448.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID wf0d7A-iyZG-2u9c-AZXL-faHh-Um2X-JKae62こうなる。 で、volume group 'vm-test' に /dev/sda6 を追加して拡張する。
~$ sudo vgextend vm-test /dev/sda6 Volume group "vm-test" successfully extendedすると、/dev/sda6 の状態が更新される。
~$ sudo pvdisplay --- Physical volume --- PV Name /dev/sda5 VG Name vm-test PV Size 63.76 GiB / not usable 2.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 16322 Free PE 0 Allocated PE 16322 PV UUID x1nhEp-eb1M-yQpB-mg7P-HUVz-A5Zx-wqP3ry --- Physical volume --- PV Name /dev/sda6 VG Name vm-test PV Size 448.00 GiB / not usable 4.97 MiB Allocatable yes PE Size 4.00 MiB Total PE 114687 Free PE 114687 Allocated PE 0 PV UUID wf0d7A-iyZG-2u9c-AZXL-faHh-Um2X-JKae62volume groupの情報も更新され、VG Sizeが増加してる。
$ sudo vgdisplay --- Volume group --- VG Name vm-test System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 511.75 GiB PE Size 4.00 MiB Total PE 131009 Alloc PE / Size 16322 / 63.76 GiB Free PE / Size 114687 / 448.00 GiB VG UUID oDIg4a-nsxe-zhWb-gPfu-qSXj-ynYh-wkfi5t
$ sudo lvdisplay --- Logical volume --- LV Path /dev/vm-test/root LV Name root VG Name vm-test LV UUID hxrWdH-RINg-UfYm-rYoo-q6IY-EdRj-fXCIKl LV Write Access read/write LV Creation host, time , LV Status available # open 1 LV Size 61.13 GiB Current LE 15649 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0Logical Volumeのパスは /dev/vm-test/root 。 このLVに、/dev/sda6の容量を全部追加
$ sudo lvextend /dev/vm-test/root /dev/sda6 Extending logical volume root to 509.12 GiB Logical volume root successfully resizedファイルシステムの更新
$ sudo resize2fs -p /dev/vm-test/root resize2fs 1.42.5 (29-Jul-2012) Filesystem at /dev/vm-test/root is mounted on /; on-line resizing required old_desc_blocks = 4, new_desc_blocks = 32 Performing an on-line resize of /dev/vm-test/root to 133464064 (4k) blocks. The filesystem on /dev/vm-test/root is now 133464064 blocks long.これで、ファイルシステムから見ても、容量が増加したはず。
$ df -h Filesystem Size Used Avail Use% Mounted on rootfs 502G 39G 438G 9% / udev 10M 0 10M 0% /dev tmpfs 397M 244K 397M 1% /run /dev/mapper/vm--test-root 502G 39G 438G 9% / :
広告
お問い合わせは sweng.tips@gmail.com まで。