IDCFでLVM(論理ボリューム)を作成してディスク拡張する方法

イヌガジェ
イヌガジェ

どうも、イヌガジェです。

今回はIDCFでLVMの作成から、拡張までする方法を最近学んだので
忘れないように記事にしていこうと思います!

同じ事で悩まれている方がいたら是非参考にしてください!

LVMとは

その前にLVMについて軽く説明していきます。

LVM(logical volume manager)とは、複数のハードディスクやパーティションにまたがった記憶領域をひとつのボリュームグループにまとめ、単一の論理ボリューム(LV)として扱うことのできるディスク管理機能です。

まあ簡単に説明すると、複数の物理ボリュームをがっちゃんこして1つの物理ディスクを超える巨大な論理ボリュームとして利用できて、自由度の高い設定ができるんですね。

また、システムを停止せずに論理ボリュームの動的拡大・縮小や、物理的なディスクの追加作業も行えるなど運用面において利点もあります。

引用:https://www.idcf.jp/words/lvm.html

イヌガジェ
イヌガジェ

いいね、LVM

ということで、早速LVMの作成をしていきましょう!

環境は以下の通り
クラウド:IDCF
OS:CentOS8
※本情報は2023/12/09時点の情報です

LVMの作成方法

まずはデバイスのスキャンとパーテションの確認

[root@inu-test01 ~]# lsscsi
[root@inu-test01 ~]# echo 1 > /sys/class/scsi_disk/0\:0\:1\:0/device/rescan

[root@inu-test01 ~]#fdisk -l
Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x0001e150
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 31457279 15727616 83 Linux
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf2d567a5
デバイス ブート 始点 終点 ブロック Id システム

[root@inu-test01 ~]#fdisk -l /dev/sdb
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf2d567a5
デバイス ブート 始点 終点 ブロック Id システム

続いて、fdiskを用いて /dev/sbd をLVM形式にフォーマットしていきます

対話形式で進むので以下の順番で回答します。

n→p→1→ Enter押下→Enter押下→t→1→L→8e→w

