仮想マシン(今回の場合CentOS 7)でディスクの拡張を行った際、特にISOブートとかさせることもなくLVM領域の拡張を行う必要があったので、備忘として残しておく。
(特に目新しいことをしたわけではなく、普通にやることやっただけなのだけど…よく忘れるので)
1.ディスクの拡張
まず、対象の仮想マシンのディスクを拡張する。ここについては各仮想基盤ごとに違うと思う。
ちなみに個人的にProxmoxVEを使っているので、対象の仮想マシンを選択して[ハードウェア]タブを開き、対象のハードディスクを選択して[Resize Disk]、ディスクに追加する容量を入力するだけだ。
ディスクの拡張後、一度OSを再起動させる。
2.パーティションの拡張
次に、fdiskを使ってパーティションの拡張を行う。
やってることは簡単で、一度既存のパーティションを削除し、その次に各パーティションを作り直しさせているだけだ。
[root@BS-PUB-WEBTOOL-TEST01 ~]# df -h ファイルシス サイズ 使用 残り 使用% マウント位置 /dev/mapper/centos-root 36G 1.4G 35G 4% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.4M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 497M 167M 330M 34% /boot tmpfs 380M 0 380M 0% /run/user/0 [root@BS-PUB-WEBTOOL-TEST01 ~]# 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. コマンド (m でヘルプ): p Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x000cf688 デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 83886079 41430016 8e Linux LVM コマンド (m でヘルプ): d パーティション番号 (1,2, default 2): 2 Partition 2 is deleted コマンド (m でヘルプ): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p パーティション番号 (2-4, default 2): 最初 sector (1026048-125829119, 初期値 1026048): 初期値 1026048 を使います Last sector, +sectors or +size{K,M,G} (1026048-125829119, 初期値 125829119): 初期値 125829119 を使います Partition 2 of type Linux and of size 59.5 GiB is set コマンド (m でヘルプ): w パーティションテーブルは変更されました! ioctl() を呼び出してパーティションテーブルを再読込みします。 WARNING: Re-reading the partition table failed with error 16: デバイスもしくはリソースがビジー 状態です. 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) ディスクを同期しています。
これで、パーティションの変更処理が行えた。
といっても現時点ではマウントしている領域なので、一度再起動してから反映されることになる。
OSを再起動しよう。
3.LVM領域の拡張をする
再起動完了後、LVM領域の拡張をさせる。
まず、pvresizeコマンドでPhysical volumeの領域を変更する。
pvresize /dev/sda2
[root@BS-PUB-WEBTOOL-TEST01 ~]# pvresize /dev/sda2 Physical volume "/dev/sda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized
今回の場合、Phycial Volumeをそのまま拡張したので、Volume Groupもそのまま拡張されている。
続いて、以下のコマンドで拡張されたVolume Groupの領域をすべてLogical Volumeに割り当てる。
lvextend -l +100%FREE /dev/centos/root
[root@BS-PUB-WEBTOOL-TEST01 ~]# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 35.59 GiB (9111 extents) to 55.63 GiB (14242 extents). Logical volume root successfully resized.
最後に、ファイルシステムのリサイズをさせる。
CentOS 7の場合、「resize2fs」ではなく「xfs_growfs」を使う。
xfs_growfs /dev/centos/root
[root@BS-PUB-WEBTOOL-TEST01 ~]# # resize2fsだと以下のようなエラーがでる [root@BS-PUB-WEBTOOL-TEST01 ~]# resize2fs /dev/centos/root resize2fs 1.42.9 (28-Dec-2013) resize2fs: Bad magic number in super-block while trying to open /dev/centos/root Couldn't find valid filesystem superblock. [root@BS-PUB-WEBTOOL-TEST01 ~]# [root@BS-PUB-WEBTOOL-TEST01 ~]# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=2332416 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=9329664, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=4555, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 9329664 to 14583808 [root@BS-PUB-WEBTOOL-TEST01 ~]# df -h ファイルシス サイズ 使用 残り 使用% マウント位置 /dev/mapper/centos-root 56G 1.4G 55G 3% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.3M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 497M 167M 330M 34% /boot tmpfs 380M 0 380M 0% /run/user/0
これで処理は完了。
![[改訂新版]プロのためのLinuxシステム構築・運用技術 (Software Design plus)](http://ecx.images-amazon.com/images/I/61%2BvBxCb0zL._SL160_.jpg)