GenPi64でrootパーティションの拡張

partedを起動

GenPi64 /home/demouser $ sudo parted
GNU Parted 3.6
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.

セクタ単位に表示を切り替え

(parted) unit s

空きスペース確認

(parted) print free
Model: SATA SSD  (scsi)
Disk /dev/sda: 468862128s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start     End         Size        Type     File system  Flags
        63s       2047s       1985s                Free Space
         1      2048s     524287s     522240s     primary  fat16        boot, lba
         2      524288s   9682946s    9158659s    primary  btrfs
         9682947s  468862127s  459179181s           Free Space

resizeは使えない

(parted) resize
Error: The resize command has been removed in parted 3.0

既存パーティションは削除。 IgnoreかCancelかの質問はIgnoreと答える。

(parted) rm 2
Warning: Partition /dev/sda2 is being used. Are you sure you want to continue?
Yes/No? Yes
Error: Partition(s) 2 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because
it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
Ignore/Cancel? Ignore

パーティション作成。この際のEndは上記でユニットサイズでprint freeした際の、最後のパーティション(空き容量の行)の「終了」のセクタになる。

(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? btrfs
Start? 524288
End? 468862127

確認

(parted) print
Model: SATA SSD  (scsi)
Disk /dev/sda: 468862128s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start    End         Size        Type     File system  Flags
 1      2048s    524287s     522240s     primary  fat16        boot, lba
  2      524288s  468862127s  468337840s  primary  btrfs

parted終了

(parted) quit
Information: You may need to update /etc/fstab.

Linuxカーネルに新しいパーティション情報を認識させるため再起動(不要かもしれない)

下記のカーネルバージョンで試した際には再起動なしでカーネルはパーティションの拡張を認識し、リサイズも成功した。

uname -a
Linux k3s-prd-agent-c 6.1.21-v8 #1 SMP PREEMPT Tue Dec 26 06:28:03 -00 2023 aarch64 GNU/Linux
sudo reboot

リサイズ

下記を実行する

sudo btrfs filesystem resize max /
demouser@GenPi64 ~ $ sudo btrfs filesystem resize max /
Resize device id 1 (/dev/sda2) from 223.32GiB to max

増えている。

demouser@GenPi64 ~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       224G  3.1G  221G   2% /
devtmpfs        3.7G     0  3.7G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           1.6G  716K  1.6G   1% /run
/dev/zram2      2.0G   52K  2.0G   1% /var/tmp
/dev/zram1      2.0G   72K  2.0G   1% /tmp
/dev/sda1       255M  145M  110M  57% /boot
tmpfs           781M     0  781M   0% /run/user/1000

/etc/fstab 修正

パーティションのPARTUUIDを確認し、現在と/etc/fstabが異なる場合は修正する

PARTUUID確認方法

lsblkでの確認方法

lsblk -o NAME,PARTUUID

blkidでの確認方法

blkid /dev/mmcblk0p2
blkid /dev/sda2

SDカードの場合

# PARTUUID="c2d6f5ac-02"        /       btrfs   noatime,compress=zstd,ssd,discard,x-systemd.growfs      0       0
/dev/mmcblk0p2       /       btrfs   noatime,compress=zstd,ssd,discard,x-systemd.growfs      0       0

USB-SATA アダプタ経由の場合

# PARTUUID="c2d6f5ac-02"        /       btrfs   noatime,compress=zstd,ssd,discard,x-systemd.growfs      0       0
/dev/sda2       /       btrfs   noatime,compress=zstd,ssd,discard,x-systemd.growfs      0       0

参考

Linuxのパーテションをリサイズ (コマンドライン)