概要
こちらの記事でFedora Server28を32GBのマイクロSDカードを使用し、RaspberryPi3B+にインストールしたところ、SDカードが約6GBしか認識しないため、最大容量まで拡張する。
Raspbianならraspi-configでワンクリックで済むのですが…
インストール直後の状態
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 427M 0 427M 0% /dev
tmpfs 482M 0 482M 0% /dev/shm
tmpfs 482M 488K 482M 1% /run
tmpfs 482M 0 482M 0% /sys/fs/cgroup
/dev/mapper/fedora-root 5.1G 1.7G 3.5G 33% /
tmpfs 482M 44K 482M 1% /tmp
/dev/mmcblk0p2 976M 57M 853M 7% /boot
/dev/mmcblk0p1 200M 19M 182M 10% /boot/efi
tmpfs 97M 0 97M 0% /run/user/0
ルート(/)ディレクトリが5.1GBしかない。
Linuxのファイルシステムの構造
・PV(Physical Volume):物理サイズ
・VG(Volume Group):ボリュームグループ。複数の物理ディスク(PV)をまとめることで、OSから1つのディスクとして認識できるようにする。
・LV(Logical Volume):論理ボリューム、/rootとか/swapとか
PVの確認
# fdisk -l
Disk /dev/mmcblk0: 29.8 GiB, 32026656768 bytes, 62552064 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
Disklabel type: dos
Disk identifier: 0x9235b19a
:
32GB(29.8GB)できちんと認識している。物理ディスク名は/dev/mmcblk0。
VGの確認
# vgdisplay
--- Volume group ---
VG Name fedora
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 5.80 GiB
PE Size 4.00 MiB
Total PE 1485
Alloc PE / Size 1485 / 5.80 GiB
Free PE / Size 0 / 0
VG UUID CtfkUX-w1WC-MdqS-3xRz-eDi8-L8x8-pNajPQ
ボリュームグループ名はfedora。サイズが5.8GBしかない。
LVの確認
# lvdisplay
--- Logical volume ---
LV Path /dev/fedora/swap
LV Name swap
VG Name fedora
LV UUID FftS6Z-Bnr9-dC76-gNTe-y7qd-kIsU-oP6pTS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-04-25 15:10:27 +0900
LV Status available
# open 2
LV Size 720.00 MiB
Current LE 180
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/fedora/root
LV Name root
VG Name fedora
LV UUID 3ZZxw3-SHI5-MG58-Wdc9-g3T3-MYGW-2yooj9
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-04-25 15:10:28 +0900
LV Status available
# open 1
LV Size <5.10 GiB
Current LE 1305
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
VG=fedoraの中に、LV=rootが5.1GB、LV=swapが720MB存在する。
拡張手順
ルートディレクトリ(/)を最大サイズまで拡張する。
1.PVにパーティーションを追加し、使われていない残りの全領域を割り当てる
2.作成したパーティーション(PV)をボリュームグループ(VG)に入れることで、VGにSDカードの全領域を設定する
3.ルートの論理ボリュームを拡張する
1.パーティーションを追加
物理ディスク(/dev/mmcblk0)にパーティーションを追加する。
"w"で書き込むまでは取り消し(やり直し)可能です。
# fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.32).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
"p"で現在の状態を確認する。
Command (m for help): p
Disk /dev/mmcblk0: 29.8 GiB, 32026656768 bytes, 62552064 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
Disklabel type: dos
Disk identifier: 0x9235b19a
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 2048 411647 409600 200M 6 FAT16
/dev/mmcblk0p2 411648 2508799 2097152 1G 83 Linux
/dev/mmcblk0p3 2508800 14680063 12171264 5.8G 8e Linux LVM
/dev/mmcblk0にp3まであるので、p4を追加する。新規作成は"n"を入力。
"p"でprimaryを選択して、残りはすべてデフォルトでいいので何も入力せず、Enterのみでよい。
最後はよくわからないがYesとした。何も言われないこともある。
Command (m for help): n
Partition type
p primary (3 primary, 0 extended, 1 free)
e extended (container for logical partitions)
Select (default e): p
Selected partition 4
First sector (14680064-62552063, default 14680064):
Last sector, +sectors or +size{K,M,G,T,P} (14680064-62552063, default 62552063):
Created a new partition 4 of type 'Linux' and of size 22.8 GiB.
Partition #4 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: Y
The signature will be removed by a write command.
"p"で設定を確認する。
Command (m for help): p
Disk /dev/mmcblk0: 29.8 GiB, 32026656768 bytes, 62552064 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
Disklabel type: dos
Disk identifier: 0x9235b19a
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 * 2048 411647 409600 200M 6 FAT16
/dev/mmcblk0p2 411648 2508799 2097152 1G 83 Linux
/dev/mmcblk0p3 2508800 14680063 12171264 5.8G 8e Linux LVM
/dev/mmcblk0p4 14680064 62552063 47872000 22.8G 83 Linux
Filesystem/RAID signature on partition 4 will be wiped.
パーティーション4に残りの全領域が設定される。この時点では変更は反映されておらず、"q"で取り消して抜けることができる。
問題なければ"w"で書き込まれる。
設定を間違えていると起動しなくなることもあるので注意。
Command (m for help): w
The partition table has been altered.
Syncing disks.
2.作成したパーティーションをボリュームグループに追加
パーティーション4に22.8GBが存在するが、ボリュームグループ=fedoraには入っていない状態。
まずはパーティーションを初期化する。
初期化前はp4は認識されていない。
# pvscan
PV /dev/mmcblk0p3 VG fedora lvm2 [5.80 GiB / 0 free]
Total: 1 [5.80 GiB] / in use: 1 [5.80 GiB] / in no VG: 0 [0 ]
pvcreateで初期化すると、認識される。
# pvcreate /dev/mmcblk0p4
Physical volume "/dev/mmcblk0p4" successfully created.
# pvscan
PV /dev/mmcblk0p3 VG fedora lvm2 [5.80 GiB / 0 free]
PV /dev/mmcblk0p4 lvm2 [<22.83 GiB]
Total: 2 [<28.63 GiB] / in use: 1 [5.80 GiB] / in no VG: 1 [<22.83 GiB]
PVとして認識されたので、これをVGに入れる。
まず、VGに入れる前の状態。VG Sizeは5.8GBとなっている。
# vgdisplay
--- Volume group ---
VG Name fedora
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 5.80 GiB
PE Size 4.00 MiB
Total PE 1485
Alloc PE / Size 1485 / 5.80 GiB
Free PE / Size 0 / 0
VG UUID CtfkUX-w1WC-MdqS-3xRz-eDi8-L8x8-pNajPQ
/dev/mmcblk0p4をfedoraに入れるとVG Sizeが28GBまで拡張される。増加分の22.8GBはFreeとなっている。
# vgextend fedora /dev/mmcblk0p4
Volume group "fedora" successfully extended
# vgdisplay
--- Volume group ---
VG Name fedora
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 28.62 GiB
PE Size 4.00 MiB
Total PE 7328
Alloc PE / Size 1485 / 5.80 GiB
Free PE / Size 5843 / 22.82 GiB
VG UUID CtfkUX-w1WC-MdqS-3xRz-eDi8-L8x8-pNajPQ
3.論理ボリュームを拡張する
論理ボリュームを確認。
# lvdisplay
--- Logical volume ---
LV Path /dev/fedora/swap
LV Name swap
VG Name fedora
LV UUID FftS6Z-Bnr9-dC76-gNTe-y7qd-kIsU-oP6pTS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-04-25 15:10:27 +0900
LV Status available
# open 2
LV Size 720.00 MiB
Current LE 180
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/fedora/root
LV Name root
VG Name fedora
LV UUID 3ZZxw3-SHI5-MG58-Wdc9-g3T3-MYGW-2yooj9
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-04-25 15:10:28 +0900
LV Status available
# open 1
LV Size <5.10 GiB
Current LE 1305
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
/dev/fedora/swapと/dev/fedora/rootの2つがあるがswapは増やす必要がないので、全容量を/rootに割り当てる。
# lvextend -l +100%FREE /dev/fedora/root
Size of logical volume fedora/root changed from <5.10 GiB (1305 extents) to 27.92 GiB (7148 extents).
Logical volume fedora/root successfully resized.
割り当て状態を確認する。この時点では、論理ボリュームの拡張はできているが、ファイルシステムとしては認識されていないので、ファイルシステムの拡張を行う必要がある。
# lvscan
ACTIVE '/dev/fedora/swap' [720.00 MiB] inherit
ACTIVE '/dev/fedora/root' [27.92 GiB] inherit
# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 436588 0 436588 0% /dev
tmpfs 493056 0 493056 0% /dev/shm
tmpfs 493056 492 492564 1% /run
tmpfs 493056 0 493056 0% /sys/fs/cgroup
/dev/mapper/fedora-root 5335040 1897980 3437060 36% /
tmpfs 493056 44 493012 1% /tmp
/dev/mmcblk0p2 999320 58048 872460 7% /boot
/dev/mmcblk0p1 204580 18824 185756 10% /boot/efi
tmpfs 98608 0 98608 0% /run/user/0
resize2fsは使用できず、xfs_growfsを使うことになっている。
また、論理ボリュームではなくマウントポイント("/")を指定する。
# xfs_growfs /
meta-data=/dev/mapper/fedora-root isize=512 agcount=4, agsize=334080 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1 spinodes=0 rmapbt=0
= reflink=0
data = bsize=4096 blocks=1336320, 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 1336320 to 7319552
確認。
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 427M 0 427M 0% /dev
tmpfs 482M 0 482M 0% /dev/shm
tmpfs 482M 492K 482M 1% /run
tmpfs 482M 0 482M 0% /sys/fs/cgroup
/dev/mapper/fedora-root 28G 1.9G 27G 7% /
tmpfs 482M 44K 482M 1% /tmp
/dev/mmcblk0p2 976M 57M 853M 7% /boot
/dev/mmcblk0p1 200M 19M 182M 10% /boot/efi
tmpfs 97M 0 97M 0% /run/user/0
28GB認識されている。