[root@inu-test01 ~]# 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.
コマンド (m でヘルプ): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
パーティション番号 (1-4, default 1): 1
最初 sector (2048-10485759, 初期値 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, 初期値 10485759): 10485759
Partition 1 of type Linux and of size 5 GiB is set
コマンド (m でヘルプ): t
Selected partition 1
Hex code (type L to list all codes): 1
Changed type of partition 'Linux' to 'FAT12'
コマンド (m でヘルプ): L
0 空 24 NEC DOS 81 Minix / 古い Li bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux スワップ c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 隠し C: ド c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux 拡張領域 c7 Syrinx
5 拡張領域 41 PPC PReP Boot 86 NTFS ボリューム da 非 FS データ
6 FAT16 42 SFS 87 NTFS ボリューム db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux プレーン de Dell ユーティリ
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX ブート可能 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 ブートマネ 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad ハ eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 拡張領域 (L 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC
11 隠し FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq 診断 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 隠し FAT16 <32M 61 SpeedStor ab Darwin ブート f2 DOS セカンダリ
16 隠し FAT16 63 GNU HURD または af HFS / HFS+ fb VMware VMFS
17 隠し HPFS/NTFS 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI スワップ fd Linux raid 自動
1b 隠し W95 FAT32 70 DiskSecure Mult bb 隠し Boot Wizar fe LANstep
1c 隠し W95 FAT32 75 PC/IX be Solaris ブート ff BBT
1e 隠し W95 FAT16 80 古い Minix
コマンド (m でヘルプ): 8e
8: 不明なコマンド
コマンドの動作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
コマンド (m でヘルプ): w
パーティションテーブルは変更されました!
ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。
[root@inu-test01 ~]#fdisk -l /dev/sdb
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xf2d567a5
デバイス ブート 始点 終点 ブロック Id システム
/dev/sdb1 2048 10485759 5241856 1 FAT12

続いて、/dev/sbd1 をPV(Physical volume)として登録します

[root@inu-test01 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@inu-test01 ~]# pvdisplay
"/dev/sdb1" is a new physical volume of "<5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 6qKnBi-CyZ2-Zpw6-gVjp-6vfw-TDMP-bUHCrD

Volume Group(VG)の作成と確認

[root@inu-test01 ~]# vgcreate VG01 /dev/sdb1
Volume group "VG01" successfully created

[root@inu-test01 ~]# vgdisplay
--- Volume group ---
VG Name VG01
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 <5.00 GiB
PE Size 4.00 MiB
Total PE 1279
Alloc PE / Size 0 / 0
Free PE / Size 1279 / <5.00 GiB
VG UUID cXxvBy-l0kR-pbx8-iAfz-bMfb-KZQZ-PhPULm

Logical Volume(LV)の作成と確認

[root@inu-test01 ~]# lvcreate -l 100%FREE -n LV01 VG01
Logical volume "LV01" created.
[root@inu-test01 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/VG01/LV01
LV Name LV01
VG Name VG01
LV UUID CcMW3n-QvRg-j5gR-aZhg-1jxM-9iUM-zUCbhC
LV Write Access read/write
LV Creation host, time inu-test01, 2023-11-21 11:42:59 +0900
LV Status available
# open 0
LV Size <5.00 GiB
Current LE 1279
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

続いて、LV上にファイルシステムを作成していきます

[root@inu-test01 ~]# mkfs.ext4 /dev/VG01/LV01
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1309696 blocks
65484 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

マウントポイント用ディレクトリの作成からのマウント

[root@inu-test01 ~]# mkdir /mnt/lvext
[root@inu-test01 ~]# mount /dev/VG01/LV01 /mnt/lvext

[root@inu-test01 ~]# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 1.5M 485M 1% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 15G 1.6G 14G 11% /
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/VG01-LV01 4.8G 20M 4.6G 1% /mnt/lvext ☆こいつがいればOK

これでできました!!
結構簡単でいいですね!

イヌガジェ
イヌガジェ

続いて、ボリュームを追加してLVMの拡張をしていきます

LVMの拡張

IDCF上でコンピュート > ボリューム > ボリューム作成 して、
対象の仮想マシンへアタッチします。

続いて、ディスクをスキャンさせて確認

[root@inu-test01 ~]# lsscsi | grep /dev/
[0:0:0:0] disk VMware Virtual disk 2.0 /dev/sda
[0:0:1:0] disk VMware Virtual disk 2.0 /dev/sdb
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR00 1.00 /dev/sr0
[root@inu-test01 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan

[root@inu-test01 ~]# lsscsi | grep /dev/
[0:0:0:0] disk VMware Virtual disk 2.0 /dev/sda
[0:0:1:0] disk VMware Virtual disk 2.0 /dev/sdb
[0:0:2:0] disk VMware Virtual disk 2.0 /dev/sdc
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR00 1.00 /dev/sr0

パーティションの作成をしていきます
対話形式で進むので以下の順番で回答します。

n→p→1→ Enter押下→Enter押下→t→1→8e→p→w

[root@inu-test01 ~]# fdisk /dev/sdc
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xacd5ac2b.
コマンド (m でヘルプ): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
パーティション番号 (1-4, default 1): 1
最初 sector (2048-20971519, 初期値 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, 初期値 20971519): 20971519
Partition 1 of type Linux and of size 10 GiB is set
コマンド (m でヘルプ): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
コマンド (m でヘルプ): p
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xacd5ac2b
デバイス ブート 始点 終点 ブロック Id システム
/dev/sdc1 2048 20971519 10484736 8e Linux LVM
コマンド (m でヘルプ): w
パーティションテーブルは変更されました!
ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。

[root@inu-test01 ~]# fdisk -l /dev/sdc
Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xacd5ac2b
デバイス ブート 始点 終点 ブロック Id システム
/dev/sdc1 2048 20971519 10484736 8e Linux LVM

ちゃんと作成されてますね。
次は/dev/sbc1 をPVとして登録します。

[root@inu-test01 ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.

では、既存のボリュームグループに追加した物理ボリュームを追加します。

[root@inu-test01 ~]# vgextend VG01 /dev/sdc1
Volume group "VG01" successfully extended

そのまま既存の論理ボリュームを拡張します!

[root@inu-test01 ~]# lvextend -l +100%FREE /dev/VG01/LV01
Size of logical volume VG01/LV01 changed from <5.00 GiB (1279 extents) to 14.99 GiB (3838 e
Logical volume VG01/LV01 successfully resized.

最後にファイルシステムを拡張し、これで拡張分の容量が使えるようになります!

[root@inu-test01 ~]# resize2fs /dev/VG01/LV01
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/VG01/LV01 is mounted on /mnt/lvext; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/VG01/LV01 is now 3930112 blocks long.

[root@inu-test01 ~]# df -h
ファイルシス サイズ 使用 残り 使用% マウント位置
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 1.5M 485M 1% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 15G 1.6G 14G 11% /
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/VG01-LV01 15G 25M 14G 1% /mnt/lvext   ☆これで容量が拡張されています!

以上になります!
かなり流れで作成したので分かりづらい部分あったかもですが参考になれば幸いです!!
参考にした記事:https://blog.idcf.jp/entry/cloud/diskcapacity/

イヌガジェ
イヌガジェ

あまり触った事なかった技術だから勉強になったな~

では、よいクリスマスを~

 

コメント

タイトルとURLをコピーしました