0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

partedコマンドによるディスクパーティション拡張(AlmaLinux8.8/9.4)

Posted at

partedコマンドを利用してディスクパーティションを拡張します。

image.png

環境

# cat /etc/redhat-release
AlmaLinux release 8.8 (Sapphire Caracal)
# cat /etc/redhat-release
AlmaLinux release 9.4 (Seafoam Ocelot)
vmware ESXi イメージ プロファイル	
ESXi-8.0U1a-21813344-standard (VMware, Inc.)

流れ

事前確認
物理ディスク拡張
パーティション拡張
ファイルシステム拡張

0.事前確認

ディスク拡張前の事前確認を行います。
lsblk -ia 物理ディスク情報確認
df -h ファイルシステム情報確認
parted -l パーティション情報確認

# lsblk -ia
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   16G  0 disk 
|-sda1   8:1    0  600M  0 part /boot/efi
|-sda2   8:2    0    1G  0 part /boot
|-sda3   8:3    0 12.4G  0 part /
`-sda4   8:4    0    2G  0 part [SWAP]
sdb      8:16   0    5G  0 disk 
|-sdb1   8:17   0    1G  0 part /home
`-sdb2   8:18   0    4G  0 part /data
sr0     11:0    1 1024M  0 rom  
# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         4.0M     0  4.0M    0% /dev
tmpfs            888M     0  888M    0% /dev/shm
tmpfs            356M  5.1M  351M    2% /run
/dev/sda3         13G  1.6G   11G   13% /
/dev/sda2        960M  210M  751M   22% /boot
/dev/sda1        599M  7.1M  592M    2% /boot/efi
/dev/sdb2        4.0G   61M  3.9G    2% /data
/dev/sdb1        960M   39M  922M    5% /home
tmpfs            178M     0  178M    0% /run/user/0
# parted -l
モデル: VMware Virtual disk (scsi)
ディスク /dev/sda: 17.2GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt
ディスクフラグ: 

番号  開始    終了    サイズ  ファイルシステム  名前                  フラグ
 1    1049kB  630MB   629MB   fat32             EFI System Partition  boot, esp
 2    630MB   1704MB  1074MB  xfs
 3    1704MB  15.0GB  13.3GB  xfs
 4    15.0GB  17.2GB  2198MB  linux-swap(v1)                          swap


モデル: VMware Virtual disk (scsi)
ディスク /dev/sdb: 5369MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt
ディスクフラグ: 

番号  開始    終了    サイズ  ファイルシステム  名前  フラグ
 1    1049kB  1075MB  1074MB  xfs
 2    1075MB  5368MB  4293MB  xfs

当該領域にデータ保持確認用のファイル等も保存しておきます。

# ll /data
合計 0
drwxr-xr-x. 2 root root 45 12月  7 21:06 test1
drwxr-xr-x. 2 root root  6 12月  7 21:05 test2
drwxr-xr-x. 2 root root  6 12月  7 21:05 test3

# ll -h /data/test1
合計 382M
-rw-r--r--. 1 root root 1.7K 12月  7 21:05 file1
-rw-r--r--. 1 root root  297 12月  7 21:06 file2
-rw-r--r--. 1 root root 382M 12月  7 21:06 file3

1.物理ディスク拡張

OSを停止し、物理ディスクの拡張を行います。
本環境ではvmware ESXiからディスク拡張を行います。

ディスク拡張前
image.png


ディスク拡張後
image.png

vmware環境の場合、スナップショットを全て削除していない場合は以下のアラートが表示されます。
image.png


ディスク拡張後にOSを起動し、lsblkコマンドにて物理ディスク容量が増えていることを確認します。
本環境ではsdb5Gから10Gに拡張されました。

# lsblk -ia
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   16G  0 disk
|-sda1   8:1    0  600M  0 part /boot/efi
|-sda2   8:2    0    1G  0 part /boot
|-sda3   8:3    0 12.4G  0 part /
`-sda4   8:4    0    2G  0 part [SWAP]
sdb      8:16   0   10G  0 disk
|-sdb1   8:17   0    1G  0 part /home
`-sdb2   8:18   0    4G  0 part /data
sr0     11:0    1 10.1G  0 rom

