ディスク拡張
参照リンク
Summary
- KVM 基盤上で、VM のディスク拡張作業を行うときの手順
- 10 GB増設
- qcow2 にて実施
- 拡張領域を作成
事前準備
サーバのシャットダウン
イメージバックアップ
ディスク容量
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_clone-LogVol01 23G 13G 8.6G 60% / tmpfs 499M 0 499M 0% /dev/shm /dev/vda1 243M 70M 160M 31% /boot
物理ボリューム
# pvdisplay --- Physical volume --- PV Name /dev/vda2 VG Name vg_clone PV Size 29.75 GiB / not usable 0 Allocatable yes PE Size 4.00 MiB Total PE 7617 Free PE 1280 Allocated PE 6337 PV UUID zIFpTx-fpir-kr5o-tAy-w0o-oYlT-kKsT6A # pvscan PV /dev/vda2 VG vg_clone lvm2 [29.75 GiB / 5.00 GiB free] Total: 1 [29.75 GiB] / in use: 1 [29.75 GiB] / in no VG: 0 [0 ]
ボリュームグループ
# vgdisplay --- Volume group --- VG Name vg_clone System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 7 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 29.75 GiB PE Size 4.00 MiB Total PE 7617 Alloc PE / Size 6337 / 24.75 GiB Free PE / Size 1280 / 5.00 GiB VG UUID B5FxL3-emIw-MGMb-spNv-aL3j-biWH-RypuUp # vgscan Reading all physical volumes. This may take a while... Found volume group "vg_clone" using metadata type lvm2
論理ボリューム
# lvdisplay --- Logical volume --- LV Path /dev/vg_clone/LogVol01 LV Name LogVol01 VG Name vg_clone LV UUID rqHjKi-nP7v-9wmW-wcXx-cl6n-eAlD-Gb2hdK LV Write Access read/write LV Creation host, time clone, 2014-05-28 23:46:01 +0900 LV Status available # open 1 LV Size 22.75 GiB Current LE 5825 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_clone/LogVol00 LV Name LogVol00 VG Name vg_clone LV UUID e9xU1n-89pG-y5eT-gjma-rHjW-B9ik-pYrSAn LV Write Access read/write LV Creation host, time clone, 2014-05-28 23:46:06 +0900 LV Status available # open 1 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 # lvscan ACTIVE '/dev/vg_clone/LogVol01' [22.75 GiB] inherit ACTIVE '/dev/vg_clone/LogVol00' [2.00 GiB] inherit
イメージ確認
# qemu-img info stg-01.qcow2 image: stg-01.qcow2 file format: qcow2 virtual size: 30G (32212254720 bytes) disk size: 31G cluster_size: 65536
イメージバックアップ
# cp -a stg-01.qcow2{,.$(date +%Y%m%d)}
ホスト作業
- 拡張確認( 40 Gになっているこを確認)
qcow2 の場合
# qemu-img resize stg-01.qcow2 +10G Image resized. # qemu-img info stg-01.qcow2 image: stg-01.qcow2 file format: qcow2 virtual size: 40G (42949672960 bytes) disk size: 31G cluster_size: 65536
raw の場合
# ionice -c3 nice -n19 dd if=/dev/zero of=stg-01.raw bs=1G count=10 seek=30 10+0 records in 10+0 records out 10737418240 bytes (11 GB) copied, 45.5551 s, 236 MB/s
raw から qcow2へコンバート
# qemu-img convert -f raw -O qcow2 test.img test.qcow2
設定ファイルの編集
# virsh edit test
- raw から qcow2へ修正する
- ディスクのパスを変える
- 拡張確認( 40 Gになっているこを確認)
VM 作業
パーティションテーブル確認
# fdisk -l Disk /dev/vda: 42.9 GB, 42949672960 bytes 16 heads, 63 sectors/track, 83220 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d3c3d Device Boot Start End Blocks Id System /dev/vda1 * 3 510 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 510 62416 31200256 8e Linux LVM Partition 2 does not end on cylinder boundary. Disk /dev/mapper/vg_clone-LogVol01: 24.4 GB, 24431820800 bytes 255 heads, 63 sectors/track, 2970 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_clone-LogVol00: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
デバイス作成
# fdisk /dev/vda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/vda: 42.9 GB, 42949672960 bytes 16 heads, 63 sectors/track, 83220 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d3c3d Device Boot Start End Blocks Id System /dev/vda1 * 3 510 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 510 62416 31200256 8e Linux LVM Partition 2 does not end on cylinder boundary. Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 3 First cylinder (1-83220, default 1): 62417 Last cylinder, +cylinders or +size{K,M,G} (62417-83220, default 83220): Using default value 83220 Command (m for help): p Disk /dev/vda: 42.9 GB, 42949672960 bytes 16 heads, 63 sectors/track, 83220 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d3c3d Device Boot Start End Blocks Id System /dev/vda1 * 3 510 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 510 62416 31200256 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 62417 83220 10485216 5 Extended Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (62417-83220, default 62417): 5 Value out of range. First cylinder (62417-83220, default 62417): Using default value 62417 Last cylinder, +cylinders or +size{K,M,G} (62417-83220, default 83220): Using default value 83220 Command (m for help): p Disk /dev/vda: 42.9 GB, 42949672960 bytes 16 heads, 63 sectors/track, 83220 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d3c3d Device Boot Start End Blocks Id System /dev/vda1 * 3 510 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 510 62416 31200256 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 62417 83220 10485216 5 Extended /dev/vda5 62417 83220 10485184+ 83 Linux Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 8e Changed system type of partition 5 to 8e (Linux LVM) Command (m for help): p Disk /dev/vda: 42.9 GB, 42949672960 bytes 16 heads, 63 sectors/track, 83220 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d3c3d Device Boot Start End Blocks Id System /dev/vda1 * 3 510 256000 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 510 62416 31200256 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 62417 83220 10485216 5 Extended /dev/vda5 62417 83220 10485184+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl( to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
再起動
デバイス確認(再起動後)
# ll /dev/vda* brw-rw----. 1 root disk 252, 0 Feb 24 2015 /dev/vda brw-rw----. 1 root disk 252, 1 Feb 24 12:35 /dev/vda1 brw-rw----. 1 root disk 252, 2 Feb 24 2015 /dev/vda2 brw-rw----. 1 root disk 252, 3 Feb 24 2015 /dev/vda3 brw-rw----. 1 root disk 252, 5 Feb 24 2015 /dev/vda5
物理ボリュームの作成
# pvcreate /dev/vda5 Physical volume "/dev/vda5" successfully created # pvdisplay --- Physical volume --- PV Name /dev/vda2 VG Name vg_clone PV Size 29.75 GiB / not usable 0 Allocatable yes PE Size 4.00 MiB Total PE 7617 Free PE 1280 Allocated PE 6337 PV UUID zIFpTx-fpir-kr5o-tAy-w0o-oYlT-kKsT6A "/dev/vda5" is a new physical volume of "10.00 GiB" --- NEW Physical volume --- PV Name /dev/vda5 VG Name PV Size 10.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID RHlc8J-U63O-LFAG-KrW-fDJs-GYRO-C5yiu3
ボリュームグループの拡張
# vgextend vg_clone /dev/vda5 Volume group "vg_clone" successfully extended # vgdisplay --- Volume group --- VG Name vg_clone System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 8 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 39.75 GiB PE Size 4.00 MiB Total PE 10176 Alloc PE / Size 6337 / 24.75 GiB Free PE / Size 3839 / 15.00 GiB VG UUID B5FxL3-emIw-MGMb-spNv-aL3j-biWH-RypuUp ※ Free PE の増加を確認
論理ボリューム拡張
# lvextend /dev/vg_clone/LogVol01 /dev/vda5 Extending logical volume LogVol01 to 32.75 GiB Logical volume LogVol01 successfully resized # lvdisplay --- Logical volume --- LV Path /dev/vg_clone/LogVol01 LV Name LogVol01 VG Name vg_clone LV UUID rqHjKi-nP7v-9wmW-wcXx-cl6n-eAlD-Gb2hdK LV Write Access read/write LV Creation host, time clone, 2014-05-28 23:46:01 +0900 LV Status available # open 1 LV Size 32.75 GiB Current LE 8384 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_clone/LogVol00 LV Name LogVol00 VG Name vg_clone LV UUID e9xU1n-89pG-y5eT-gjma-rHjW-B9ik-pYrSAn LV Write Access read/write LV Creation host, time clone, 2014-05-28 23:46:06 +0900 LV Status available # open 1 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 # vgdisplay --- Volume group --- VG Name vg_clone System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 9 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 39.75 GiB PE Size 4.00 MiB Total PE 10176 Alloc PE / Size 8896 / 34.75 GiB Free PE / Size 1280 / 5.00 GiB VG UUID B5FxL3-emIw-MGMb-spNv-aL3j-biWH-RypuUp ※ Alloc が増えて、Free PEが減少
ファイルシステム拡張
CentOS7 以降
# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=524032 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=2096128, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 2096128 to 9959424
CentOS7 以前
# resize2fs /dev/vg_clone/LogVol01 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg_clone/LogVol01 is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 3 Performing an on-line resize of /dev/vg_clone/LogVol01 to 8585216 (4k) blocks. The filesystem on /dev/vg_clone/LogVol01 is now 8585216 blocks long. # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_clone-LogVol01 33G 13G 18G 42% / tmpfs 499M 0 499M 0% /dev/shm /dev/vda1 243M 70M 160M 31% /boot
CentOS7 で resize2fs を実行すると下記エラーが出る
resize2fs: Bad magic number in super-block while trying to open /dev/centos/root
df -h で拡張の確認