LoginSignup
2
1

More than 3 years have passed since last update.

GCP上のCML2のディスク拡張

Posted at

はじめに

CML2をGCPで使用している際、ディスク容量が足りなくなったので、拡張する方法をまとめます。

手順

1.VMインスタンスでのディスク拡張

まずは該当のVMインスタンスで使用しているディスクのサイズを拡張したいサイズへ変更します。
ナビゲーションメニュー >Compute Engine >ディスク
スクリーンショット 2021-05-10 13.38.28.png

拡張したいディスクをクリックし、編集からサイズを変更して保存。
スクリーンショット 2021-05-10 13.34.54.png

スクリーンショット 2021-05-10 13.35.06.png

2.コマンドラインから拡張

まずは現状の確認。
/dev/mapper/cl_cml2--controller-root が変更前の15Gのままです。
今回は40Gへ拡張します。

$ df -h
Filesystem                            Size  Used Avail Use% Mounted on
devtmpfs                               15G     0   15G   0% /dev
tmpfs                                  15G  160K   15G   1% /dev/shm
tmpfs                                  15G  8.6M   15G   1% /run
tmpfs                                  15G     0   15G   0% /sys/fs/cgroup
/dev/mapper/cl_cml2--controller-root   15G   15G 1020K 100% / # ここを拡張します
/dev/sda1                             488M  156M  297M  35% /boot
overlay                                15G   15G 1020K 100% /var/lib/libvirt/images
tmpfs                                 3.0G     0  3.0G   0% /run/user/1000

対象デバイスの情報を確認します。
cl_cml2--controller-root が拡張対象となるので、sdaの2つ目のパーティションが対象となります。

$ sudo lsblk
NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                            8:0    0   40G  0 disk
|-sda1                         8:1    0  512M  0 part /boot
`-sda2                         8:2    0 15.5G  0 part
  |-cl_cml2--controller-root 253:0    0   15G  0 lvm  / #拡張対象です
  `-cl_cml2--controller-swap 253:1    0  512M  0 lvm  [SWAP]

対話モードで対象デバイスのパーティション情報を確認していきます。

$ sudo fdisk /dev/sda
[sudo] password for sysadmin:

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

まずは'p'を入力します。
1行目でこのデバイスに40Gの割り当てられていることが確認できます。
今回は2つ目のパーティションのsda2を拡張します。

Command (m for help): p
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xf8882087

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1050623  1048576  512M 83 Linux
/dev/sda2       1050624 67108830 66058207 31.5G 8e Linux LVM

拡張するために、’d’にて一度パーティションを削除します。

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

削除後の確認で'p'を実行すると、パーティションが削除され情報が表示されてません。

Command (m for help): p
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xf8882087

Device     Boot Start     End Sectors  Size Id Type
/dev/sda1  *     2048 1050623 1048576  512M 83 Linux

拡張後の論理パーティションを作成します。
はじめに'n'にて新規パーティションを作成します。
パーティションタイプは'P'のプライマリー、
パーティションナンバーは削除した'2'、
FirstセクターとLastセクターはdefaultと表示されている値を使用します。
作成後に、LVM signatureの削除を確認されますが、削除はしないので、'n'を入力。

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): P
Partition number (2-4, default 2): 2
First sector (1050624-83886079, default 1050624): 1050624
Last sector, +sectors or +size{K,M,G,T,P} (1050624-83886079, default 83886079): 83886079

Created a new partition 2 of type 'Linux' and of size 39.5 GiB.
Partition #2 contains a LVM2_member signature.

Do you want to remove the signature? [Y]es/[N]o: n

新規作成したパーティションのタイプを設定します。
’t’を入力し、タイプの設定モード。
パーティションナンバーは'2'、
Hex codeは削除前と同様にLinux LVMの'8e'を指定します。

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

保存します。

Command (m for help): w
The partition table has been altered.
Syncing disks.

一度リブートします。

$ sudo reboot
[sudo] password for sysadmin:

物理ボリュームを拡張します。

$ sudo pvresize /dev/sda2
[sudo] password for sysadmin:
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

論理ボリュームを拡張する前に、拡張対象のパスを確認します。

$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/cl_cml2-controller/root # これが対象のパスになります
  LV Name                root
  VG Name                cl_cml2-controller
  LV UUID                JlPwdJ-US8U-AeXT-t3fB-egUP-2gO6-HJBtnt
  LV Write Access        read/write
  LV Creation host, time cml2-controller.cml.lab, 2020-07-30 07:41:56 -0400
  LV Status              available
  # open                 1
  LV Size                <15.00 GiB
  Current LE             3839
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/cl_cml2-controller/swap
  LV Name                swap
  VG Name                cl_cml2-controller
  LV UUID                Qazfpx-trJd-j2v9-i69C-RjyQ-SYRj-et1k1q
  LV Write Access        read/write
  LV Creation host, time cml2-controller.cml.lab, 2020-07-30 07:41:57 -0400
  LV Status              available
  # open                 2
  LV Size                512.00 MiB
  Current LE             128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

空き容量全てを対象の論理ボリュームに割り当てます。

$ sudo lvresize -l +100%FREE /dev/cl_cml2-controller/root
  Size of logical volume cl_cml2-controller/root changed from <15.00 GiB (3839 extents) to <39.00 GiB (9983 extents).
  Logical volume cl_cml2-controller/root successfully resized.

最後にファイルシステムの拡張をします。
マウントポイントはlsblkで確認の通り、'/'になります。

$ sudo xfs_growfs /
meta-data=/dev/mapper/cl_cml2--controller-root isize=512    agcount=21, agsize=196352 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=3931136, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           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 3931136 to 10222592

最後にdfで確認です。
/dev/mapper/cl_cml2--controller-root が無事に39Gで認識されてます。

$ df -h
Filesystem                            Size  Used Avail Use% Mounted on
devtmpfs                               15G     0   15G   0% /dev
tmpfs                                  15G  160K   15G   1% /dev/shm
tmpfs                                  15G  8.6M   15G   1% /run
tmpfs                                  15G     0   15G   0% /sys/fs/cgroup
/dev/mapper/cl_cml2--controller-root   39G   16G   24G  39% /
/dev/sda1                             488M  156M  297M  35% /boot
overlay                                39G   16G   24G  39% /var/lib/libvirt/images
tmpfs                                 3.0G     0  3.0G   0% /run/user/1000
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1