LoginSignup
0
1

More than 5 years have passed since last update.

【CentOS7】クラウドや仮想マシン上でディスク拡張したときのファイルシステム拡張手順

Last updated at Posted at 2018-10-19

はじめに

クラウドや仮想マシンで既存ディスクを拡張し、CentOS7上でファイルシステム拡張を行ったときの手順。

環境

[クラウド]:ECL2.0(NTTコミュニケーションズ)
[OS]:CentOS Linux release 7.3.1611 (Core)
[SSHツール]:Tera Term 4.86

手順

現状確認。

filename.rb
[root@hostname ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   20G  1.2G   19G   6% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.4M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vdb1                493G  461G  9.1G  99% /data
/dev/vda1                497M  132M  366M  27% /boot
tmpfs                    383M     0  383M   0% /run/user/1001
[root@hostname ~]#

今回は、ファイルシステム「/dev/vdb1」を500GB -> 1,024GBに拡張する。

まず、クラウドや仮想マシン上でディスクの拡張を行います。
既存ディスク:500GB -> 拡張後:1,024GB
(クラウド作業は省略)

サーバーにログインし、拡張したディスクを確認します。

filename.rb
[root@hostname ~]# fdisk -l

#~省略~

Disk /dev/vdb: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe0a08c6e

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048  1048575999   524286976   83  Linux

#~省略~

Disk /dev/vdb: 1099.5 GB ←クラウド上で拡張したサイズが認識されています。

fdiskコマンドで、パーティションを操作します。

filename.rb
[root@hostname ~]# fdisk /dev/vdb
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.


Command (m for help):

次に、パーティションテーブルを表示します。

filename.rb
Command (m for help): p

Disk /dev/vdb: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe0a08c6e

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048  1048575999   524286976   83  Linux

Command (m for help):

パーティションを削除します。

filename.rb
Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help):

新しいパーティションを作成します。

filename.rb
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):

ここでは、デフォルト(すべてエンターキー)で進めています。

filename.rb
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-2147483647, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2147483647, default 2147483647):
Using default value 2147483647
Partition 1 of type Linux and of size 1024 GiB is set

Command (m for help):

パーティションテーブルの変更を保存して終了します。

filename.rb
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.
[root@hostname ~]#

再起動して、パーティションテーブルの変更を反映させます。

filename.rb
[root@hostname ~]# shutdown -r now

再起動後、resize2fsコマンドで、ファイルシステムを拡張します。

filename.rb
[root@hostname ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vdb1 is mounted on /data; on-line resizing required
old_desc_blocks = 63, new_desc_blocks = 128
The filesystem on /dev/vdb1 is now 268435200 blocks long.

[root@hostname ~]#

ファイルシステムが拡張されたか確認する。

filename.rb
[root@hostname ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   20G  1.2G   19G   6% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.4M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vdb1               1008G  461G  504G  48% /data
/dev/vda1                497M  132M  366M  27% /boot
tmpfs                    383M     0  383M   0% /run/user/1001
[root@hostname ~]#

今回対象の「/dev/vdb1」が拡張されている。

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