VirtualBox上のCentOSのディスク容量を拡張する #virtualbox #centos
WindowsのVirtualBoxにCentOSを入れていますが、長く使っているとディスク容量が足りなくなったので拡張しました。方法をメモします。
VirtualBoxの仮想ディスクサイズ拡張
ゲストOS(CentOS)停止してプロンプトを起動。VBoxManage.exeコマンドで仮想ディスクサイズを拡張します。
$ "{VirtualBoxインストールディレクトリ}\VBoxManage.exe" modifyhd [対象のvdiファイル] --resize [変更後サイズ(MB)]
仮想ディスクパーティションサイズ拡張
Gnome Partition Editorを使って仮想ディスクパーティションサイズを変更します。
公式から「GParted Live CD/USB/HD/PXE Bootable Image > Stable Releases > xxxlivexxx.iso」と辿ってisoイメージをダウンロードします。
VirtualBoxの設定メニューから「 設定>ストレージ>コントローラ:IDEにダウンロードしたISOイメージを追加」と辿って、ダウンロードしたISOイメージをマウントします。
ゲストOS起動して、言語に日本語、モードにGUIモードを選択します。対象のパーティションを右クリックしてリサイズを選択。仮想ディスクサイズと同様のサイズに変更してApplyを選択します。
起動しているGnome Pertition EditorのOSを停止して、ISOイメージファイルをアンマウントします。
CentOSの仮想ボリューム拡張
このままではCentOSのLVMのサイズが変更されていませんので、変更します。
LVMを確認 $ fdisk -l Disk /dev/sda: 17.2 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 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: 0x0000d424 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2089 16264192 8e Linux LVM Disk /dev/mapper/vg_centos-lv_root: 3833 MB, 3833593856 bytes 255 heads, 63 sectors/track, 466 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_centos-lv_swap: 4227 MB, 4227858432 bytes 255 heads, 63 sectors/track, 514 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 LVMのサイズ拡張 $ lvextend -l +100%FREE /dev/mapper/vg_centos-lv_root Extending logical volume lv_root to 11.57 GiB Logical volume lv_root successfully resized まだ反映されていない $ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 3.6G 2.9G 468M 87% / tmpfs 939M 0 939M 0% /dev/shm /dev/sda1 485M 53M 407M 12% /boot サイズ拡張を反映 $ resize2fs /dev/mapper/vg_centos-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_centos-lv_root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/mapper/vg_centos-lv_root to 3033088 (4k) blocks. The filesystem on /dev/mapper/vg_centos-lv_root is now 3033088 blocks long. 拡張された $ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 12G 2.9G 8.0G 27% / tmpfs 939M 0 939M 0% /dev/shm /dev/sda1 485M 53M 407M 12% /boot
参考
linux - How to increase a virtualbox' disk size? - Super User