さくらのVPS から独立記事。
さくらの VPS v4 がスペックアップで SSD サイズ 30GB → 50GB に変更されたときにパーティション追加を行ったメモ。
ルートパーティション拡張はできなさそうなので、parted で GPT を書き換え、mkpart で新しいパーティションを追加した。
8 Parted Commands to Create and Manage Partitions in Linux
https://www.tecmint.com/parted-command-create-linux-partitions/
$ cat /etc/redhat-release CentOS release 6.10 (Final) $ uname -a Linux localhost.localdomain 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
parted でパーティション一覧を出すと、GPT の修正を提案されるので受け入れる。
$ parted
$ (parted) print Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 41943040 blocks) or continue with the current setting? Fix/Ignore? # F
まだパーティションの合計は 30GB のときのまま。
Model: Virtio Block Device (virtblk) Disk /dev/vda: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 263MB 262MB ext4 Linux filesystem 2 263MB 2411MB 2147MB linux-swap(v1) Linux swap 3 2411MB 32.2GB 29.8GB ext4 Linux filesystem
新しいパーティションを作る。
$ (parted) mkpart Partition name? []? # data File system type? [ext2]? # ext2 Start? # 32.2GB End? # 53.7GB
ext4 は対応していないようで怒られてしまった。
No Implementation: Support for creating ext4 file systems is not implemented yet.
警告が出るけど気にしない。
Warning: WARNING: the kernel failed to re-read the partition table on /dev/vda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
パーティション一覧を再表示。
(parted) print Model: Virtio Block Device (virtblk) Disk /dev/vda: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 1049kB 263MB 262MB ext4 Linux filesystem 2 263MB 2411MB 2147MB linux-swap(v1) Linux swap 3 2411MB 32.2GB 29.8GB ext4 Linux filesystem 4 32.2GB 53.7GB 21.5GB ext2 data
パーティションが追加されたので parted を閉じる。ありがたいお知らせ付き。
$ (parted) quit Information: You may need to update /etc/fstab.
パーティションテーブルが再読み込みできなかったそうなのでリブートする。
その後 /dev/vda4 が追加されているか確認する。
ext4 にするには以下を入力してまたリブート。
mkfs.ext4 /dev/vda4
fstab に作成したパーティションを追加する。
mkdir /data id=$(blkid -o value -s UUID /dev/vda4) echo "UUID=${id} /data ext4 defaults 0 2" | sudo tee /etc/fstab