本日、新オプションとしてディスク増設機能をリリースしました。1GB単位でディスクを最大4台、最大250GB × 4 = 1TBまで追加できます。ディスクを追加した後はファイルシステムとして使える状態にしなければなりませんが、ユニットホスティングでは仮想サーバはLVMを使用していますので、LVMを使用して/パーティションの拡張を行うまでをご紹介します。
まずは、ディスクの増設から。今回は250GB追加してみます。カスタマイズ画面からスライダーをガーっと右までスライドして適用を押すと下記のようにディスクが追加された旨が表示されます。
ディスク増設の項目にディスクのエントリが追加されました。簡単ですね。デバイスファイル名はブラウザに表示されている /dev/xvdb となります。
実際にコンソールからfdiskコマンドで見てみましょう。
$ sudo /sbin/fdisk -l /dev/xvdb
Disk /dev/xvdb: 268.4 GB, 268435456000 bytes
255 heads, 63 sectors/track, 32635 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/xvdb doesn't contain a valid partition table
と、ディスクが実際に追加されています。ここからディスクを使えるようにするにはfdiskでパーティションを切り、ファイルシステムとして使用できるようにしなければなりません。
今回は、LVMを使用しているのでディスクとして追加するのではなく、LVMのLVの一つを拡張して/パーティションの空き容量を増やしてみたいと思います。手順は以下の順序です。
- fdiskでLVMパーティションを作成
- 新しく作ったLVMパーティションにPVを作成
- 新しいPVを既存のVGに追加
- /パーティションとして使用しているLVを拡張
- resize2fsで/パーティションのファイルシステムを拡張
以降は実際に作業した際のログを表示します。その方が分かりやすいですよね:-)
1. fdiskでLVMパーティションを作成
$ sudo /sbin/fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 32635.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-32635, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-32635, default 32635):
Using default value 32635
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/xvdb: 268.4 GB, 268435456000 bytes
255 heads, 63 sectors/track, 32635 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvdb1 1 32635 262140606 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
これで、LVMパーティションが作成されました。次のステップへ進みましょう。
2. 新しく作ったLVMパーティションにPVを作成
$ sudo /usr/sbin/pvcreate /dev/xvdb1
Physical volume "/dev/xvdb1" successfully created
ここはメッセージ通りですね。
3. 新しいPVを既存のVGに追加
$ sudo /usr/sbin/vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 19.72G 0
VG追加前はVGの空きが0になってますね。VGへPVを追加してみましょう。
$ sudo /usr/sbin/vgextend VolGroup00 /dev/xvdb1
Volume group "VolGroup00" successfully extended
$ sudo /usr/sbin/vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 2 2 0 wz--n- 269.69G 249.97G
空き容量が一気に250GB増えました。
4. /パーティションとして使用しているLVを拡張
実際に拡張前の状況を見てみましょう。
$ sudo /usr/sbin/lvdisplay /dev/VolGroup00/LogVol00
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID s9d6Rn-eo2K-7VqU-Pxgq-AA4o-kz3W-bQFI9n
LV Write Access read/write
LV Status available
# open 1
LV Size 18.72 GB
Current LE 599
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
では、LVを拡張してみます。
$ sudo /usr/sbin/lvextend -l +100%FREE /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 249.97 GB
Logical volume LogVol00 successfully resized
で、確認。
$ sudo /usr/sbin/lvdisplay /dev/VolGroup00/LogVol00
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID s9d6Rn-eo2K-7VqU-Pxgq-AA4o-kz3W-bQFI9n
LV Write Access read/write
LV Status available
# open 1
LV Size 249.97 GB
Current LE 7999
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
ここで、lvextendのオプションで-l +100%FREEはVGの空き容量全部使っちまえーというオプションです。もちろんオプションを変更して空き容量の50%とかも可能です。
5. resize2fsで/パーティションのファイルシステムを拡張
これでやっと最後です。コマンド打つだけならすぐなのですが、文章にすると長くなるものですね。あと一息頑張りましょう。ファイルシステムの拡張前に現在の状況を確認します。
$ sudo /bin/df -h /dev/mapper/VolGroup00-LogVol00
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
19G 1.4G 16G 8% /
容量は19GBとなっています。では徐ろにresize2fsを実行します。
$ sudo /sbin/resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 65527808 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 65527808 blocks long.
$ sudo /bin/df -h /dev/mapper/VolGroup00-LogVol00
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
243G 1.4G 229G 1% /
このコマンドの実行時間はディスク容量に応じて変わります。大きい容量であればそれなりにかかりますが、程なくコマンドは正常に終了しました。実際にdfで確認してみると243GBまで容量が増えていますね。
これでディスクが20GB+250GBになりました。簡単ですね。
なんだかLVMのチュートリアルみたいになってしまいましたが、もちろん/パーティションを拡張するのではなく特定のディレクトリにマウントして使用することも可能です。一時的に使用するならそちらの方が分かりやすいかもしれませんね。
ディスクを増設してLVMで使用している場合、不要になった際には適切な取り扱いをしないとサーバのファイルシステムを壊しますので取り扱いにはご注意ください。
でわまた。





$ sudo /usr/sbin/lvextend -l100%FREE /dev/VolGroup00/LogVol00
New size given (279 extents) not larger than existing size (319 extents)
Run `lvextend –help’ for more information.
100%FREE ではなく、 +100%FREEにしないと成功しませんでした。
$ sudo /usr/sbin/lvextend -l +100%FREE /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 18.69 GB
Logical volume LogVol00 successfully resized