CentOS / RHEL : Resize (extend) non-root EXT3/4 filesystem on non-LVM device (hard disk partition)

Feasibility of filesystem resize (extend)

The underlying device (partition in our case) upon which an EXT3/4 filesystem resides must first be resized before the filesystem can be resized. Accordingly, the feasibility of underlying device resize must first be established to determine whether filesystem resize is possible.
The following conditions/scenarios make it feasible to resize (extend) an EXT3/4 filesystem:

  1. The EXT3/4 filesystem resides on a device/partition but does not fully occupy the entire space within the partition and sufficient disk space exists between the end of the filesystem and partition end boundary.
  2. The EXT3/4 filesystem resides on a device/partition occupying the entire partition space, however sufficient, contiguous free blocks exist on the disk/device immediately after the filesystem partition end boundary and either the
    • next partition start boundary or
    • end of entire disk/device)

Backup all data on filesystem to be resized

Resizing a filesystem and underlying devices is dangerous and potentially destructive if performed incorrectly. Repartitioning devices is similarly destructive and may result in complete data loss. Before proceeding, backup the contents of the filesystem/device to be resized.

Resizing (extending) non-root filesystem on hard disk partition (non-LVM)

1. Sample setup
In this example, device /dev/sdb (20Gb) contains a single primary partition (/dev/sdb1) of 11Gb with an EXT3/4 filesystem (/data) that spans the entire partition.
Approximately 9Gb of free disk space exists between the end of the partition and end of the device.

# df -k /data
Filesystem          1K-blocks      Used Available Use% Mounted on
/dev/sdb1            11353328  10668192    223764  98% /data
# cat /proc/partitions | grep sdb
   8    16   20971520 sdb
   8    17   12008556 sdb1
# fdisk -l /dev/sdb

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1495 12008556 83 Linux

2. Unmount filesystem to be resized
Umount the filesystem to be resized e.g.:

# umount /data

3. Perform a filesystem check
Verify the filesystem type of the filesystem to be resized.

# blkid /dev/sdb1
/dev/sdb1: LABEL="/data" UUID="1fc0bbcd-ba86-40b6-b562-5da90fb0d7af" TYPE="ext3"

Perform a filesystem check of the filesystem ensuring to use the corresponding filesystem check utility (fsck.ext3, fsck.ext4) for the filesystem type e.g.:

# fsck.ext3 -fy /dev/sdb1
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
data: 21/1441792 files (4.8% non-contiguous), 2712300/2883584 blocks

4. Resize (extend) the partition
This step assumes free disk space exists between the end of the partition and end of the device. If free diskspace is unavailable, engage your Storage Administrator to grow/extend the underlying device before re-creating a larger partition. Use the fdisk utility to delete then recreate a larger partition, ensuring the re-use the original partition start block e.g. :

# fdisk /dev/sdb

The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 1495 12008556 83 Linux

Command (m for help): d       ### this step deletes the partition
Selected partition 1

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): [enter]
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): [enter]
Using default value 2610

Command (m for help): p

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.

5. Verify partition resize
Verify that the system can now see the newly created larger partition e.g.:

# cat /proc/partitions | grep sdb
   8    16   20971520 sdb
   8    17   20964793 sdb1

If the system fails to detect the new partition sizing, run the partprobe utility against the resized device e.g.:

# partprobe /dev/sdb

6. Resize (extend) the filesystem
Use the resize2fs utility to extend the EXT3/4 filesystem to utilise the additional space in the partition e.g.:

# resize2fs /dev/sdb1
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/sdb1 to 5241198 (4k) blocks.
The filesystem on /dev/sdb1 is now 5241198 blocks long.
Note: when running resize2fs, if no size is specified, the filesystem will be extended to utilise all available/remaining space in the partition.

6. Perform a filesystem check
Perform a filesystem check of the resized EXT3/4 filesystem ensuring to use the corresponding filesystem check utility (fsck.ext3, fsck.ext4) for the filesystem type in use e.g.:

# fsck.ext3 -fy /dev/sdb1
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
data: 21/2621440 files (4.8% non-contiguous), 2750333/5241198 blocks

7. Mount the resized filesystem
Mount the newly resized EXT3/4 filesystem e.g.:

# mount /data

8. Verify filesystem resize
Review dmesg, messages log, etc. to verify successful filesystem resize e.g.:

# df -h /data
Filesystem         Size Used Avail Use% Mounted on
/dev/sdb1           20G  11G  9.0G  54% /data
Related Post