LoginSignup
0
1

More than 1 year has passed since last update.

VirtualBoxにおけるCentOS7のディスク容量を増やす

Posted at

参考サイト
https://yukituna.com/2790/
https://beanhouse.org/wordpress/?p=1490

現在のディスク使用状況の確認

# df
ファイルシス            1K-ブロック    使用  使用可 使用% マウント位置
devtmpfs                    5470928       0 5470928    0% /dev
tmpfs                       5487828       0 5487828    0% /dev/shm
tmpfs                       5487828    9660 5478168    1% /run
tmpfs                       5487828       0 5487828    0% /sys/fs/cgroup
/dev/mapper/centos-root     6486016 6482552    3464  100% /
/dev/sda1                   1038336  244292  794044   24% /boot
tmpfs                       1097568      28 1097540    1% /run/user/1000

ルートディレクトリの使用%が100%になってしまったのでこれを拡張します。
また、オプションで -h を付けると単位付きでわかりやすく表示してくれます。

# df -h

VirtualBoxでの設定

vbset.png

ファイル -> 仮想メディアマネージャー から設定します
フォト 2022_06_08 20_14_07.png

ディスクの一覧と仮想的なサイズ、実際のサイズが表示されます
下にあるサイズから容量を選択して適用を押して閉じます

ゲストOSのCLIからの操作

ゲストOSを起動して先ほどの操作したdfコマンドからパーティションを操作していきます

# 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 でヘルプ): 

コマンドを入力して操作します。主な操作は以下です。

コマンド 処理
m コマンド一覧を表示
p パーティション一覧を表示
n 新しいパーティションを作成
w 変更を保存して終了
q 変更を保存せずに終了

pコマンドで一覧を表示しましょう

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

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

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

dコマンドで/dev/sda2を解放します

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

nコマンドでパーティション2を追加します
全部デフォルトで構いません(Enterを押していくだけでOK)

コマンド (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-104857599, 初期値 2099200): 
初期値 2099200 を使います
Last sector, +sectors or +size{K,M,G} (2099200-104857599, 初期値 104857599): 
初期値 104857599 を使います
Partition 2 of type Linux and of size 49 GiB is set

wコマンドでテーブルの変更を保存して終了

コマンド (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)
ディスクを同期しています。

再起動します

# reboot

パーティションの物理ボリュームのサイズを変更
(pvresize -> physical volume resize)

# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

パーティションの論理ボリュームのサイズを変更
(lvextend -> logical volume extend)

# lvextend -l +100%FREE /dev/centos/root
  New size (12338 extents) matches existing size (12338 extents).

XFSファイルシステムのサイズを拡張

# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=32, agsize=406016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=12634112, 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

df -hで確認
サイズが増えているはずです!

# df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
devtmpfs                  5.3G     0  5.3G    0% /dev
tmpfs                     5.3G     0  5.3G    0% /dev/shm
tmpfs                     5.3G  9.5M  5.3G    1% /run
tmpfs                     5.3G     0  5.3G    0% /sys/fs/cgroup
/dev/mapper/centos-root    49G  6.4G   42G   14% /
/dev/sda1                1014M  239M  776M   24% /boot
tmpfs                     1.1G   28K  1.1G    1% /run/user/1000
0
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
0
1