動機
今、テスト環境として利用しているVMwareのGuest OSの容量がかつかつなので広げる必要があった。
方法
vmware-vdiskmanagerを用いれば可能。
$ vmware-vdiskmanager -x DISK_SIZE VMDK_FILENAME.vmdk
DISK_SIZEは拡張後に期待するディスクサイズです。
作業ログ
今回はメインのボリュームを増やした上にswap領域も拡大するという目的で行いました。
ディスクボリューム拡大
まずfdisk -lで容量の確認
- Guest OS
# /sbin/fdisk -l Disk /dev/sda: 16.1 GB, 16106127360 bytes 255 heads, 63 sectors/track, 1958 cylinders Units = シリンダ数 of 16065 * 512 = 8225280 bytes デバイス Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1305 10377990 8e Linux LVM /dev/sda3 1306 1958 5245222+ 8e Linux LVM # df -k Filesystem 1K-ブロック 使用 使用可 使用% マウント位置 /dev/mapper/VolGroup00-LogVol00 13354544 12679456 1772 100% / /dev/sda1 101086 13363 82504 14% /boot none 708248 0 708248 0% /dev/shm # shutdown -h now Broadcast message from root (pts/2) (Sun Mar 8 16:02:52 2009): The system is going down for system halt NOW!
次にVMWareイメージのリサイズ
- Host OS
$ vmware-vdiskmanager -x 20Gb Red\ Hat\ Enterprise\ Linux\ 4\ \(3\).vmdk
リサイズした領域を論理ボリュームに割当て
- Guest OS
$ su - # telinit 1 ←Run LevelをSingle User Modeに下げる # /sbin/fdisk /dev/sda -l Disk /dev/sda/: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1305 10377990 8e Linux LVM /dev/sda3 1306 1958 5245222+ 8e Linux LVM # /sbin/fdisk /dev/sda 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): 4 First cylinder (1959-2610, default 1959): 1959 Last cylinder or +size or +sizeM or +sizeK (1959-2610, default 2610): 2610 Command (m for help): t Partition number (1-4): 4 Hex code (type L to list codes): 8e Changed system type of partition 4 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/sda: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = シリンダ数 of 16065 * 512 = 8225280 bytes デバイス Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1305 10377990 8e Linux LVM /dev/sda3 1306 1958 5245222+ 8e Linux LVM /dev/sda4 1959 2610 5237190 8e Linux LVM # /usr/sbin/pvcreate /dev/sda4 Physical volume "/dev/sda4" successfully created # /usr/sbin/vgextend VolGroup00 /dev/sda4 Volume group "VolGroup00" successfully extended # /usr/sbin/lvextend -L +7G /dev/VolGroup00/LogVol00 Extending logical volume LogVol00 to 19.94 GB Insufficient free space: 224 extents needed, but only 159 available # /usr/sbin/lvextend -L +4.9G /dev/VolGroup00/LogVol00 Rounding up size to full physical extent 4.91GB Extending logical volume LogVol00 to 17.84 GB Logical volume LogVol00 successfully resized # /sbin/resize2fs /dev/VolGroup00/LogVol00 ←resize2fsで失敗した。 resize2fs 1.35 (28-Feb-2004) /dev/VolGroup00/LogVol00 is mounted; can't resize a mounted filesystem! # ext2online /dev/VolGroup00/LogVol00 ext2online v1.1.10 - 2001/03/10 for EXT2FS 0.5b
最後ext2onlineで論理ボリュームに割り当てたけどresize2fsでなくて大丈夫なんかなあ。
スワップ領域拡大
まずswap領域用の場所を確保してswap用ファイルを作成。
# mkdir /swap # dd if=/dev/zero of=/swap/swap0 bs=1024 count=4194304 # chmod 600 /swap/swap0 # mkswap /swap/swap0 4194304 Setting up swapspace version 1, size = 4294963 kB
swap領域を確保したらswapに追加。
# swapon /swap/swap0 # less /proc/swaps Filename Type Size Used Priority /dev/mapper/VolGroup00-LogVol01 partition 2031608 0 -1 /swap/swap0 file 4194296 0 -2
無事に使えることが確認できたら再起動しても同様の設定になるようにrc.localに追加。
# vi /etc/rc.d/rc.local + swapon /swap/swap0