概要
さくらのVPS では、v4 バージョンの仮想サーバでスケールアップ機能をご利用可能です。
スケールアップ機能を使えば、メモリおよびCPUは自動でスケールアップします。しかし、増量した仮想ディスク容量をOSに認識させるためには、お客様ご自身での作業が必要です。
この手順書は、仮想サーバ上で仮想ディスクを拡張する手順を説明します。
- ・本手順書はさくらのVPS v4 バージョンの仮想サーバのみ対応です。
・本手順書は標準OSの Ubuntu14.04 のみ対応です。
・初期提供時の仮想ディスクパーティション構成を変更している場合、
本手順書は対応しませんのでご注意ください。
・ディスクの拡張作業を実施するには、root権限が必要です。
・本手順を実施するにあたって、仮想サーバは1回以上の再起動が必要です。
本手順書で想定している仮想サーバのスペックは以下の通りです。実際のスペックは、お客様の実環境に合わせてお読み替えください。
- | プラン | 仮想CPU | 仮想メモリ容量 | 仮想ディスク容量 |
---|---|---|---|---|
スケールアップ前 | SSD 1G | 2CPU | 1024MB | 30GiB |
スケールアップ後 | SSD 4G | 4CPU | 4096MB | 100GiB |
スケールアップを実施する
さくらのVPSのスケールアップは、VPS コントロールパネルから行います。
手順の詳細については、こちらのマニュアル をご覧ください。
なお、スケールアップを実施する前に、念のために重要なデータのバックアップをとりましょう。
ディスク拡張の準備作業
サーバを起動、ログイン
スケールアップ完了後、VPSコントロールパネルの「起動」ボタンを押して、仮想サーバを起動します。
コントロールパネル上にある「コンソール」→「VNCコンソール(HTML5)」を使い、サーバが正常に起動できたのを確認します。
VNCコンソールまたはSSH経由で、仮想サーバへ ubuntu ユーザでログインします。
必要なパッケージをインストール
ディスクの状態の確認および拡張には、gdisk という名前のパッケージが必要です。
もしインストールされていなければ、あらかじめインストールしておきます。
1 2 3 4 |
$ dpkg -l gdisk dpkg-query: no packages found matching gdisk $ sudo apt-get install -y gdisk |
ディスクを拡張する
ディスクの状態を確認
現在のディスクの状況を確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$ sudo gdisk -l /dev/vda GPT fdisk (gdisk) version 0.8.8 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/vda: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 4E163027-808E-4390-AC37-17D747CB89C8 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 62914526 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 2 4096 8392703 4.0 GiB 8200 3 8392704 62914526 26.0 GiB 8300 Linux filesystem $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 253:0 0 100G 0 disk tqvda1 253:1 0 1M 0 part tqvda2 253:2 0 4G 0 part [SWAP] mqvda3 253:3 0 26G 0 part / |
gdisk コマンドの結果から /dev/vda のサイズは 100GB に拡張されたのが分かります。しかし、OS 側からの認識状況を確認しますと、3つのパーティションとして認識している容量の合計は 30GB です。
また、lsblk コマンドの結果から、標準OSでインストールしたパーティション 「tqvda1」「tqvda2」「mqvda3」 の3つが確認できます。
パーティションをソートする
先ほどの gdisk コマンドの実行結果を見ますと、Total free space (合計空き容量)が正しく認識されていないことが分かります。「2014 sectors (1007.0 KiB)」の表示、つまり空き容量が 1MB 程度ですが、本来は70GB あります。
これを整理(ソート)して正しい情報にするには、以下のコマンドを実行します。
1 2 3 4 |
$ 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. The operation has completed successfully. |
実行後、もう一度 gdisk コマンドでディスクの状況を確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$ sudo gdisk -l /dev/vda GPT fdisk (gdisk) version 0.8.8 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/vda: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 4E163027-808E-4390-AC37-17D747CB89C8 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 146802654 sectors (70.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 2 4096 8392703 4.0 GiB 8200 3 8392704 62914526 26.0 GiB 8300 Linux filesystem |
今度は Total free space が増えたのが分かります。「146802654 sectors (70.0 GiB)」と表示されており、正常に空き容量を認識しました。
新しいパーティションを作成する
スケールアップにより増えたディスク容量を OS 認識ができましたので、gdisk コマンドで新しいディスクパーティションを作ります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
$ sudo gdisk /dev/vda GPT fdisk (gdisk) version 0.8.8 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-209715166, default = 62914560) or {+-}size{KMGTP}: Last sector (62914560-209715166, default = 209715166) 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: 209715200 sectors, 100.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 4E163027-808E-4390-AC37-17D747CB89C8 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 209715166 Partitions will be aligned on 2048-sector boundaries Total free space is 2047 sectors (1023.5 KiB) ##### # 表示されている新しいパーティションテーブルにサイズなどの問題がないことを確認します。 ##### Number Start (sector) End (sector) Size Code Name 1 2048 4095 1024.0 KiB EF02 2 4096 8392703 4.0 GiB 8200 3 8392704 62914526 26.0 GiB 8300 Linux filesystem 4 62914560 209715166 70.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. The operation has completed successfully. |
ファイルシステムを作る
新規作成したパーティションを利用するには、フォーマットして、マウントする必要があります。以降の例ではファイルシステムを ext4 形式でフォーマットし、 /data にマウントする手順を説明します。
まず、新しいディスクパーティションがOS上にデバイスとして認識されているか確認します。
1 2 |
$ ls /dev/vda4 ls: cannot access /dev/vda4: No such file or directory |
新しく作成した vda4 がデバイスとして認識されていない場合は、一度OSを再起動しましょう。
1 |
$ sudo reboot |
再起動が困難な場合は、以下のコマンドで強制的に認識させることも可能です。
1 |
$ sudo partx -a /dev/vda |
vda4 がOSに認識されたら、 mkfs.ext4 コマンドでフォーマットを実行します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$ sudo mkfs.ext4 /dev/vda4 mke2fs 1.42.9 (4-Feb-2014) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 4587520 inodes, 18350075 blocks 917503 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 560 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done |
なお、この状態では作成したファイルシステムでは23カ月または180日たつと、自動的にファイルシステムのチェックが実行されます。
この間隔は tune2fs コマンドで調整できます。次の例はチェックを行わない指定です。
1 |
$ sudo tune2fs -c -1 -i 0 /dev/vda4 |
新しいディスクをマウントする
初期化した領域をディスクとして使うには、まずマウントポイントを作成します。
マウントポイントを作成したら、 /dev/vda4 を /data にマウントします。
1 2 |
$ sudo mkdir /data $ sudo mount /dev/vda4 /data |
それから、マウントが完了したかどうかを確認します。
1 2 3 4 5 6 7 8 9 10 |
$ mount | grep vda4 /dev/vda4 on /data type ext4 (rw) $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 253:0 0 100G 0 disk tqvda1 253:1 0 1M 0 part tqvda2 253:2 0 4G 0 part [SWAP] tqvda3 253:3 0 26G 0 part / mqvda4 253:4 0 70G 0 part /data |
70Gのサイズで /data にマウントされていることが確認できます。
最後にOSを再起動してもマウントできるように、 /etc/fstab に設定を追加します。
1 2 |
$ id=$(sudo blkid -o value -s UUID /dev/vda4) $ echo "UUID=${id} /data ext4 defaults 0 2" | sudo tee -a /etc/fstab |
サーバの再起動
拡張したディスクが正しく動作するか確認するために、仮想サーバを再起動します。
1 |
$ sudo reboot |
サーバを再起動した後に、 df コマンドなどで作成した領域がマウントされていることを確認できれば、作業完了です。