LVMとかパーティションとか概念図


すまん、絵だけなんだ。。

「いや違うぜ」があったときにコメント残していただけると、私も、また次ココにたどり着いた人にも優しいのでおねしゃす。

LV(論理ボリューム)を拡張した

$ df -hP | egrep 'ファイル|VolGroup'
ファイルシス                   サイズ  使用  残り 使用% マウント位置
/dev/mapper/VolGroup01-lv_root    20G   12G  8.8G   57% /
/dev/mapper/VolGroup01-lv_log     20G  104M   20G    1% /var/log
/dev/mapper/VolGroup01-lv_home    20G   33M   20G    1% /home

lv_root が足りなくなったのでサイズ拡張した記録。

$ sudo lvextend -L+100G /dev/VolGroup01/lv_root
  Insufficient free space: 25600 extents needed, but only 0 available

何も考えずに lvextend で +100G 使用としたら怒られた。
VolGroup01 に空き容量が足りないとのこと。

$ sudo vgdisplay VolGroup01
  --- Volume group ---
  VG Name               VolGroup01
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               70.00 GiB
  PE Size               4.00 MiB
  Total PE              17920
  Alloc PE / Size       17920 / 70.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               IuxwAp-c9aL-Twkj-DR56-PLJa-rVML-v0BGse

VG Size が 70.00 GiBしかない。
先にこっちを拡張する必要があるようだ。

$ sudo gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 11715870720 sectors, 5.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): A26D1B0D-6373-488E-80B1-6AC958A6D78F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 11715870686
Partitions will be aligned on 2048-sector boundaries
Total free space is 11568011197 sectors (5.4 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1052671   512.0 MiB   0700
   3         1052672       147861503   70.0 GiB    8E00

パーティション Number 3Code 8E00 = Linux LVM なのでこいつを拡張したい。
しかしすでに作成済みのパーティションを削除>拡張するのは怖いので、新たに作成して追加することにした。

$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help):

まずは現在の状態を表示

Command (? for help): p ★現在の状態を表示
Disk /dev/sda: 11715870720 sectors, 5.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): A26D1B0D-6373-488E-80B1-6AC958A6D78F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 11715870686
Partitions will be aligned on 2048-sector boundaries
Total free space is 11568011197 sectors (5.4 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1052671   512.0 MiB   0700
   3         1052672       147861503   70.0 GiB    8E00

次に新しいパーティションを作成

Command (? for help): n ★パーティション作成
Partition number (4-128, default 4):  ★Numberはデフォルトの「4」なのでそのままEnter
First sector (34-11715870686, default = 147861504) or {+-}size{KMGTP}: ★開始位置もデフォ。Enter。
Last sector (147861504-11715870686, default = 11715870686) or {+-}size{KMGTP}: +200G ★200GBを指定
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8E00  ★Linux LVM を示す 8E00 を指定
Changed type of partition to 'Linux LVM'

作成したパーティションを確認

Command (? for help): p ★確認
Disk /dev/sda: 11715870720 sectors, 5.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): A26D1B0D-6373-488E-80B1-6AC958A6D78F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 11715870686
Partitions will be aligned on 2048-sector boundaries
Total free space is 11148580797 sectors (5.2 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1052671   512.0 MiB   0700
   3         1052672       147861503   70.0 GiB    8E00
   4       147861504       567291903   200.0 GiB   8E00  Linux LVM

書き込む

Command (? for help): w ★書き込む

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y ★「Y」を指定
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

カーネルはまだ古いパーティションテーブルを使用している。
新しいパーティションテーブルは再起動後に有効になるらしい。

$ ls -l /dev/sda*
brw-rw---- 1 root disk 8, 0 12月  6 15:33 /dev/sda
brw-rw---- 1 root disk 8, 1 12月  6 15:33 /dev/sda1
brw-rw---- 1 root disk 8, 2 12月  6 15:33 /dev/sda2
brw-rw---- 1 root disk 8, 3 12月  6 15:33 /dev/sda3

確かにまだない。
pvcreate でそのまま作れたりしないかな。

$ sudo pvcreate /dev/sda4
  Device /dev/sda4 not found.
$ sudo pvcreate /dev/sda
  Device /dev/sda excluded by a filter.

駄目らしい。うーん、/ と同じデバイスに作ってしまったからかな。
だったらいっそ、めちゃくちゃでかいサイズにしておくか。

$ sudo gdisk /dev/sda  ★編集開始
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p  ★編集前を表示
Disk /dev/sda: 11715870720 sectors, 5.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): A26D1B0D-6373-488E-80B1-6AC958A6D78F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 11715870686
Partitions will be aligned on 2048-sector boundaries
Total free space is 11148580797 sectors (5.2 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1052671   512.0 MiB   0700
   3         1052672       147861503   70.0 GiB    8E00
   4       147861504       567291903   200.0 GiB   8E00  Linux LVM

Command (? for help): d  ★削除
Partition number (1-4): 4  ★Number 4を削除

Command (? for help): p  ★削除後を表示
Disk /dev/sda: 11715870720 sectors, 5.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): A26D1B0D-6373-488E-80B1-6AC958A6D78F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 11715870686
Partitions will be aligned on 2048-sector boundaries
Total free space is 11568011197 sectors (5.4 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1052671   512.0 MiB   0700
   3         1052672       147861503   70.0 GiB    8E00

Command (? for help): n  ★新規作成
Partition number (4-128, default 4): 4  ★Number 4を作成
First sector (34-11715870686, default = 147861504) or {+-}size{KMGTP}:  ★そのままEnter
Last sector (147861504-11715870686, default = 11715870686) or {+-}size{KMGTP}:  ★そのままEnter
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8E00  ★Linux LVM
Changed type of partition to 'Linux LVM'

Command (? for help): p  ★編集後を表示
Disk /dev/sda: 11715870720 sectors, 5.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): A26D1B0D-6373-488E-80B1-6AC958A6D78F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 11715870686
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1052671   512.0 MiB   0700
   3         1052672       147861503   70.0 GiB    8E00
   4       147861504     11715870686   5.4 TiB     8E00  Linux LVM

