VirtualBox6.0上のOracleLinux7.6のディスクを拡張する

VirtualBox6.0上にインストールされたOracleLinux7.6のディスクを拡張した時のメモ。

バージョン

VirtualBox 6.0
OracleLinux 7.6

VirtualBoxの設定

 ・ファイル>仮想メディアマネージャ を選択
 ・追加したいディスクのプロパティ画面を表示して、ディスクのサイズを変更して適用

OracleLinuxの設定

 ・rootユーザでログイン
 ・現状のディスク確認

[root@oel7 ~]$ df
ファイルシス        1K-ブロック    使用  使用可 使用% マウント位置
/dev/mapper/ol-root    10258432 9495888  762544   93% /
devtmpfs                1006548       0 1006548    0% /dev
tmpfs                   1023400       0 1023400    0% /dev/shm
tmpfs                   1023400    9680 1013720    1% /run
tmpfs                   1023400       0 1023400    0% /sys/fs/cgroup
/dev/sda1               1038336  299928  738408   29% /boot
tmpfs                    204680       8  204672    1% /run/user/42
tmpfs                    204680      24  204656    1% /run/user/1000


 ・fdiskでパーティションを拡張

[root@oel7 ~]# fdisk /dev/sda
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/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000b1daf

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    25165823    11533312   8e  Linux LVM

コマンド (m でヘルプ): d
パーティション番号 (1,2, default 2): 
Partition 2 is deleted

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

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

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

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   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)
ディスクを同期しています。


 ・Linuxを再起動

[root@oel7 ~]# reboot


 ・物理ボリュームのサイズの変更

[root@oel7 ~]# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized


 ・論理ボリュームのサイズを拡張

[root@oel7 ~]# lvextend -l +100%FREE /dev/mapper/ol-root
  Size of logical volume ol/root changed from 9.79 GiB (2507 extents) to <17.80 GiB (4556 extents).
  Logical volume ol/root successfully resized.


 ・ファイルシステムを拡張

[root@oel7 ~]# xfs_growfs /dev/mapper/ol-root
meta-data=/dev/mapper/ol-root    isize=256    agcount=4, agsize=641792 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2567168, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               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 2567168 to 4665344


 ・ディスクサイズが拡張されたか確認

[root@oel7-node2 ~]# df
ファイルシス        1K-ブロック    使用  使用可 使用% マウント位置
/dev/mapper/ol-root    18651136 9641740 9009396   52% /
devtmpfs                1006548       0 1006548    0% /dev
tmpfs                   1023400       0 1023400    0% /dev/shm
tmpfs                   1023400    9664 1013736    1% /run
tmpfs                   1023400       0 1023400    0% /sys/fs/cgroup
/dev/sda1               1038336  299928  738408   29% /boot
tmpfs                    204680       4  204676    1% /run/user/42
tmpfs                    204680      24  204656    1% /run/user/1000