VMware上のCentOSに割り当てたディスク領域を拡張する
VMware Fusion 上の CentOS に割り当てているディスク領域を拡張した際の備忘録。
■概要
Mac の VMware Fusion で作成した CentOS 仮想マシンに割り当てているディスク領域を20GBから40GBに拡張する。
※環境
Mac OS X El Capitan
VMware Fusion 8
CentOS 7
■変更手順
①VMware Fusion 上でディスク容量を増やす
CentOSの仮想マシンをシステム終了している状態で、VMware Fusionの仮想マシン設定パネルを開く。
ここでディスク容量を変更できる。
20GBから40GBに変更する。
②CentOS側でパーティションの容量を増やす
現在のディスクの状態を確認
[root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 18555904 10241464 8314440 56% / devtmpfs 3119660 0 3119660 0% /dev tmpfs 3134112 184 3133928 1% /dev/shm tmpfs 3134112 9184 3124928 1% /run tmpfs 3134112 0 3134112 0% /sys/fs/cgroup /dev/loop0 1900368 6148 1772980 1% /srv/node/swiftloopback /dev/sda1 303788 199580 104208 66% /boot .host:/ 998041088 369500884 628540204 38% /mnt/hgfs tmpfs 626824 20 626804 1% /run/user/1000 [root@localhost ~]# [root@localhost ~]# fdisk -l /dev/sda Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 label type: dos Disk identifier: 0x0000d44c Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 41943039 18566144 83 Linux
現在のディスク容量にはまだ変化はないが、
/dev/sda3 18555904 10241464 8314440 56% /
/dev/sda3 4810752 41943039 18566144 83 Linux
増加したことは認識しているようだ。
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
CentOS側の容量を拡張するため、/dev/sda3 の End を後ろに拡張する。
一度 /dev/sda3 を削除(d)し、End を変更した /dev/sda3 を作成(n)する。
作成の際、First sector と Last sector はデフォルトで設定している。
※パーティション設定を誤るとデータが消える恐れがあるので注意すること!
[root@localhost ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): d Partition number (1-3, default 3): 3 Partition 3 is deleted Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 label type: dos Disk identifier: 0x0000d44c Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 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 (3,4, default 3): 3 First sector (4810752-83886079, default 4810752): Using default value 4810752 Last sector, +sectors or +size{K,M,G} (4810752-83886079, default 83886079): Using default value 83886079 Partition 3 of type Linux and of size 37.7 GiB is set Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 label type: dos Disk identifier: 0x0000d44c Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris /dev/sda3 4810752 83886079 39537664 83 Linux
設定したパーティションで保存(w)して fdisk を終了する。
※もし設定を誤ったりキャンセルしたい場合は'q'で抜ける
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.
警告が出て、再起動後に設定が反映されると言われたので再起動する。
再起動後、dfコマンドで確認するが、まだ /dev/sda3 の容量は変わっていない。
[root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 18555904 10241464 8314440 56% / devtmpfs 3119660 0 3119660 0% /dev tmpfs 3134112 184 3133928 1% /dev/shm tmpfs 3134112 9184 3124928 1% /run tmpfs 3134112 0 3134112 0% /sys/fs/cgroup /dev/loop0 1900368 6148 1772980 1% /srv/node/swiftloopback /dev/sda1 303788 199580 104208 66% /boot .host:/ 998041088 369500884 628540204 38% /mnt/hgfs tmpfs 626824 20 626804 1% /run/user/1000
最後に xfs_growfs コマンドで /dev/sda3 のサイズを変更する。
[root@localhost ~]# xfs_growfs /dev/sda3 meta-data=/dev/sda3 isize=256 agcount=4, agsize=1160384 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=4641536, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 4641536 to 9884416
dfコマンドで再度確認すると、ちゃんと /dev/sda3 の容量が増加している。
[root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 39527424 10241680 29285744 26% / devtmpfs 3119660 0 3119660 0% /dev tmpfs 3134112 184 3133928 1% /dev/shm tmpfs 3134112 9184 3124928 1% /run tmpfs 3134112 0 3134112 0% /sys/fs/cgroup /dev/loop0 1900368 6148 1772980 1% /srv/node/swiftloopback /dev/sda1 303788 199580 104208 66% /boot .host:/ 998041088 369758552 628282536 38% /mnt/hgfs tmpfs 626824 20 626804 1% /run/user/1000