Command (? for help): w  ★書込

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y  ★おっけー
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

$ sudo gdisk -l /dev/sda  ★確認
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 11715870720 sectors, 5.5 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): A26D1B0D-6373-488E-80B1-6AC958A6D78F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 11715870686
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            4095   1024.0 KiB  EF02
   2            4096         1052671   512.0 MiB   0700
   3         1052672       147861503   70.0 GiB    8E00
   4       147861504     11715870686   5.4 TiB     8E00  Linux LVM

一度サーバを再起動

$ sudo shutdown -r now

再起動後に再確認

$ ls -l /dev/sda*
brw-rw---- 1 root disk 8, 0 12月  6 16:02 /dev/sda
brw-rw---- 1 root disk 8, 1 12月  6 16:02 /dev/sda1
brw-rw---- 1 root disk 8, 2 12月  6 16:02 /dev/sda2
brw-rw---- 1 root disk 8, 3 12月  6 16:02 /dev/sda3
brw-rw---- 1 root disk 8, 4 12月  6 16:02 /dev/sda4

認識されている。これをVGに追加する。

$ sudo vgextend VolGroup01 /dev/sda4
  Physical volume "/dev/sda4" successfully created.
  Volume group "VolGroup01" successfully extended

確認

$ sudo vgdisplay VolGroup01
  --- Volume group ---
  VG Name               VolGroup01
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <5.46 TiB
  PE Size               4.00 MiB
  Total PE              1430030
  Alloc PE / Size       17920 / 70.00 GiB
  Free  PE / Size       1412110 / <5.39 TiB
  VG UUID               IuxwAp-c9aL-Twkj-DR56-PLJa-rVML-v0BGse

VG Size が増えた!
改めて lv_root のサイズを拡張する。

$ sudo lvextend -L+100G /dev/VolGroup01/lv_root
  Size of logical volume VolGroup01/lv_root changed from 20.00 GiB (5120 extents) to 120.00 GiB (30720 extents).
  Logical volume VolGroup01/lv_root successfully resized.
$ sudo lvextend -L+100G /dev/VolGroup01/lv_root
  Size of logical volume VolGroup01/lv_root changed from 120.00 GiB (30720 extents) to 220.00 GiB (56320 extents).
  Logical volume VolGroup01/lv_root successfully resized.

200 GiB 増やそうと思ったのに間違えて 100 GiB を指定したので2回実行した。

$ df -hP | egrep 'ファイル|VolGr'
ファイルシス                   サイズ  使用  残り 使用% マウント位置
/dev/mapper/VolGroup01-lv_root    20G   12G  8.8G   57% /
/dev/mapper/VolGroup01-lv_home    20G   33M   20G    1% /home
/dev/mapper/VolGroup01-lv_log     20G  100M   20G    1% /var/log

まだ認識されていない。ファイルシステムを拡張する必要がある。
lv_rootxfs で作っているので resize2fs ではなく xfs_growfs を使う。

$ sudo xfs_growfs /dev/VolGroup01/lv_root
meta-data=/dev/mapper/VolGroup01-lv_root isize=512    agcount=4, agsize=1310720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=5242880, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5242880 to 57671680

一瞬だったけど大丈夫なのかな。

$ df -hP | egrep 'ファイル|VolGr'
ファイルシス                   サイズ  使用  残り 使用% マウント位置
/dev/mapper/VolGroup01-lv_root   220G   12G  209G    6% /
/dev/mapper/VolGroup01-lv_home    20G   33M   20G    1% /home
/dev/mapper/VolGroup01-lv_log     20G  101M   20G    1% /var/log

お。できた!