LVM 使わずに作成した virtualbox 仮想マシンのディスクを、 ちょっとずつ必要に応じてサイズ拡張しているといつも手順を忘れるのでメモしておく。
vmdk 形式ではリサイズできないので vdi フォーマットに変換する
ファイルを作成するのでそこそこ時間がかかる
VBoxManage clonehd gentoo-disk1.vmdk gentoo-disk1.vdi --format VDI
作成した vdi ファイルの論理サイズを拡張する
実際にファイルサイズを拡張するわけではないので一瞬でおわる。 MB 単位で指定するので、ここでは 16 GB にしている。
VBoxManage modifyhd gentoo-disk1.vdi --resize 16384
仮想マシンの仮想ディスクを付け替える
新しく作成した vdi 形式のディスクへ付け替える。
おなじ SATA ポートで
↓
つけかえる
パーティションを拡張する
ディスクは拡張しても OS からわからないので、パーティションを拡張する。 fdisk コマンドで行うが、「拡張」オプションはないので消してから再作成する。
ディスク自体が拡張しているか確認する。
fdisk -l
Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 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: 0x2147bbb1 Device Boot Start End Blocks Id System /dev/sda1 2048 206847 102400 83 Linux /dev/sda2 206848 4401151 2097152 82 Linux swap / Solaris /dev/sda3 4401152 31457279 13528064 83 Linux
上の状態だと /dev/sda3 が拡張したい領域なので一度消す
fdisk /dev/sda
Command (m for help): d Partition number (1-4): 3 Partition 3 is deleted
消えている
Command (m for help): p Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 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: 0x2147bbb1 Device Boot Start End Blocks Id System /dev/sda1 2048 206847 102400 83 Linux /dev/sda2 206848 4401151 2097152 82 Linux swap / Solaris
再作成
Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (1-4, default 3): 3 First sector (4401152-33554431, default 4401152): Using default value 4401152 Last sector, +sectors or +size{K,M,G} (4401152-33554431, default 33554431): Using default value 33554431 Partition 3 of type Linux and of size 13.9 GiB is set
確認
Command (m for help): p Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 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: 0x2147bbb1 Device Boot Start End Blocks Id System /dev/sda1 2048 206847 102400 83 Linux /dev/sda2 206848 4401151 2097152 82 Linux swap / Solaris /dev/sda3 4401152 33554431 14576640 83 Linux
保存して終了
Command (m for help): w The partition table has been altered!
ファイルサイズを拡張する
パーティションが拡張できたらファイルサイズを拡張して OS に認識させる。
resize2fs /dev/sda3
確認
df -h
設定したサイズに増えていれば完了。
ホストマシンのディスクを圧迫するので不要になった vmdk ファイルを捨てる。