Linux VM のディスクサイズを拡張してみる(非 OS 領域)

投稿者: | 2024-01-09

samba 共有している領域のディスクの空き容量が逼迫し始めたのでディスク拡張をしてみる。
いつもはより大きいディスクをぶら下げてマウント変更するヤドカリの引っ越し方式で対応していたけど、データ退避が面倒になったのでそのまま拡張で行ってみることにする。

先ずは作業前の状態を確認。
拡張対象は 300G の /ftp_home という領域。

# df -h
ファイルシス        サイズ  使用  残り 使用% マウント位置
devtmpfs              908M     0  908M    0% /dev
tmpfs                 920M     0  920M    0% /dev/shm
tmpfs                 920M   41M  879M    5% /run
tmpfs                 920M     0  920M    0% /sys/fs/cgroup
/dev/mapper/cl-root    27G  3.2G   24G   12% /
/dev/sda1            1014M  305M  710M   31% /boot
/dev/sdb1             300G  272G   28G   91% /ftp_home
tmpfs                 184M     0  184M    0% /run/user/1000
# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


コマンド (m でヘルプ): p

Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xd73b3265

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048   629145599   314571776   83  Linux

次に ESXi 上でディスクサイズを 300GB から 500GB に変更。(作業対象の OS は起動したままで作業)

サイズ変更後、改めて状態を確認。

# df -h
ファイルシス        サイズ  使用  残り 使用% マウント位置
devtmpfs              908M     0  908M    0% /dev
tmpfs                 920M     0  920M    0% /dev/shm
tmpfs                 920M  9.0M  911M    1% /run
tmpfs                 920M     0  920M    0% /sys/fs/cgroup
/dev/mapper/cl-root    27G  3.2G   24G   12% /
/dev/sdb1             300G  272G   28G   91% /ftp_home
/dev/sda1            1014M  318M  697M   32% /boot
tmpfs                 184M     0  184M    0% /run/user/1000

df の結果に変化ないけど、

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


コマンド (m でヘルプ): p

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xd73b3265

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048   629145599   314571776   83  Linux

fdisk の結果は 322.1GB から 536.9GB に変わっている。
そのまま fdisk で対象の sdb1 を一旦削除し作り直す。

# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


コマンド (m でヘルプ): p  

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xd73b3265

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048   629145599   314571776   83  Linux

コマンド (m でヘルプ): 
コマンド (m でヘルプ): d
Selected partition 1
Partition 1 is deleted

コマンド (m でヘルプ): p

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xd73b3265

デバイス ブート      始点        終点     ブロック   Id  システム

コマンド (m でヘルプ): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
パーティション番号 (1-4, default 1): 1
最初 sector (2048-1048575999, 初期値 2048): そのままエンター
初期値 2048 を使います
Last sector, +sectors or +size{K,M,G} (2048-1048575999, 初期値 1048575999): そのままエンター
初期値 1048575999 を使います
Partition 1 of type Linux and of size 500 GiB is set

コマンド (m でヘルプ): p

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xd73b3265

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048  1048575999   524286976   83  Linux

コマンド (m でヘルプ): w
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。

WARNING: Re-reading the partition table failed with error 16: デバイスもしくはリソースがビジー状態です.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
ディスクを同期しています。

ディスク領域としては拡張されたけど、ファイルシステムのサイズが以前のままなので、ファイルシステム側を引き続き拡張する。
xfs を使っている筈だけど、念のため fstab を確認しておく。

# cat /etc/fstab 

~省略~
UUID=6d1366d9-86f3-4cb2-bcf9-26c1e420a93f /ftp_home     xfs     defaults        0 0
~/省略~

想定通り xfs を使っているので xfs_growfs で拡張実施。

# xfs_growfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=19660736 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=78642944, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=38399, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 78642944 to 131071744

コマンドを叩くだけで勝手に拡張される。
改めて df でサイズを確認すると 500G に拡張され、使用率も 91% から 55% まで軽減。

# df -h
ファイルシス        サイズ  使用  残り 使用% マウント位置
devtmpfs              908M     0  908M    0% /dev
tmpfs                 920M     0  920M    0% /dev/shm
tmpfs                 920M  9.0M  911M    1% /run
tmpfs                 920M     0  920M    0% /sys/fs/cgroup
/dev/mapper/cl-root    27G  3.2G   24G   12% /
/dev/sda1            1014M  318M  697M   32% /boot
/dev/sdb1             500G  272G  228G   55% /ftp_home
tmpfs                 184M     0  184M    0% /run/user/1000

念のため、拡張した領域下で rw してみて問題ないことを確認し作業終了。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です