OCI に作成した Oracle Linux で VNC をインストールすべく sudo dnf group install "Server with GUI" -y したところ、/boot領域(ファイルシステム)の容量が枯渇して OS が起動しなくなってしまいました。
という訳(?)で、本記事では OCI に作成した Oracle Linux の /boot領域(ファイルシステム)を拡張してみますやで。
彡(^)(^)
1. /boot領域(ファイルシステム)の拡張戦略
ちょっと大げさですが /boot領域(ファイルシステム)の拡張戦略を考えてみます。Compute に作成した Oracle Linux 8 のファイルシステムとパーティションは以下のように構成されています。
# dfコマンドの結果
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs tmpfs 7.7G 8.7M 7.7G 1% /run
tmpfs tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/ocivolume-root xfs 36G 9.7G 26G 28% /
/dev/sda2 xfs 1014M 356M 659M 36% /boot ★★ここを拡張したい
/dev/mapper/ocivolume-oled xfs 10G 122M 9.9G 2% /var/oled
/dev/sda1 vfat 100M 6.0M 94M 6% /boot/efi
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/987
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/1000
# fdiskコマンドの結果
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M EFI System
/dev/sda2 206848 2303999 2097152 1G Linux filesystem ★★ここが /boot のパーティション
/dev/sda3 2304000 97675263 95371264 45.5G Linux LVM ★★ここを Block Volume に一時的に退避する
上記の /dev/sda2(パーティション), /boot領域(ファイルシステム) を拡張したい訳ですが、LVM のパーティションの /dev/sda3 が邪魔で拡張できません。そのため /dev/sda3 を一時的に Attach した Block Volume に退避して、/dev/sda2 を拡張します。
2. 検証したOCI環境の構成
以下の環境で検証しています。
Compute ... VM.Standard.E4.Flex(1oCPU, 16GB Memory)
OS ... Oracle Linux 8.9
OS Image ... Oracle-Linux-8.9-2024.05.29-0
Boot Volume のサイズ ... 100GB
Block Volume(100GB)を Compute に Attach
またコマンド類は全てrootユーザーで実行するものとします。
3. ファイルシステムとマウントポイントの状況を確認
下記コマンドでファイルシステムとマウントポイントの状況を確認します。
df -Th
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs tmpfs 7.7G 8.7M 7.7G 1% /run
tmpfs tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/ocivolume-root xfs 36G 9.7G 26G 28% /
/dev/sda2 xfs 1014M 356M 659M 36% /boot ★ここを拡張したい
/dev/mapper/ocivolume-oled xfs 10G 122M 9.9G 2% /var/oled
/dev/sda1 vfat 100M 6.0M 94M 6% /boot/efi
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/987
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/1000
4. デバイスのパーティションの状況を確認
下記コマンドでデバイスのパーティション状況を確認します。
fdisk -l
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# fdisk -l
GPT PMBR size mismatch (97677311 != 209715199) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: 3A87099A-673A-4D5E-9C66-9D307A1A0FBF
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M EFI System
/dev/sda2 206848 2303999 2097152 1G Linux filesystem ★ここが /boot のパーティション
/dev/sda3 2304000 97675263 95371264 45.5G Linux LVM
Disk /dev/mapper/ocivolume-root: 35.5 GiB, 38088474624 bytes, 74391552 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk /dev/mapper/ocivolume-oled: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
[root@osaka-ayu-compute ~]#
5. Block Volume のデバイスにパーティションを作成
下記コマンドで Block Volume のデバイス /dev/sdb にパーティションを作成します。パーティションのサイズは退避する LVMパーティション(/dev/sda3) と同サイズ以上にする必要があります。
fdisk /dev/sdb
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x802edbc2.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): +50G
Created a new partition 1 of type 'Linux' and of size 50 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@osaka-ayu-compute ~]# ls -la /dev/sd*
brw-rw----. 1 root disk 8, 0 Jun 19 14:10 /dev/sda
brw-rw----. 1 root disk 8, 1 Jun 19 14:10 /dev/sda1
brw-rw----. 1 root disk 8, 2 Jun 19 14:10 /dev/sda2
brw-rw----. 1 root disk 8, 3 Jun 19 14:10 /dev/sda3
brw-rw----. 1 root disk 8, 16 Jun 19 14:17 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun 19 14:17 /dev/sdb1
[root@osaka-ayu-compute ~]#
6. LVM の 物理ボリュームを作成
下記コマンドで Block Volume のパーティションに LVM の物理ボリュームを作成します。
pvcreate /dev/sdb1
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@osaka-ayu-compute ~]#
7. LVM の Volume Group の情報を確認
下記コマンドで Volume Group の情報を確認します。
vgs
vgs --options +devices
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# vgs
VG #PV #LV #SN Attr VSize VFree
ocivolume 1 2 0 wz--n- 45.47g 0
[root@osaka-ayu-compute ~]# vgs --options +devices
VG #PV #LV #SN Attr VSize VFree Devices
ocivolume 1 2 0 wz--n- 45.47g 0 /dev/sda3(0)
ocivolume 1 2 0 wz--n- 45.47g 0 /dev/sda3(2560)
[root@osaka-ayu-compute ~]#
8. LVM の Volume Group に Block Volume のパーティションを追加
下記コマンドで Volume Group に Block Volume のパーティション /dev/sdb1 を追加します。
vgextend ocivolume /dev/sdb1
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# vgextend ocivolume /dev/sdb1
Volume group "ocivolume" successfully extended
9. Boot Volume のパーティションを Block Volumeパーティションに移行(コピー)
下記コマンドで Boot Volume のパーティション /dev/sda3 を Block Volumeパーティション /dev/sdb1 に移行(コピー)します。
pvmove /dev/sda3 /dev/sdb1
vgs --options +devices
実行結果は以下の通りです。Volume Group下のデバイスが /dev/sda3 → /dev/sdb1 に変わっています。
[root@osaka-ayu-compute ~]# pvmove /dev/sda3 /dev/sdb1
/dev/sda3: Moved: 0.03%
/dev/sda3: Moved: 1.74%
/dev/sda3: Moved: 3.26%
:
/dev/sda3: Moved: 97.65%
/dev/sda3: Moved: 99.16%
/dev/sda3: Moved: 100.00%
[root@osaka-ayu-compute ~]# vgs --options +devices
VG #PV #LV #SN Attr VSize VFree Devices
ocivolume 2 2 0 wz--n- <95.47g <50.00g /dev/sdb1(0)
ocivolume 2 2 0 wz--n- <95.47g <50.00g /dev/sdb1(2560)
10. LVM の Volume Group から Boot Volume のパーティションを削除
下記コマンドで LVM の Volume Group から Boot Volume のパーティション /dev/sda3 を削除します。
vgreduce ocivolume /dev/sda3
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# vgreduce ocivolume /dev/sda3
Removed "/dev/sda3" from volume group "ocivolume"
11. Boot Volume のパーティションを削除
下記コマンドで Boot Volume のパーティション /dev/sda3 を削除します。
fdisk /dev/sda
fdisk -l
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (97677311 != 209715199) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Command (m for help): p
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: 3A87099A-673A-4D5E-9C66-9D307A1A0FBF
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M EFI System
/dev/sda2 206848 2303999 2097152 1G Linux filesystem
/dev/sda3 2304000 97675263 95371264 45.5G Linux LVM
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 has been deleted.
Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@osaka-ayu-compute ~]# fdisk -l
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: 3A87099A-673A-4D5E-9C66-9D307A1A0FBF
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M EFI System
/dev/sda2 206848 2303999 2097152 1G Linux filesystem
Disk /dev/mapper/ocivolume-root: 35.5 GiB, 38088474624 bytes, 74391552 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk /dev/mapper/ocivolume-oled: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: dos
Disk identifier: 0x802edbc2
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 104859647 104857600 50G 83 Linux
[root@osaka-ayu-compute ~]#
12. partedコマンドで /boot のパーティションを拡張
下記コマンドで /boot のパーティション /dev/sda2 を拡張します。
parted /dev/sda
resizepart 2 5GiB
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart 2 5GiB
Warning: Partition /dev/sda2 is being used. Are you sure you want to continue?
Yes/No? Yes
(parted) print
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 106MB 105MB fat16 EFI System Partition boot, esp
2 106MB 5369MB 5263MB xfs
(parted) q
Information: You may need to update /etc/fstab.
13. xfs_growfsコマンドで /boot領域(ファイルシステム)を拡張
下記コマンドで /boot領域(ファイルシステム)を拡張します。今回の構成の /boot のファイルシステムは xfs なので xfs_growfsコマンドを使用します。
xfs_growfs /boot
df -Th
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# xfs_growfs /boot
meta-data=/dev/sda2 isize=512 agcount=4, agsize=65536 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=262144, 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=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 262144 to 1284864
[root@osaka-ayu-compute ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs tmpfs 7.7G 8.7M 7.7G 1% /run
tmpfs tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/ocivolume-root xfs 36G 9.7G 26G 28% /
/dev/sda2 xfs 4.9G 385M 4.6G 8% /boot
/dev/mapper/ocivolume-oled xfs 10G 154M 9.9G 2% /var/oled
/dev/sda1 vfat 100M 6.0M 94M 6% /boot/efi
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/987
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/1000
[root@osaka-ayu-compute ~]#
14. Boot Volume の拡張(オプション作業)
/boot領域を拡張した場合に Block Volume へ退避した情報を書き戻す領域が不足する可能性があります。不足する場合は Boot Volume を拡張します。ダイアログも出ますが拡張後に OS での rescan も忘れずに。
下記は rescan のコマンドのサンプルです。Boot Volume拡張後にダイアログに表示されるものを OS で実行して下さい。
sudo dd iflag=direct if=/dev/oracleoci/oraclevda of=/dev/null count=1
echo "1" | sudo tee /sys/class/block/`readlink /dev/oracleoci/oraclevda | cut -d'/' -f 2`/device/rescan
下記は実行結果のサンプルとなります。
[root@osaka-ayu-compute ~]# sudo dd iflag=direct if=/dev/oracleoci/oraclevda of=/dev/null count=1
1+0 records in
1+0 records out
512 bytes copied, 0.00154237 s, 332 kB/s
[root@osaka-ayu-compute ~]# echo "1" | sudo tee /sys/class/block/`readlink /dev/oracleoci/oraclevda | cut -d'/' -f 2`/device/rescan
1
[root@tokyo-datainteg001 ~]#
15. Boot Volume のデバイスにパーティションを再作成
下記コマンドで Boot Volume のデバイス /dev/sda にパーティション /dev/sda3 を再作成します。パーティションのサイズは書き戻す LVMパーティション(/dev/sdb1) と同サイズ以上にする必要があります。
fdisk /dev/sda
fdisk -l /dev/sda
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: 3A87099A-673A-4D5E-9C66-9D307A1A0FBF
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M EFI System
/dev/sda2 206848 10485759 10278912 4.9G Linux filesystem
Command (m for help): n
Partition number (3-128, default 3): 3
First sector (10485760-209715166, default 10485760):
Last sector, +sectors or +size{K,M,G,T,P} (10485760-209715166, default 209715166): +50G
Created a new partition 3 of type 'Linux filesystem' and of size 50 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@osaka-ayu-compute ~]# fdisk -l /dev/sda
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: 3A87099A-673A-4D5E-9C66-9D307A1A0FBF
Device Start End Sectors Size Type
/dev/sda1 2048 206847 204800 100M EFI System
/dev/sda2 206848 10485759 10278912 4.9G Linux filesystem
/dev/sda3 10485760 115343359 104857600 50G Linux filesystem
[root@osaka-ayu-compute ~]#
16. LVM の Volume Group に Boot Volume のパーティションを再追加
下記コマンドで LVM の Volume Group に Boot Volume のパーティション /dev/sda3 を再追加します。
vgextend ocivolume /dev/sda3
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# vgextend ocivolume /dev/sda3
Physical volume "/dev/sda3" successfully created.
Volume group "ocivolume" successfully extended
[root@osaka-ayu-compute ~]#
17. Block Volume のパーティションを Boot Volume のパーティションに移行(書き戻し)
下記コマンドで Block Volume のパーティション /dev/sdb1 を Boot Volume のパーティション /dev/sda3 に移行(書き戻し)します。
pvmove /dev/sdb1 /dev/sda3
vgs --options +devices
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# pvmove /dev/sdb1 /dev/sda3
/dev/sdb1: Moved: 0.02%
/dev/sdb1: Moved: 1.74%
/dev/sdb1: Moved: 3.26%
:
:
/dev/sdb1: Moved: 100.00%
[root@osaka-ayu-compute ~]# vgs --options +devices
VG #PV #LV #SN Attr VSize VFree Devices
ocivolume 2 2 0 wz--n- 99.99g <54.52g /dev/sda3(0)
ocivolume 2 2 0 wz--n- 99.99g <54.52g /dev/sda3(2560)
18. LVM の Volume Group から Block Volume のパーティションを削除
下記コマンドで LVM の Volume Group から Block Volume のパーティション /dev/sdb1 を削除
vgreduce ocivolume /dev/sdb1
実行結果は以下の通りです。
[root@osaka-ayu-compute ~]# vgreduce ocivolume /dev/sdb1
Removed "/dev/sdb1" from volume group "ocivolume"
19. Compute から Block Volume を Detach
Compute から Block Volume を Detach します。下記では OCIコンソール で Block Volume を Detach していますが OCI CLI等でもよいです。Detach した Block Volume は削除して問題ありません。
Block Volume を iSCSI で Attach している場合は OS で Disconnect してから Detach して下さい。
20. Compute の再起動とファイルシステム確認
Compute を再起動して dfコマンドを実行します。/boot領域が拡張されています。
Last login: Wed Jun 19 15:19:50 2024 from 172.17.20.2
[opc@osaka-ayu-compute ~]$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs tmpfs 7.7G 8.7M 7.7G 1% /run
tmpfs tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/ocivolume-root xfs 36G 11G 26G 30% /
/dev/mapper/ocivolume-oled xfs 10G 163M 9.9G 2% /var/oled
/dev/sda2 xfs 4.9G 385M 4.6G 8% /boot ★★拡張されている
/dev/sda1 vfat 100M 6.0M 94M 6% /boot/efi
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/987
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/1000
[opc@osaka-ayu-compute ~]$
21. Custom Image化のススメ
この作業ですが時間も手間も掛かります。幸い Custom Image化することで作業内容を保持できるので、新しい Compute で /boot領域の拡張を行いたい場合は、/boot領域を拡張済みの Compute を Custom Image化してそちらをプロビジョニングすることをオススメしておきます。
カスタム・イメージの管理
https://docs.oracle.com/ja-jp/iaas/Content/Compute/Tasks/managingcustomimages.htm
22. まとめ
OCI に作成した Oracle Linux の /boot領域(ファイルシステム)を拡張できました。
デフォルトの容量(1GB)がちと少ないような?最初からもう少し大きくして欲しいですやね彡(^)(^)
参考記事.
下記記事を参考にさせて頂きました。