VMware仮想ディスクの拡張
VMware で仮想ディスクのサイズを変更したくなったとき :: Drk7jp
そんな面倒くさいことをしなくても、VMwareで動作させている環境がKernel 2.6+LVM2で、Logical Volumeがext2かext3でフォーマットしてあるのであれば、何も考えずにオンラインリサイズできます。
もともと8GBだった仮想ディスクに2GB加えて10GBにする場合を例に説明します。まず、拡張前のfdisk, dfの出力がこんな感じです。
# /sbin/fdisk -l
Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 1044 8281507+ 8e Linux LVM
# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
7459216 ? ? ?% /
/dev/hda1 101086 15767 80100 17% /boot
tmpfs 127636 0 127636 0% /dev/shm
最初に行うのは、VMをshutdownし、vmware-vdiskmanager.exeを使って仮想ディスクを拡張することです。非常に時間がかかります。
vmware-vdiskmanager.exe -x 10Gb vdisk.vmdk
Windows版ではなく、Linux版のVMware Workstation, VMware Serverでもvmware-vdiskmanagerというコマンドが使えます。
次に通常通りVMを立ち上げて(正確には以降の作業はSingle User Modeでやった方がよいでしょう)、fdiskでパーティションを切ります。
# /sbin/fdisk /dev/hda -l Disk /dev/hda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 13 104391 83 Linux /dev/hda2 14 1044 8281507+ 8e Linux LVM # /sbin/fdisk /dev/hda The number of cylinders for this disk is set to 1305. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (1045-1305, default 1045): 1045 Last cylinder or +size or +sizeM or +sizeK (1045-1305, default 1305): 1305 Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): 8e Changed system type of partition 3 to 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. Syncing disks. # reboot (再起動) # /sbin/fdisk -l Disk /dev/hda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 13 104391 83 Linux /dev/hda2 14 1044 8281507+ 8e Linux LVM /dev/hda3 1045 1305 2096482+ 8e Linux LVM
おめでとうございます。/dev/hda3が作られました。
はい、次。/dev/hda3を元にPhysical Volumeを作り、Volume Group(VolGroup00)に追加し、VolGroup00のLogical Volume(LogVol00)を拡張します。
# /usr/sbin/pvcreate /dev/hda3 Physical volume "/dev/hda3" successfully created # /usr/sbin/vgextend VolGroup00 /dev/hda3 Volume group "VolGroup00" successfully extended # /usr/sbin/lvextend -L +2G /dev/VolGroup00/LogVol00 Extending logical volume LogVol00 to 9.34 GB Logical volume LogVol00 successfully resized
最後にresize2fsを実行します。
# /sbin/resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2449408 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2449408 blocks long.
# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
9490960 2893504 6109240 33% /
/dev/hda1 101086 15767 80100 17% /boot
tmpfs 127636 0 127636 0% /dev/shm
確かに増えました。ありがとうございました。
仮想ディスクをvmware-vdiskmanagerで拡張する代わりに、別の仮想ディスクを作った場合にも同じ方法が使えるはずです。基本的にはLVMにできることはLVMに任せてしまう方が安全にかつ柔軟にディスク領域の拡張が実現できます。
このエントリーのトラックバックURL: http://as-is.net/mt/mt-tb.cgi/457
おお!スバラシイ!ちゃんと LVMの機能を活かした方法ですね。
仮想ディスクを使う限りは、パーティションをenlargeする方法でもこの方法でもあんまり性能的に差がなさそうな気がしています。LVMのオーバーヘッドはほとんど無視できるかな、と。
物理ディスクを使えば随分速くなるんでしょうね。ただ、バックアップとかどうするのでしょう。