CentOS7とは異なり、ディスクのアンマウントを行わなくとも以降の作業を実施可能です。

2.パーティション拡張

partedコマンドによるパーティション拡張を行います。

# parted /dev/sdb
GNU Parted 3.5
/dev/sdb を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。

拡張対象パーティションの番号を確認します。

(parted) print
モデル: VMware Virtual disk (scsi)
ディスク /dev/sdb: 10.7GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt
ディスクフラグ:

番号  開始    終了    サイズ  ファイルシステム  名前  フラグ
 1    1049kB  1075MB  1074MB  xfs
 2    1075MB  5368MB  4293MB  xfs

パーティションの拡張を行います。
resizepartコマンドにて、パーティション番号と拡張容量を指定します。100%で空き容量全体を割り当てます。

(parted) resizepart 2 100%
警告: パーティション /dev/sdb2 は使用中です。それでも実行しますか?
はい(Y)/Yes/いいえ(N)/No? Y

容量が拡張されたことを確認します。
終了が5368MBから10.7GBへ、サイズが4293MBから9663MBへ拡張されました。

(parted) print
モデル: VMware Virtual disk (scsi)
ディスク /dev/sdb: 10.7GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt
ディスクフラグ:

番号  開始    終了    サイズ  ファイルシステム  名前  フラグ
 1    1049kB  1075MB  1074MB  xfs
 2    1075MB  10.7GB  9663MB  xfs

quitでGNU Partedを終了します。

(parted) quit
通知: 必要であれば /etc/fstab を更新するのを忘れないようにしてください。
# 

3.ファイルシステム拡張

ディスクおよびパーティションに次いで、ファイルシステムも拡張します。

事前にファイルシステムサイズを確認します。

# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         4.0M     0  4.0M    0% /dev
tmpfs            888M     0  888M    0% /dev/shm
tmpfs            356M  5.1M  351M    2% /run
/dev/sda3         13G  1.6G   11G   13% /
/dev/sdb1        960M   39M  922M    5% /home
/dev/sdb2        4.0G  442M  3.6G   11% /data
/dev/sda2        960M  210M  751M   22% /boot
/dev/sda1        599M  7.1M  592M    2% /boot/efi
tmpfs            178M     0  178M    0% /run/user/0

xfs_growfsコマンドを利用してファイルシステムを拡張します。

# xfs_growfs /dev/sdb2
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=262016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=0
data     =                       bsize=4096   blocks=1048064, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1048064 to 2359035

dfコマンドにてファイルシステム容量を確認します。
4.0Gから9.0Gに拡張されました。

# df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
devtmpfs         4.0M     0  4.0M    0% /dev
tmpfs            888M     0  888M    0% /dev/shm
tmpfs            356M  5.1M  351M    2% /run
/dev/sda3         13G  1.6G   11G   13% /
/dev/sdb1        960M   39M  922M    5% /home
/dev/sdb2        9.0G  478M  8.5G    6% /data
/dev/sda2        960M  210M  751M   22% /boot
/dev/sda1        599M  7.1M  592M    2% /boot/efi
tmpfs            178M     0  178M    0% /run/user/0

拡張後にファイル等が残存していることも確認できました。

# ll /data
合計 0
drwxr-xr-x. 2 root root 45 12月  7 21:06 test1
drwxr-xr-x. 2 root root  6 12月  7 21:05 test2
drwxr-xr-x. 2 root root  6 12月  7 21:05 test3


# ll -h /data/test1
合計 382M
-rw-r--r--. 1 root root 1.7K 12月  7 21:05 file1
-rw-r--r--. 1 root root  297 12月  7 21:06 file2
-rw-r--r--. 1 root root 382M 12月  7 21:06 file3

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?