LoginSignup
2
0

More than 3 years have passed since last update.

VirtualBox上のCentOS7のHDDサイズを拡張したい

Posted at

TL;DR(要約)

仮想CentOS7の容量を拡張するには

  1. VirtualBoxの仮想メディアマネージャーで.vdiファイルのサイズを拡張
  2. Gpartedでパーティションを拡張
  3. lvextendで論理ボリュームの拡張
  4. xfs_growfsでファイルシステムの拡張

です。

背景

仮想で運用しているCentOSの容量が足りなくなったので拡張したい。
で、Ubuntuではやったことあるのでいつも通りVirtualboxの仮想メディアマネージャーからサイズを変更して、GPartedでパーティションも切りなおしたのに。
あれ、なんで容量が増えてないの?


TL;DRに到るまでのメモ

gpart.jpg

GPartedで見ると /dev/sda1/dev/sda2が確認できます。
拡張したのは/dev/sda2/なので、まずはどう認識されているのかをmountコマンドで確認します。

# あれ、/dev/sda2がないぞ...?
[admin@localhost ~]$ mount | grep sda
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

# / をマウントしてるのは /dev/mapper/centos-root となっている。何これ?
[admin@localhost ~]$ mount | grep cent
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

/ にマウントされている /dev/mapper/centos-rootが何者かわからなかったので調べてみたところ、LVMという仕組みがあるらしい。
パーティションの拡張はできたけど、論理ボリュームの設定ができていないからサイズが拡張されていないのか。ふむ。

lvdsiplayvgdisplay で状況を確認。

[admin@localhost ~]$ sudo lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                agK4Ww-ON0a-xLf2-umr2-cm7h-RJ31-JYSkHS
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-12 20:57:21 +0900
  LV Status              available
  # open                 2
  LV Size                820.00 MiB
  Current LE             205
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                KNzEAM-AzBI-jLvl-6dA3-Y8fV-jDMJ-IisdoN
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-12 20:57:21 +0900
  LV Status              available
  # open                 1
  LV Size                <6.20 GiB # ← 現在のサイズ。ここを拡張したい。
  Current LE             1586
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[admin@localhost ~]$ sudo vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <39.00 GiB # ← ここまでは拡張できる
  PE Size               4.00 MiB
  Total PE              9983
  Alloc PE / Size       1791 / <7.00 GiB
  Free  PE / Size       8192 / 32.00 GiB
  VG UUID               UpCTuz-OvY3-Gw5k-a6FK-zlwv-mz0b-meXy0p

lvextendコマンドで追加する論理ボリューム容量を指定できるみたいなので、とりあえず30GB追加。
その後 xfs_growfs でファイルシステムの拡張をして完了です。

[admin@localhost ~]$ sudo lvextend -L +30G /dev/centos/root 
[sudo] admin のパスワード:
  Size of logical volume centos/root changed from <6.20 GiB (1586 extents) to <36.20 GiB (9266 extents).
  Logical volume centos/root successfully resized.


[admin@localhost ~]$ sudo lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                agK4Ww-ON0a-xLf2-umr2-cm7h-RJ31-JYSkHS
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-12 20:57:21 +0900
  LV Status              available
  # open                 2
  LV Size                820.00 MiB
  Current LE             205
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                KNzEAM-AzBI-jLvl-6dA3-Y8fV-jDMJ-IisdoN
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-06-12 20:57:21 +0900
  LV Status              available
  # open                 1
  LV Size                <36.20 GiB # ← 6.20GiBから36.20GiBまで増えました!
  Current LE             9266
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

# まだファイルシステムの拡張はされていないので、`/dev/mapper/centos-root`のサイズは6.2Gのまま。

[admin@localhost ~]$ df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos-root   6.2G  4.6G  1.7G   74% /
devtmpfs                  908M     0  908M    0% /dev
tmpfs                     920M     0  920M    0% /dev/shm
tmpfs                     920M  8.6M  911M    1% /run
tmpfs                     920M     0  920M    0% /sys/fs/cgroup
/dev/sda1                1014M  189M  826M   19% /boot
tmpfs                     184M     0  184M    0% /run/user/0
tmpfs                     184M     0  184M    0% /run/user/1001
[admin@localhost ~]$ 

[admin@localhost ~]$ sudo xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=406016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1624064, 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 1624064 to 9488384

# ファイルシステムの拡張も終わったので、`/dev/mapper/centos-root`のサイズは37Gのまま。

[admin@localhost ~]$ df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos-root    37G  4.6G   32G   13% /
devtmpfs                  908M     0  908M    0% /dev
tmpfs                     920M     0  920M    0% /dev/shm
tmpfs                     920M  8.6M  911M    1% /run
tmpfs                     920M     0  920M    0% /sys/fs/cgroup
/dev/sda1                1014M  189M  826M   19% /boot
tmpfs                     184M     0  184M    0% /run/user/0
tmpfs                     184M     0  184M    0% /run/user/1001

参考

2
0
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
0