vSphere上のLinux(RedHat7)のディスク容量の拡張
※もともと、LinuxホストのボリュームはLVMで構成されているとしています。
目次
vSphere上の仮想マシンのディスクサイズの拡張
- 重要なサーバの場合、仮想マシンのクローンを作成しておきます。
※事情によりだと思いますが「クローン オプションの選択」ではカスタマイズしません。
- vSphere(Web)Clientで対象の仮想マシンを選択して「設定の編集」からハードディスクの容量(赤枠部分)を拡張します。
※仮想マシンが「パワーオフ」の状態でないと変更できません。
- 変更が確認できたら仮想マシンを「パワーオンします。」
仮想マシンのディスクの拡張をOSに認識させる。
パーティションの作成
事前確認
# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
/dev/mapper/rhel-root 302G 3.4G 299G 2% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 17M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/rhel-usr_local 90G 27G 64G 30% /usr/local ←ここに追加しようと思います。
/dev/sda1 509M 168M 342M 33% /boot
tmpfs 783M 0 783M 0% /run/user/1003
tmpfs 783M 0 783M 0% /run/user/0
パーティションツールによる確認
# fdisk -l
Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors ←追加した分がちゃんと認識されてます。
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000d0582
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 1050623 524288 83 Linux
/dev/sda2 1050624 838860799 418905088 8e Linux LVM
Disk /dev/mapper/rhel-root: 323.7 GB, 323724771328 bytes, 632274944 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk /dev/mapper/rhel-swap: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk /dev/mapper/rhel-usr_local: 96.6 GB, 96636764160 bytes, 188743680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
パーティションツールによる/dev/sda(ハードディスク1)の設定
# 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: 536.9 GB, 536870912000 bytes, 1048576000 sectors ←増えてる
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000d0582
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 1050623 524288 83 Linux
/dev/sda2 1050624 838860799 418905088 8e Linux LVM
増えた領域に新しいパーティションを作成します。
コマンド (m でヘルプ): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
パーティション番号 (3,4, default 3): 3
最初 sector (838860800-1048575999, 初期値 838860800): [空Enter(初期値)]
初期値 838860800 を使います
Last sector, +sectors or +size{K,M,G} (838860800-1048575999, 初期値 1048575999): [空Enter(初期値)]
初期値 1048575999 を使います
Partition 3 of type Linux and of size 100 GiB is set ←パーティション3を100GBで設定しましたよ!
設定内容の確認
※この時点ではまだ反映されていないのでFDISKツールを終了すると元に戻ります。間違えたら修正できます。
コマンド (m でヘルプ): p
Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000d0582
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 1050623 524288 83 Linux
/dev/sda2 1050624 838860799 418905088 8e Linux LVM
/dev/sda3 838860800 1048575999 104857600 83 Linux ←拡張した空き領域に「/dev/sda3」ができてます。
ボリュームラベルの編集
※機能的には何の影響もありませんが、後々わからなくなると困るのでまじめに設定しておきます。
コマンド (m でヘルプ): t
パーティション番号 (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
変更内容を確認しておきます。
コマンド (m でヘルプ): p
Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000d0582
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 1050623 524288 83 Linux
/dev/sda2 1050624 838860799 418905088 8e Linux LVM
/dev/sda3 838860800 1048575999 104857600 8e Linux LVM ←「Linux」が「Linux LVM」に変更されました。
変更した内容をパーティションテーブルに書き込みます
コマンド (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) ←要は「新しいテーブルを利用するためにはrebootかpartprobeツールかkpartxを使ってね」ということです。
ディスクを同期しています。
・・・・素直にOSを再起動しました。
ボリュームグループの拡張
起動後、VGの状態を確認します。
# vgdisplay -C
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 399.50 GiB
PE Size 4.00 MiB
Total PE 102271
Alloc PE / Size 102270 / 399.49 GiB ←まだ増えてません。
Free PE / Size 1 / 4.00 MiB
VG UUID sVVdsf-1IRU-fUYq-IQhP-A7wl-cgDm-EWRM3i
「VG Name:rhel」に「/dev/sda3」を追加します。
CAUTION
pvcreateについて
こういう作業の場合、ほとんどのお手本には「pvcreate(PV作成)」が記述されていますが、「vgextend」を実行する際、物理デバイスにpvが設定されていなかった場合、設定する機能が実装されていますのでこの手順の中でも割愛しています。
# man vgextend
~中略~
If PhysicalDevicePath was not previously configured for LVM with pvcreate(8), the device will be initialized with the same
default values used with pvcreate(8). If non-default pvcreate(8) values are desired, they may be given on the commandline
with the same options as pvcreate(8). See PHYSICAL DEVICE OPTIONS for available options. Note that the restore-related
options such as --restorefile, --uuid and --physicalvolumesize are not available. If a restore operation is needed, use
pvcreate(8) and vgcfgrestore(8).
# vgextend rhel /dev/sda3
Physical volume "/dev/sda3" successfully created
Volume group "rhel" successfully extended
改めてVGの状態を確認します。
# vgextend rhel /dev/sda3display
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 499.49 GiB ←VGのサイズが前の「399.50 GiB」から増えてます。
PE Size 4.00 MiB
Total PE 127870
Alloc PE / Size 102270 / 399.49 GiB
Free PE / Size 25600 / 100.00 GiB ←空き容量が増えてます。
VG UUID sVVdsf-1IRU-fUYq-IQhP-A7wl-cgDm-EWRM3i
論理ボリューム(LVM)の拡張
LVの状態を確認します。
# lvdisplay
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
~中略~
--- Logical volume ---
LV Path /dev/rhel/usr_local ←ここに割り当てようと思います。
LV Name usr_local
VG Name rhel
LV UUID l7wFu0-reCQ-nZgE-jeS2-jYUN-MNLe-amSuT9
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-09-28 18:56:05 +0900
LV Status available
# open 1
LV Size 90.00 GiB
Current LE 23040
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
~中略~
「/dev/rhel/usr_local」を空き領域いっぱいに拡張します。
# lvextend -l +100%FREE /dev/rhel/usr_local
Size of logical volume rhel/usr_local changed from 90.00 GiB (23040 extents) to 190.00 GiB (48640 extents).
Logical volume usr_local successfully resized.
LVの状態を確認します。
# lvdisplay
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
~中略~
--- Logical volume ---
LV Path /dev/rhel/usr_local
LV Name usr_local
VG Name rhel
LV UUID l7wFu0-reCQ-nZgE-jeS2-jYUN-MNLe-amSuT9
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-09-28 18:56:05 +0900
LV Status available
# open 1
LV Size 190.00 GiB
Current LE 48640
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
~中略~
最終の結果確認です。
# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
/dev/mapper/rhel-root 302G 3.4G 299G 2% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 36K 3.9G 1% /dev/shm
tmpfs 3.9G 17M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 509M 168M 342M 33% /boot
/dev/mapper/rhel-usr_local 190G 27G 164G 15% /usr/local ←ちゃんと増えてます。
tmpfs 783M 0 783M 0% /run/user/1003
雑感:この手の作業で一番時間がかかるのは実際、「作業前バックアップ」ですよね。