2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

データを保持したままのパーティションの拡張 (非LVM環境、ext4)

Posted at

前提条件

拡張するパーティションの後ろに空き領域が必要。
要するに対象のパーティションのすぐ後ろの領域に他のパーティションが存在する場合は無理。
また、作業前にはバックアップを行うこと。

#1.現在のサイズや存在するファイルを確認

$ df -hT /testdir/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      ext4  9.1G   37M  8.6G   1% /testdir
$ ll /testdir/
total 316
-rw-r--r-- 1 root root 100000 Jul  4 21:56 file1
-rw-r--r-- 1 root root 100000 Jul  4 21:56 file2
-rw-r--r-- 1 root root 100000 Jul  4 21:56 file3
drwx------ 2 root root  16384 Jul  4 21:55 lost+found

#2.パーティションテーブルを確認

$ parted /dev/sdb u s p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 41943040s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start  End        Size       Type     File system  Flags
 1      2048s  19531775s  19529728s  primary  ext4
        ^^^^^★開始セクタが後述の作業で必要になる
$

#3.アンマウント

$ umount  /testdir/

#4.パーティションの削除

$ parted /dev/sdb rm 1
Information: You may need to update /etc/fstab.

$ parted /dev/sdb u s p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 41943040s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start  End  Size  Type  File system  Flags

#5.パーティションの再作成

$ parted -s /dev/sdb mkpart primary 2048s 100%
$                                   ^^^^^★必ず「2.」で確認した開始セクタを入力すること
$ parted /dev/sdb u s p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 41943040s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start  End        Size       Type     File system  Flags
 1      2048s  41943039s  41940992s  primary  ext4

$ parted /dev/sdb u GB p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      0.00GB  21.5GB  21.5GB  primary  ext4

#6.ファイルシステムチェック及びファイルシステムの拡張

$ e2fsck /dev/sdb1
e2fsck 1.42.9 (28-Dec-2013)
/dev/sdb1: clean, 14/610800 files, 80417/2441216 blocks
$ resize2fs -f /dev/sdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sdb1 to 5242624 (4k) blocks.
The filesystem on /dev/sdb1 is now 5242624 blocks long.

#7.拡張後のサイズや存在するファイルを確認

$ mount /dev/sdb1 /testdir/
$  df -hT /testdir/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      ext4   20G   45M   19G   1% /testdir
$ ll /testdir/
total 316
-rw-r--r-- 1 root root 100000 Jul  4 21:56 file1
-rw-r--r-- 1 root root 100000 Jul  4 21:56 file2
-rw-r--r-- 1 root root 100000 Jul  4 21:56 file3
drwx------ 2 root root  16384 Jul  4 21:55 lost+found
$

参考情報

How can I extend an existing file-system partition without destroying data?
https://access.redhat.com/solutions/29095

How to extend a logical volume and its filesystem online in Red Hat Enterprise Linux?
https://access.redhat.com/solutions/24770

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?