Ubuntu14.04 の LVM領域拡張

1. 現在の領域情報を表示

admin@Ubuntu-SV-1404:~$ df -h

Filesystem      Size  Used Avail Use% Mounted on
udev            481M  4.0K  481M   1% /dev
tmpfs            99M  948K   98M   1% /run
/dev/dm-0        98G   81G   13G  87% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            492M     0  492M   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sda1       236M   40M  184M  18% /boot

2. ボリュームグループ(物理/論理)の情報を取得

admin@Ubuntu-SV-1404:~$ sudo vgdisplay -v

  • ボリュームグループ名を控えておくこと(参照その1)
  • 論理パス名を控えておくこと(参照その2)
    Finding all volume groups
    Finding volume group "Ubuntu-SV-1404-vg"        "【参照 その1】"
  --- Volume group ---
  VG Name               Ubuntu-SV-1404-vg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               149.76 GiB
  PE Size               4.00 MiB
  Total PE              38338
  Alloc PE / Size       38338 / 149.76 GiB
  Free  PE / Size       0 / 0
  VG UUID               RIfIUw-aftq-bBSe-xayv-AGEg-Ka2z-48rwwN

  --- Logical volume ---
  LV Path                /dev/Ubuntu-SV-1404-vg/root "【参照 その2】"
  LV Name                root
  VG Name                Ubuntu-SV-1404-vg
  LV UUID                pL9YCI-VF7l-1eBG-kMCM-EdO3-3jDK-GDMgv3
  LV Write Access        read/write
  LV Creation host, time Ubuntu-SV-1404, 2017-04-22 09:01:34 +0900
  LV Status              available
  # open                 1
  LV Size                148.76 GiB
  Current LE             38083
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

〜後略〜

3. fdiskを実行

admin@Ubuntu-SV-1404:~$ sudo fdisk /dev/sda

4. パーティション情報を表示

Command (m for help): p

Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 cylinders, total 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00038162

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758   209713151   104605697    5  Extended
/dev/sda5          501760   209713151   104605696   8e  Linux LVM

5. パーティションの新規追加

Command (m for help): n

Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)

6. プライマリパーティションを追加

Select (default p): p

7. パーテイション番号を設定

Partition number (1-4, default 3):

  • 基本デフォルトでOK

8. 開始セクタを設定

First sector (499712-314572799, default 499712): 209713152

  • この時、3.で取得したパーティション情報の/dev/sda5 の最終セクタ(209713151) + 1から始める。

9. 終了セクタを設定

Last sector, +sectors or +size{K,M,G} (209713152-314572799, default 314572799):

  • 指定がなければ、デフォルトで一番最後が指定される。必要であれば指定すること。

10. パーティション情報を表示

  • 5 〜 9 で作成した、パーティションが作られていることを確認する
  • 新しく作成したパーティションのデバイス名を控えておくこと(参照その3)

Command (m for help): p

Disk /dev/sda: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 cylinders, total 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00038162

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758   209713151   104605697    5  Extended
/dev/sda3       209713152   314572799    52429824   83  Linux    "参照その3"
/dev/sda5          501760   209713151   104605696   8e  Linux LVM

11. パーティション情報を保存する。

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.

12. ボリュームグループに新しく作成したパーティションを追加する

  • Ubuntu-SV-1404-vg の部分は、2. の【参照その1】に置き換えること
  • /dev/sda3 の部分は、10.の【参照その3】に置き換えること

admin@Ubuntu-SV-1404:~$ sudo vgextend Ubuntu-SV-1404-vg /dev/sda3

Volume group "Ubuntu-SV-1404-vg" successfully extended

13. 論理ボリュームにボリュームグループの未使用領域を追加する

admin@Ubuntu-SV-1404:~$ sudo lvextend -l +100%FREE /dev/Ubuntu-SV-1404-vg/root

Extending logical volume root to 148.76 GiB
  Logical volume root successfully resized

14. ファイルシステムの拡張を行う

  • /dev/Ubuntu-SV-1404-vg/root の部分は、2. の【参照その2】に置き換えること

admin@Ubuntu-SV-1404:~$ sudo resize2fs /dev/Ubuntu-SV-1404-vg/root

resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/Ubuntu-SV-1404-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 10
The filesystem on /dev/Ubuntu-SV-1404-vg/root is now 38996992 blocks long.

15. LVMの領域が拡張されていることを確認する。

admin@Ubuntu-SV-1404:~$ df -h

Filesystem      Size  Used Avail Use% Mounted on
udev            481M  4.0K  481M   1% /dev
tmpfs            99M  952K   98M   1% /run
/dev/dm-0       147G   81G   60G  58% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            492M     0  492M   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sda1       236M   40M  184M  18% /boot