※参考古賀先生のcentos8
CentOS8 実践ガイド [システム管理編]
なんのためにfdiskを実施するのか。
理由:OSが認識できるパーティションを作成するため。
パーティションを作成後に、LVM(Logical Volume Manager)管理する。
手順
0.ゲストOSを停止する。
0-1。ゲストOSにディスクを追加する
または
0-1 ゲストOSの既存ディスクサイズを増やす。
今回は、既存ディスクサイズ変更で実施しました。
1.fdiskでデバイスの情報を取得する。
fdisk -l デバイス名(/dev/sdaX)
ディスクが30GB→50GBに増えていることを確認。
fdisk -l /dev/sda
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
2.fdiskを行う。今回追加されるのは「/dev/sda3」
n add a new partition
p print the partition table
t change a partition's system id
w write table to disk and exit
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.
コマンド (m でヘルプ): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
パーティション番号 (3,4, default 3):
最初 sector (62914560-104857599, 初期値 62914560):
初期値 62914560 を使います
Last sector, +sectors or +size{K,M,G} (62914560-104857599, 初期値 104857599):
初期値 104857599 を使います
Partition 3 of type Linux and of size 20 GiB is set
コマンド (m でヘルプ): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ae6d1
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 62914559 30407680 8e Linux LVM
/dev/sda3 62914560 104857599 20971520 83 Linux
コマンド (m でヘルプ): t
パーティション番号 (1-3, default 3):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
コマンド (m でヘルプ): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ae6d1
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 62914559 30407680 8e Linux LVM
/dev/sda3 62914560 104857599 20971520 8e Linux LVM
コマンド (m でヘルプ): w
パーティションテーブルは変更されました!
ioctl() を呼び出してパーティションテーブルを再読込みします。
WARNING: Re-reading the partition table failed with error 16: デバイスもしくはリソースがビジー状態です.
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)
ディスクを同期しています。
3.fdiskの設定確認を行う。
fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ae6d1
デバイス ブート 始点 終点 ブロック Id システム
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 62914559 30407680 8e Linux LVM
/dev/sda3 62914560 104857599 20971520 8e Linux LVM
Disk /dev/mapper/vg001-system: 27.9 GB, 27908898816 bytes, 54509568 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk /dev/mapper/vg001-swap: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
4.現在の物理ボリューム情報を取得する。
pvdisplay
pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg001
PV Size <29.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 7423
Free PE 1
Allocated PE 7422
PV UUID qQ1CeJ-9ulz-VqO8-qSno-lXsf-ig4b-Ilkf7o
5.物理ボリュームに先ほど追加したデバイスを追加する。
※createっていうけど、デバイスを登録するイメージに近い。
※以下のコマンド失敗。。。。
※OS再起動が必要でした。。。。
※fdiskからは見えるがLVM側からは認識できない。
pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
6.物理ボリューム一覧を表示する ※追加されたこと確認
[root@redhat ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg001
PV Size <29.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 7423
Free PE 1
Allocated PE 7422
PV UUID qQ1CeJ-9ulz-VqO8-qSno-lXsf-ig4b-Ilkf7o
"/dev/sda3" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID W2MHA4-Ndpf-thlp-xWh9-B5li-563U-4kBzrm
7.今回は、既存のvgにディスクを追加する。
vgdisplay
--- Volume group ---
VG Name vg001
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <29.00 GiB
PE Size 4.00 MiB
Total PE 7423
Alloc PE / Size 7422 / 28.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID parUDn-nSC2-cUs7-dgaj-I2oA-pYAW-30Y4Vg
既存のボリュームグループがvg001なのでそれに先ほどpvcrateしたデバイス「/dev/sda3」を追加する。
vgextend vg001 /dev/sda3
Volume group "vg001" successfully extended
lvdisplayで
※LV NAME変な名前にしてすいません。
lvdisplay
--- Logical volume ---
LV Path /dev/vg001/system
LV Name system
VG Name vg001
LV UUID Hvjad0-ZyxR-zPB9-HAvL-jcFQ-Sx6E-B5Bo9T
LV Write Access read/write
LV Creation host, time localhost, 2021-11-30 01:41:10 +0900
LV Status available
# open 1
LV Size 25.99 GiB
Current LE 6654
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/vg001/swap
LV Name swap
VG Name vg001
LV UUID mGV0k1-NvUF-Y5nH-rDV2-ocpC-0BN6-03UToQ
LV Write Access read/write
LV Creation host, time localhost, 2021-11-30 01:41:11 +0900
LV Status available
# open 2
LV Size 3.00 GiB
Current LE 768
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
最後に
lvextend
lvextend -l +100%FREE /dev/vg001/system
Size of logical volume vg001/system changed from 25.99 GiB (6654 extents) to 45.99 GiB (11774 extents).
Logical volume vg001/system successfully resized.
vgdisplayで
Free PE / Size 0 / 0になったこと
vgdisplay
--- Volume group ---
VG Name vg001
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
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 48.99 GiB
PE Size 4.00 MiB
Total PE 12542
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 0 / 0
VG UUID parUDn-nSC2-cUs7-dgaj-I2oA-pYAW-30Y4Vg
lvdisplayでサイズが増えたことを確認する。
LV Size 45.99 GiB
lvdisplay
--- Logical volume ---
LV Path /dev/vg001/system
LV Name system
VG Name vg001
LV UUID Hvjad0-ZyxR-zPB9-HAvL-jcFQ-Sx6E-B5Bo9T
LV Write Access read/write
LV Creation host, time localhost, 2021-11-30 01:41:10 +0900
LV Status available
# open 1
LV Size 45.99 GiB
Current LE 11774
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
今回はファイルシステムがxfsなので
xfs_growfsコマンドを実行
xfs_growfs /dev/vg001/system
meta-data=/dev/mapper/vg001-system isize=512 agcount=4, agsize=1703424 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=6813696, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3327, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 6813696 to 12056576
# 拡張前
df -h
/dev/mapper/vg001-system 26G 3.8G 23G 15% /
# 拡張後
df -h
/dev/mapper/vg001-system 46G 3.8G 43G 9% /
増えていることを確認