【fdisk】LVM 環境を構築した後に拡張してみる【備忘録】

こんにちは。
fdisk にあまり馴染みがなかったので、勉強がてら LVM 構築/拡張の検証をしてみました。

1.環境

ラズパイに USB メモリを 2 つアタッチして LVM 環境を構築します。
※ 最初は 1 つの USB メモリで LVM を構築、2 つ目で拡張を行います。

[root@sanuki-raspi-wd01 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb           8:16   1 29.7G  0 disk
sda           8:0    1 14.5G  0 disk
mmcblk0     179:0    0 29.4G  0 disk
|-mmcblk0p2 179:2    0  488M  0 part [SWAP]
|-mmcblk0p3 179:3    0 28.7G  0 part /
`-mmcblk0p1 179:1    0  286M  0 part /boot

2.LVM構築

1 つめの USB メモリにパーティションを切って LVM を構築ます。

## LVM のパーティションを作成

[root@sanuki-raspi-wd01 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-30310399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-30310399, default 30310399):
Using default value 30310399
Partition 1 of type Linux and of size 14.5 GiB is set

Command (m for help): p

Disk /dev/sda: 15.5 GB, 15518924800 bytes, 30310400 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 label type: dos
Disk identifier: 0x8f5acbf5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    30310399    15154176   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sda: 15.5 GB, 15518924800 bytes, 30310400 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 label type: dos
Disk identifier: 0x8f5acbf5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    30310399    15154176   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

## パーティションの確認

[root@sanuki-raspi-wd01 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb           8:16   1 29.7G  0 disk
sda           8:0    1 14.5G  0 disk
`-sda1        8:1    1 14.5G  0 part
mmcblk0     179:0    0 29.4G  0 disk
|-mmcblk0p2 179:2    0  488M  0 part [SWAP]
|-mmcblk0p3 179:3    0 28.7G  0 part /
`-mmcblk0p1 179:1    0  286M  0 part /boot

## 物理ボリューム作成

[root@sanuki-raspi-wd01 ~]# pvcreate /dev/sda1
  Physical volume "/dev/sda1" successfully created.
[root@sanuki-raspi-wd01 ~]# pvdisplay
  "/dev/sda1" is a new physical volume of "14.45 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda1
  VG Name
  PV Size               14.45 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               bmKMbk-xiag-DHqv-J2N8-AAUA-plbr-yMOJgQ

## ボリュームグループ(testvg01)作成

[root@sanuki-raspi-wd01 ~]# vgcreate testvg01 /dev/sda1
  Volume group "testvg01" successfully created
[root@sanuki-raspi-wd01 ~]# vgdisplay
  --- Volume group ---
  VG Name               testvg01
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <14.45 GiB
  PE Size               4.00 MiB
  Total PE              3699
  Alloc PE / Size       0 / 0
  Free  PE / Size       3699 / <14.45 GiB
  VG UUID               D98n40-QSB4-CLFX-G8gl-4GAV-8K9K-ncMLJX


## 論理ボリューム(testlv01)作成

[root@sanuki-raspi-wd01 ~]# lvcreate -n testlv01 -l 100%FREE testvg01
  Logical volume "testlv01" created.
[root@sanuki-raspi-wd01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg01/testlv01
  LV Name                testlv01
  VG Name                testvg01
  LV UUID                81F6gu-v9lD-K36o-mf0o-15dX-D6wj-UFcRbC
  LV Write Access        read/write
  LV Creation host, time sanuki-raspi-wd01, 2020-10-05 08:26:25 +0900
  LV Status              available
  # open                 0
  LV Size                <14.45 GiB
  Current LE             3699
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

## 論理ボリュームにファイルシステム作成

[root@sanuki-raspi-wd01 ~]# mkfs -t xfs /dev/testvg01/testlv01
meta-data=/dev/testvg01/testlv01 isize=512    agcount=4, agsize=946944 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=3787776, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

## /mnt/HDDにマウント

[root@sanuki-raspi-wd01 ~]# mkdir /mnt/HDD
[root@sanuki-raspi-wd01 ~]# mount -t xfs /dev/testvg01/testlv01 /mnt/HDD/
[root@sanuki-raspi-wd01 ~]# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb                     8:16   1 29.7G  0 disk
sda                     8:0    1 14.5G  0 disk
`-sda1                  8:1    1 14.5G  0 part
  `-testvg01-testlv01 254:0    0 14.5G  0 lvm  /mnt/HDD
mmcblk0               179:0    0 29.4G  0 disk
|-mmcblk0p2           179:2    0  488M  0 part [SWAP]
|-mmcblk0p3           179:3    0 28.7G  0 part /
`-mmcblk0p1           179:1    0  286M  0 part /boot
[root@sanuki-raspi-wd01 ~]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/root                       29G  1.4G   27G   5% /
devtmpfs                       430M     0  430M   0% /dev
tmpfs                          463M     0  463M   0% /dev/shm
tmpfs                          463M   12M  451M   3% /run
tmpfs                          463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1                 286M   55M  231M  20% /boot
tmpfs                           93M     0   93M   0% /run/user/0
/dev/mapper/testvg01-testlv01   15G   33M   15G   1% /mnt/HDD

3.LVM 拡張

ここから 2 つめの USB メモリで LVM を拡張してみます。

## パーティション作成

[root@sanuki-raspi-wd01 ~]# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb                     8:16   1 29.7G  0 disk
sda                     8:0    1 14.5G  0 disk
`-sda1                  8:1    1 14.5G  0 part
  `-testvg01-testlv01 254:0    0 14.5G  0 lvm  /mnt/HDD
mmcblk0               179:0    0 29.4G  0 disk
|-mmcblk0p2           179:2    0  488M  0 part [SWAP]
|-mmcblk0p3           179:3    0 28.7G  0 part /
`-mmcblk0p1           179:1    0  286M  0 part /boot
[root@sanuki-raspi-wd01 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-62333951, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-62333951, default 62333951):
Using default value 62333951
Partition 1 of type Linux and of size 29.7 GiB is set

Command (m for help): p

Disk /dev/sdb: 31.9 GB, 31914983424 bytes, 62333952 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 label type: dos
Disk identifier: 0x1a15259c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    62333951    31165952   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 31.9 GB, 31914983424 bytes, 62333952 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 label type: dos
Disk identifier: 0x1a15259c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    62333951    31165952   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@sanuki-raspi-wd01 ~]# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb                     8:16   1 29.7G  0 disk
`-sdb1                  8:17   1 29.7G  0 part
sda                     8:0    1 14.5G  0 disk
`-sda1                  8:1    1 14.5G  0 part
  `-testvg01-testlv01 254:0    0 14.5G  0 lvm  /mnt/HDD
mmcblk0               179:0    0 29.4G  0 disk
|-mmcblk0p2           179:2    0  488M  0 part [SWAP]
|-mmcblk0p3           179:3    0 28.7G  0 part /
`-mmcblk0p1           179:1    0  286M  0 part /boot

## 物理ボリューム作成

[root@sanuki-raspi-wd01 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@sanuki-raspi-wd01 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               testvg01
  PV Size               14.45 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3699
  Free PE               0
  Allocated PE          3699
  PV UUID               bmKMbk-xiag-DHqv-J2N8-AAUA-plbr-yMOJgQ

  "/dev/sdb1" is a new physical volume of "29.72 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               29.72 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               0Gn20F-PrwI-KZj4-9ocS-K1Pz-QoBV-AMOVV3


  
## ボリュームグループ(testvg01)の拡張

[root@sanuki-raspi-wd01 ~]# vgdisplay
  --- Volume group ---
  VG Name               testvg01
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <14.45 GiB
  PE Size               4.00 MiB
  Total PE              3699
  Alloc PE / Size       3699 / <14.45 GiB
  Free  PE / Size       0 / 0
  VG UUID               D98n40-QSB4-CLFX-G8gl-4GAV-8K9K-ncMLJX
[root@sanuki-raspi-wd01 ~]# vgextend testvg01 /dev/sdb1
  Volume group "testvg01" successfully extended
[root@sanuki-raspi-wd01 ~]# vgdisplay
  --- Volume group ---
  VG Name               testvg01
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <44.17 GiB
  PE Size               4.00 MiB
  Total PE              11307
  Alloc PE / Size       3699 / <14.45 GiB
  Free  PE / Size       7608 / <29.72 GiB
  VG UUID               D98n40-QSB4-CLFX-G8gl-4GAV-8K9K-ncMLJX
  
## 論理ボリューム(testlv01)の拡張

[root@sanuki-raspi-wd01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg01/testlv01
  LV Name                testlv01
  VG Name                testvg01
  LV UUID                81F6gu-v9lD-K36o-mf0o-15dX-D6wj-UFcRbC
  LV Write Access        read/write
  LV Creation host, time sanuki-raspi-wd01, 2020-10-05 08:26:25 +0900
  LV Status              available
  # open                 1
  LV Size                <14.45 GiB
  Current LE             3699
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

[root@sanuki-raspi-wd01 ~]# lvextend -l +100%FREE /dev/testvg01/testlv01
  Size of logical volume testvg01/testlv01 changed from <14.45 GiB (3699 extents) to <44.17 GiB (11307 extents).
  Logical volume testvg01/testlv01 successfully resized.
[root@sanuki-raspi-wd01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg01/testlv01
  LV Name                testlv01
  VG Name                testvg01
  LV UUID                81F6gu-v9lD-K36o-mf0o-15dX-D6wj-UFcRbC
  LV Write Access        read/write
  LV Creation host, time sanuki-raspi-wd01, 2020-10-05 08:26:25 +0900
  LV Status              available
  # open                 1
  LV Size                <44.17 GiB
  Current LE             11307
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0
[root@sanuki-raspi-wd01 ~]# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb                     8:16   1 29.7G  0 disk
`-sdb1                  8:17   1 29.7G  0 part
  `-testvg01-testlv01 254:0    0 44.2G  0 lvm  /mnt/HDD
sda                     8:0    1 14.5G  0 disk
`-sda1                  8:1    1 14.5G  0 part
  `-testvg01-testlv01 254:0    0 44.2G  0 lvm  /mnt/HDD
mmcblk0               179:0    0 29.4G  0 disk
|-mmcblk0p2           179:2    0  488M  0 part [SWAP]
|-mmcblk0p3           179:3    0 28.7G  0 part /
`-mmcblk0p1           179:1    0  286M  0 part /boot

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

[root@sanuki-raspi-wd01 ~]# xfs_growfs /dev/testvg01/testlv01
meta-data=/dev/mapper/testvg01-testlv01 isize=512    agcount=4, agsize=946944 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3787776, 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 3787776 to 11578368
[root@sanuki-raspi-wd01 ~]# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/root                       29G  1.4G   27G   5% /
devtmpfs                       430M     0  430M   0% /dev
tmpfs                          463M     0  463M   0% /dev/shm
tmpfs                          463M   12M  451M   3% /run
tmpfs                          463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1                 286M   55M  231M  20% /boot
tmpfs                           93M     0   93M   0% /run/user/0
/dev/mapper/testvg01-testlv01   45G   33M   45G   1% /mnt/HDD

ストレージ周りは怖いのであんまり触りたくないですね。

投稿者: snk

保有資格 ・TOEIC 835 ・LPIC 304 ・AWS SAA/SAP ・GCP PCA ・IPA SC

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です