Xen+CentOS6.3でのディスク領域拡張(LVM編)

Xenの仮想サーバでdisk領域が足りなくなった際の対処と
してサーバへの割り当てサイズを増やす時の手順です。

【前提条件】

ホストOS:Xen
ゲストOS:CentOS6.3
ゲストOSパーティション:LVM
ホストOSのディスク領域は割り当て済みで空きがある

RHELの最近のバージョンであればほぼLVMになっていると思います。
LVM以外の方法はliknux disk領域拡張で記載しています。

まずはXen側のサイズを変更します。
XenCenterを開き該当の仮想サーバをShutDownします。
その後、ストレージがあるVirtualDisksを選択して、仮想サーバのDiskのProertiesから
Size and Locationを開きサイズを変更します。
※停止していないとsizeを変える事ができません。
今回は1300GBから1700GBへ拡張しました。
サイズを変更したらVMを起動します。

Xen側の作業は以上です。
続いてゲストOS側の作業です。

fdiskでlvmのパーティションを作成します。

まずはfdiskで確認
# fdisk -l

Disk /dev/xvda: 1825.4 GB, 1825361100800 bytes
255 heads, 63 sectors/track, 221920 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: 0x00077127

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 169704 1362634356 8e Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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_home: 1339.5 GB, 1339534868480 bytes
255 heads, 63 sectors/track, 162855 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

/dev/xvdaが1800GBありますが割り当てが53Gと1339Gだけである事がわかります。
注意!!
ここの値はdiskのbytesサイズなのでXen等で設定した値と違うので間違えないように!!

# fdisk /dev/xvda

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): p  ←パーティションの確認、2番目の/dev/xvda2が今回の対象です。

Disk /dev/xvda: 1825.4 GB, 1825361100800 bytes
255 heads, 63 sectors/track, 221920 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: 0x00077127

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 169704 1362634356 8e Linux LVM

Command (m for help): d  ←削除
Partition number (1-4): 2  ←パーティション指定

Command (m for help): p  ←対象パーティションが消えている事を確認

Disk /dev/xvda: 1825.4 GB, 1825361100800 bytes
255 heads, 63 sectors/track, 221920 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: 0x00077127

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.

Command (m for help): n  ←新規パーティション作成
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2  ←パーティション指定
First cylinder (64-221920, default 64):   ←Startセクターを指定、全部使うのでdefault指定
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-221920, default 221920):   ←Endセクターを指定、こちらもdefault指定
Using default value 221920

Command (m for help): p  ←空き領域が全部割り当て有られている事を確認します。

Disk /dev/xvda: 1825.4 GB, 1825361100800 bytes
255 heads, 63 sectors/track, 221920 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: 0x00077127

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 221920 1782059376 83 Linux

Command (m for help): t  ←LVMにする為にsystemidを変更します。
Partition number (1-4): 2  ←パーティション指定
Hex code (type L to list codes): 8e  ←LVMのidを指定、idを確認する場合はCommandでlで一覧がでます。
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p  ←最終チェックをします。

Disk /dev/xvda: 1825.4 GB, 1825361100800 bytes
255 heads, 63 sectors/track, 221920 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: 0x00077127

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 221920 1782059376 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.
# reboot ←デバイスが使用中だから適用させる為にリブートをします。

リブート完了後、ボリュームの拡張を実施します。
サイズを確認、この時点では何も変わっていません。
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 1.2G 46G 3% /
tmpfs 503M 0 503M 0% /dev/shm
/dev/xvda1 485M 30M 430M 7% /boot
/dev/mapper/VolGroup-lv_home
1.2T 1.1T 70G 95% /home

◎物理ボリュームの拡張
サイズの確認
# pvscan
PV /dev/xvda2 VG VolGroup lvm2 [1.27 TiB / 0 free]
Total: 1 [1.27 TiB] / in use: 1 [1.27 TiB] / in no VG: 0 [0 ]
再割り当てを実施
# pvresize /dev/xvda2
Physical volume “/dev/xvda2” changed
1 physical volume(s) resized / 0 physical volume(s) not resized
サイズが大きくなっている事を確認
# pvscan
PV /dev/xvda2 VG VolGroup lvm2 [1.66 TiB / 399.99 GiB free]
Total: 1 [1.66 TiB] / in use: 1 [1.66 TiB] / in no VG: 0 [0 ]

◎論理ボリュームの拡張
サイズの確認
# lvscan
ACTIVE ‘/dev/VolGroup/lv_root’ [50.00 GiB] inherit
ACTIVE ‘/dev/VolGroup/lv_home’ [1.22 TiB] inherit
ACTIVE ‘/dev/VolGroup/lv_swap’ [1.97 GiB] inherit

サイズの再割り当て、400GだとNGだったので399Gにしています。
# lvscan resize -L +399G /dev/VolGroup/lv_home
Extending logical volume lv_home to 1.61 TiB
Logical volume lv_home successfully resized
サイズが変更されている事を確認
# lvscan
ACTIVE ‘/dev/VolGroup/lv_root’ [50.00 GiB] inherit
ACTIVE ‘/dev/VolGroup/lv_home’ [1.61 TiB] inherit
ACTIVE ‘/dev/VolGroup/lv_swap’ [1.97 GiB] inherit

◎ファイルシステムの拡張

対象ボリュームを指定して再割り当てを実施、サイズによっては結構時間がかかります。
# resize2fs /dev/mapper/VolGroup-lv_home
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_home is mounted on /home; on-line resizing required
old desc_blocks = 78, new_desc_blocks = 103
Performing an on-line resize of /dev/mapper/VolGroup-lv_home to 431630336 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_home is now 431630336 blocks long.

無事拡張されました。
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 1.2G 46G 3% /
tmpfs 503M 0 503M 0% /dev/shm
/dev/xvda1 485M 30M 430M 7% /boot
/dev/mapper/VolGroup-lv_home
1.6T 1.1T 443G 72% /home

注意!!
拡張は必ず物理→論理→ファイルシステムの順番で実施して下さい。
基本は箱の外側から大きくしていくことです。
外側が広がっていなければ内側が広がる事はないですからね。

コメントする