目次
[更新: 2020年4月23日]
概要
さくらのVPSにおいて、V4, V5バージョンの仮想サーバではスケールアップ機能のご利用は可能です。
スケールアップ機能を使えば、メモリおよびCPUは自動でスケールアップします。しかし、増量した仮想ディスク容量をOSに認識させるためには、お客様ご自身での作業が必要です。
この手順書は、仮想サーバ上で仮想ディスクを拡張する手順を説明します。
- ・本手順書はさくらのVPS V4, V5 バージョンの仮想サーバのみ対応します。
・本手順書の対象は標準OSの Ubuntu 18.04 です。カスタムOSにてインストールされた Ubuntu 18.04 は対象外となります。
・初期提供時の仮想ディスクパーティションの構成が変更があった場合、本手順書では適応しないので、ご注意ください。
・ディスクの拡張作業を実施するには、root権限が必要となります。
・本手順を実施するにあたって、仮想サーバは1回以上の再起動が必要です。
本手順書で想定している仮想サーバのスペックは以下の通りです。実際のスペックは、お客様の実環境に合わせてお読み替えください。
- | プラン | 仮想CPU | 仮想メモリ容量 | 仮想ディスク容量 |
---|---|---|---|---|
スケールアップ前 | 512 MB | 1 CPU | 512 MB | 25 GiB |
スケールアップ後 | 1 G | 2 CPU | 1024 MB | 50 GiB |
スケールアップの実施
さくらのVPSのスケールアップは、VPS コントロールパネルから行います。
手順の詳細については、こちらのマニュアル をご覧ください。
なお、スケールアップを実施する前に、念のために重要なデータのバックアップをとりましょう。
ディスク拡張の準備作業
サーバを起動、ログイン
スケールアップ完了後、VPSコントロールパネルの「起動」ボタンを押して、仮想サーバを起動します。
「コンソール」-「VNCコンソール」をクリックします。
サーバの起動が正常に完了したことを確認してから、ubuntu ユーザでログインします。※サーバへのログインは、SSH経由でも問題ありません。
必要なパッケージのインストール
ディスクの状態の確認および拡張には、gdisk という名前のパッケージが必要です。
もしインストールされていなければ、あらかじめインストールしておきます。
$ dpkg -l gdisk dpkg-query: no packages found matching gdisk $ sudo apt install -y gdisk
ディスクの拡張
ディスク状態の確認
現在のディスクの状況を確認します。
$ sudo gdisk -l /dev/vda GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/vda: 104857600 sectors, 50.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 279D0791-7FA2-479C-8B01-240EEBC1D913 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 52428766 Partitions will be aligned on 2048-sector boundaries Total free space is 4541 sectors (2.2 MiB) Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 primary 2 4096 8392703 4.0 GiB 8200 primary 3 8392704 52426239 21.0 GiB 8300 primary $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 50G 0 disk ├─vda1 252:1 0 1M 0 part ├─vda2 252:2 0 4G 0 part [SWAP] └─vda3 252:3 0 21G 0 part /
gdisk コマンドの結果から /dev/vda のサイズは 50GB に拡張されたのがわかります。しかし、OS側からの認識状況を確認しますと3つのパーティションとして認識している容量の合計は25GBです。
また、lsblk コマンドの結果から標準OSインストールしたパーティション「vda1」「vda2」「vda3」の3つが確認できます。
パーティションのソート
先ほどの gdisk コマンドの実行結果を見ますと、Total free space (合計空き容量) が正しく認識されていないことがわかります。
「4541 sectors (2.2 MiB)」の表示、つまり空き容量が2.2MB程度ですが、本来は 25GB あります。これを整理(ソート)して正しい情報にするには、以下のコマンドを実行します。
$ sudo sgdisk -s /dev/vda Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.
実行後、もう一度 gdisk コマンドでディスクの状況を確認します。
$ sudo gdisk -l /dev/vda GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/vda: 104857600 sectors, 50.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 279D0791-7FA2-479C-8B01-240EEBC1D913 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 104857566 Partitions will be aligned on 2048-sector boundaries Total free space is 52433341 sectors (25.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 primary 2 4096 8392703 4.0 GiB 8200 primary 3 8392704 52426239 21.0 GiB 8300 primary
今度は Total free space が増えたのがわかります。「146802654 sectors (25.0 GiB)」と表示されており、正常に空き容量を認識しました。
新しいパーティションの作成
スケールアップにより増えたディスク容量を OS 認識ができましたので、gdisk コマンドで新しいディスクパーティションを作成します。
$ sudo gdisk /dev/vda GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. ##### # [ n ] コマンドを入力します。新しいパーティションを作るという意味です。 ##### Command (? for help): n ##### # Partition number はデフォルトの [ 4 ] にしますので、そのまま [ Enter ] キーを押します。 ##### Partition number (4-128, default 4): ##### # Fisrt sector/Last sector もデフォルトの数値にするので、そのまま [ Enter ] キーを押します。 ##### First sector (34-104857566, default = 52426752) or {+-}size{KMGTP}: Last sector (52426752-104857566, default = 104857566) or {+-}size{KMGTP}: ##### # Partition Type もデフォルトの [ Linux filesystem ] で問題がなければ、そのまま [ Enter ] キーを押します。 ##### Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' ##### # 作成完了したので、 [ p ] コマンドでパーティションテーブルの確認をします。 ##### Command (? for help): p Disk /dev/vda: 104857600 sectors, 50.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 279D0791-7FA2-479C-8B01-240EEBC1D913 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 104857566 Partitions will be aligned on 2048-sector boundaries Total free space is 2526 sectors (1.2 MiB) ##### # 表示されている新しいパーティションテーブルにサイズなどの問題がないことを確認します。 ##### Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 primary 2 4096 8392703 4.0 GiB 8200 primary 3 8392704 52426239 21.0 GiB 8300 primary 4 52426752 104857566 25.0 GiB 8300 Linux filesystem ##### # 問題がなければ [ w ] コマンドを入力します。 ##### Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! ##### # もう一度確認をして問題がなければ [ y ]を入力して、 [ Enter ] キーを押します。 # このコマンドを実行すると、ディスクの書き換えが発生するので、必ず確認した上で実行しましょう。 ##### Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/vda. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.
ファイルシステムの作成
新規作成したパーティションを利用するには、フォーマットして、マウントする必要があります。以降の例ではファイルシステムを ext4 形式でフォーマットし、 /data にマウントする手順を説明します。
まず新しいディスクパーティションがOS上にデバイスとして認識されているかを確認します。
$ ls /dev/vda4 ls: cannot access /dev/vda4: No such file or directory
vda4 が デバイスとして認識されていない場合、一度OSを再起動します。
$ sudo reboot
再起動が困難な場合は、以下のコマンドで強制認識させることも可能です。
$ sudo partx -a /dev/vda
vda4 がOSに認識されたら、 mkfs.ext4 コマンドでフォーマットを実行します。
$ sudo mkfs.ext4 /dev/vda4 mke2fs 1.44.1 (24-Mar-2018) Creating filesystem with 6553600 4k blocks and 1641600 inodes Filesystem UUID: eee5636a-78df-47e4-95a7-0949db8ffba7 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
なお、この状態では作成したファイルシステムでは23カ月または180日たつと、自動的にファイルシステムのチェックが実行されます。
この間隔は tune2fs コマンドで調整できます。次の例はチェックを行わない指定です。
$ sudo tune2fs -c -1 -i 0 /dev/vda4 tune2fs 1.44.1 (24-Mar-2018) Setting maximal mount count to -1 Setting interval between checks to 0 seconds
新しいディスクのマウント
初期化した領域をディスクとして使うには、まずマウントポイントを作成します。
マウントポイントを作成したら、 /dev/vda4 を /data にマウントします。
$ sudo mkdir /data $ sudo mount /dev/vda4 /data
マウントが完了したかどうかを確認します。
$ mount | grep vda4 /dev/vda4 on /data type ext4 (rw,relatime,data=ordered) # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 50G 0 disk ├─vda1 252:1 0 1M 0 part ├─vda2 252:2 0 4G 0 part [SWAP] ├─vda3 252:3 0 21G 0 part / └─vda4 252:4 0 25G 0 part /data
25G のサイズで /data にマウントされていることが確認できます。
最後にOSを再起動してもマウントできるように、 /etc/fstab に設定を追加します。
$ id=$(sudo blkid -o value -s UUID /dev/vda4) $ echo "UUID=${id} /data ext4 defaults 0 2" | sudo tee -a /etc/fstab
サーバの再起動
拡張したディスクが正しく動作するか確認するために、仮想サーバを再起動します。
$ sudo reboot
サーバを再起動した後に、df コマンドなどで作成した領域がマウントされていることを確認できれば作業完了です。