2
3

More than 5 years have passed since last update.

kvmとlvmベースで作成した仮想サーバのディスク拡張

Posted at

imgファイルではなく、lvmボリュームで作成している仮想サーバのディスク増設手順。
仮想サーバの作成方法にもよるが、仮想サーバ内で再度lvm等を利用していなかった場合
オンラインでディスクの増設が可能になる。(気がする)

lvmボリュームで仮想サーバを作成する理由は
そっちの方が拡張性が高そうな雰囲気を感じるのと
imgファイルより性能が高かったから(趣味の範囲)

対象のlvmを調査して、拡張を行う

対象のストレージpoolを確認

# virsh pool-list

名前               状態     自動起動
-----------------------------------------
default              動作中  はい (yes)
kvm-pool             動作中  はい (yes)

後はlvscanとかvirsh vol-list kvm-poolとか使って適当に。

対象のlvmのディスクを拡張

先に拡張しないとエラーになるので先にlvmを拡張

lvextend -L+10G /dev/vg_kvm/lvmtest-root

仮想サーバ内でのディスクを拡張

virsh blockresize lvmtest /dev/vg_kvm/lvmtest-root 30G

+10Gとか出来そうだけど特に試してない。ちなみにinfoは全く変わらない

# virsh vol-info --pool kvm-pool lvmtest-root

名前:         lvmtest-root
タイプ:      ブロック
容量:         30.00 GiB
割り当て:   30.00 GiB

/etc/init.d/libvirt restartで容量が反映される事は確認してる

そしてこの時点ではまだ仮想サーバにディスク増設が反映されてない
とりあえず今のところ、オンラインで増設は厳しい感じ。
コンフィグ読めてないだけっぽいから、何か方法がある気はしてるけど・・・

オンラインでの増設手段あればご教授ください・・・

対象サーバのreboot

仮想サーバから直にrebootだと容量の増加が確認出来なかったので
コマンドラインから実行してやる。シャットダウンはどこからでもOK

virsh start lvmtest

ディスク領域拡張

何も特別な事しないでfdisk

対象HDD確認

 # fdisk -l

 Disk /dev/sda: 42.9 GB, 42949672960 bytes
 255 heads, 63 sectors/track, 5221 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: 0x0005e801

    Device Boot      Start         End      Blocks   Id  System
 /dev/sda1   *           1          64      512000   83  Linux
 Partition 1 does not end on cylinder boundary.
 /dev/sda2              64        3916    30942246   8e  Linux LVM

/dev/sdaがのディスクが増えてる事を確認

拡張

pvの容量確認

  [root@lvmtest ~]# pvscan
    PV /dev/sda2   VG VolGroup   lvm2 [19.50 GiB / 4.99 GiB free]
    Total: 1 [19.50 GiB] / in use: 1 [19.50 GiB] / in no VG: 0 [0   ]

拡張したディスクをlvmに割り当て

  # fdisk /dev/sda

  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

  Disk /dev/sda: 42.9 GB, 42949672960 bytes
  255 heads, 63 sectors/track, 5221 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: 0x0005e801

     Device Boot      Start         End      Blocks   Id  System
  /dev/sda1   *           1          64      512000   83  Linux
  Partition 1 does not end on cylinder boundary.
  /dev/sda2              64        3916    30942246   8e  Linux LVM

  Command (m for help): d
  Partition number (1-4): 2
  Command (m for help): n
  Command action
     e   extended
     p   primary partition (1-4)
  p
  Partition number (1-4): 2
  First cylinder (64-5221, default 64):
  Using default value 64
  Last cylinder, +cylinders or +size{K,M,G} (64-5221, default 5221):
  Using default value 5221

  Command (m for help): t
  Partition number (1-4): 2
  Hex code (type L to list codes): 8e
  Changed system type of partition 2 to 8e (Linux LVM)

  Command (m for help): p

  Disk /dev/sda: 42.9 GB, 42949672960 bytes
  255 heads, 63 sectors/track, 5221 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: 0x0005e801

     Device Boot      Start         End      Blocks   Id  System
  /dev/sda1   *           1          64      512000   83  Linux
  Partition 1 does not end on cylinder boundary.
  /dev/sda2              64        5221    41424658+  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.

pvに拡張したディスクを割り当て

# pvresize  /dev/sda2

  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

再度確認

[root@lvmtest ~]# pvscan
  PV /dev/sda2   VG VolGroup   lvm2 [39.50 GiB / 25.00 GiB free]
  Total: 1 [39.50 GiB] / in use: 1 [39.50 GiB] / in no VG: 0 [0   ]

lvmに割り当て

対象lvmを確認

# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       14G  5.9G  6.7G  47% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             477M   48M  405M  11% /boot

拡張。今回は20GBを割り当て

# lvextend -L+20G /dev/mapper/VolGroup-lv_root

    Size of logical volume VolGroup/lv_root changed from 13.51 GiB (3458 extents) to 33.51 GiB (8578 extents).
  Logical volume lv_root successfully resized

# resize2fs /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 8783872 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 8783872 blocks long.

増えてる事を確認

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       33G  5.9G   26G  19% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/sda1             477M   48M  405M  11% /boot
/dev/sdb1             965M  1.3M  914M   1% /data
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3