vagrant環境を100GBまで増やした時のメモ
8GBしかディスク容量がないvagrant環境を100GBまで増やした時のメモ
ホストOSでの作業
# vagrantのディスクパスへ移動 cd /cygdrive/c/Users/kinosuke/VirtualBox VMs/golem_default_1514254535481_98090 # vdi形式にクローンする VBoxManage clonehd "centos-vm-disk1.vmdk" "clone-disk1.vdi" --format vdi # 100GBに増やす VBoxManage modifyhd clone-disk1.vdi --resize 102400 容量確認 VBoxManage showhdinfo clone-disk1.vdi # vidからvmdkに変換 VBoxManage clonehd "clone-disk1.vdi" "centos-vm-disk2.vmdk" --format vmdk
VirtualBoxのGUIでディスクを差し替える。
ゲストOSでの作業(パーティションの追加)
ゲストOSの/dev/sdaが増えているので、これから新たなパーティションを作り論理ボリュームに割り当てていく。
# 確認 [root@golem ~]# fdisk -l Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x00051d1a 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 1275 9726976 8e Linux LVM Disk /dev/mapper/VolGroup-lv_root: 8908 MB, 8908701696 bytes 255 heads, 63 sectors/track, 1083 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/VolGroup-lv_swap: 1048 MB, 1048576000 bytes 255 heads, 63 sectors/track, 127 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 # パーティションを追加する。 [root@golem ~]# fdisk /dev/sda 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (1275-13054, default 1275): Using default value 1275 Last cylinder, +cylinders or +size{K,M,G} (1275-13054, default 13054): Using default value 13054 Command (m for help): p Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x00051d1a 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 1275 9726976 8e Linux LVM /dev/sda3 1275 13054 94616255 83 Linux 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): p Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0x00051d1a 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 1275 9726976 8e Linux LVM /dev/sda3 1275 13054 94616255 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.
再起動して反映する
ゲストOSでの作業(ボリュームの作成)
# 物理ボリューム確認 [root@golem ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup PV Size 9.28 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 2374 Free PE 0 Allocated PE 2374 PV UUID hTIxaE-XcZT-GoSQ-sIy7-jD2T-vHZE-MvgwTM # 物理ボリューム作成 [root@golem ~]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created # 物理ボリューム確認 [root@golem ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup PV Size 9.28 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 2374 Free PE 0 Allocated PE 2374 PV UUID hTIxaE-XcZT-GoSQ-sIy7-jD2T-vHZE-MvgwTM "/dev/sda3" is a new physical volume of "90.23 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name PV Size 90.23 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID QD6Ybs-UbFs-ddl8-XUj1-TYHh-hFOk-xO8AYT # ボリュームグループ確認 [root@golem ~]# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 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 9.27 GiB PE Size 4.00 MiB Total PE 2374 Alloc PE / Size 2374 / 9.27 GiB Free PE / Size 0 / 0 VG UUID vSK8ek-anHw-vzIU-hLSC-YyUi-JJCK-43dkaR # 物理ボリュームを、ボリュームグループに追加する [root@golem ~]# vgextend VolGroup /dev/sda3 Volume group "VolGroup" successfully extended # ボリュームグループ確認 [root@golem ~]# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 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 99.50 GiB PE Size 4.00 MiB Total PE 25473 Alloc PE / Size 2374 / 9.27 GiB Free PE / Size 23099 / 90.23 GiB VG UUID vSK8ek-anHw-vzIU-hLSC-YyUi-JJCK-43dkaR # 論理ボリューム確認 [root@golem ~]# lvdisplay --- Logical volume --- LV Path /dev/VolGroup/lv_root LV Name lv_root VG Name VolGroup LV UUID BbyXpl-Lu8z-aDXc-hF5u-ib1j-ml0f-PRlYvR LV Write Access read/write LV Creation host, time localhost.localdomain, 2015-11-02 23:49:55 +0900 LV Status available # open 1 LV Size 8.30 GiB Current LE 2124 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/VolGroup/lv_swap LV Name lv_swap VG Name VolGroup LV UUID yk1n3U-cHOX-jeC6-p8yJ-sMu5-YMLL-oOs2cH LV Write Access read/write LV Creation host, time localhost.localdomain, 2015-11-02 23:49:56 +0900 LV Status available # open 1 LV Size 1000.00 MiB Current LE 250 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 # 論理ボリュームの容量を増やす # Lオプションで指定する追加サイズは、vgdisplayで表示されたFree PE / SizeとPE Sizeをかけた値 [root@golem ~]# lvextend -L +92396 /dev/VolGroup/lv_root Size of logical volume VolGroup/lv_root changed from 8.30 GiB (2124 extents) to 98.53 GiB (25223 extents). Logical volume lv_root successfully resized # ファイルシステムに反映 [root@golem ~]# resize2fs -f /dev/VolGroup/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 7 Performing an on-line resize of /dev/VolGroup/lv_root to 25828352 (4k) blocks. The filesystem on /dev/VolGroup/lv_root is now 25828352 blocks long. # 確認 [root@golem ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 97G 7.6G 85G 9% / tmpfs 1.9G 4.0K 1.9G 1% /dev/shm /dev/sda1 477M 57M 396M 13% /boot
参考にさせていただきました
https://qiita.com/koitaro/items/c8bf8eb1e67e78890a5c
http://te2u.hatenablog.jp/entry/2015/04/20/012914