How do I expand / resize an ext3 file system in linux

The following is an example of increasing the size of a Storage LUN that has an ext3 file system on it. When performing operations like this, perform a backup of the file system first.

(The system used for this example is running Red Hat Enterprise Linux Server release 5 (Tikanga), kernel version is 2.6.18-8.el5PAE and EMC PowerPath (c) Version 5.1 SP 2 (build 21) installed.)

Lets look at the LUN and file system “pre-resize”:

# powermt display dev=emcpowera

Pseudo name=emcpowera

CLARiiON ID=CK200075000424 [Sunx4150_SG]

Logical device ID=6006016024D01E009286CA9A490DDE11 [LUN 39]

state=alive; policy=BasicFailover; priority=0; queued-IOs=0

Owner: default=SP B, current=SP B Array failover mode: 1

==============================================================================

— ————– Host ————— – Stor – — I/O Path – — Stats —

### HW Path I/O Paths Interf. Mode State Q-IOs Errors

==============================================================================

0 qla2xxx sda SP A5 active alive 0 0

0 qla2xxx sdc SP B4 active alive 0 0

# mount /dev/emcpowera1 /data03

# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sde5 20G 15G 4.0G 79% /

/dev/sde1 99M 17M 78M 18% /boot

/dev/sde3 97G 48G 44G 53% /data01

/dev/sde2 144G 108G 30G 79% /data02

/dev/sdb 730G 301G 393G 44% /cpe-backup

none 4.0G 0 4.0G 0% /dev/shm

/dev/emcpower1 197G 187G 673M 100% /data03

Step 1: Perform a backup of the file system.

Step 2: Unmount the file system.

# umount /data03

# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sde5 20G 15G 4.0G 79% /

/dev/sde1 99M 17M 78M 18% /boot

/dev/sde3 97G 48G 44G 53% /data01

/dev/sde2 144G 108G 30G 79% /data02

/dev/sdb 730G 301G 393G 44% /cpe-backup

none 4.0G 0 4.0G 0% /dev/shm

Step 3: Increase the size of the LUN using the backend array tools. In some cases, like with CLARiiON MetaLUN, this can actually be performed “online” in order to decrease the time that the file system is unavailable. However, just because the disk array can be done online that does not mean the application layer can handle online expansion (some file systems can handle online expansion, currently ext3 cannot).

Step 4: Use sfdisk -R to re-read the new partition size. The operating system has no idea that the LUN size has been increased because it was done by the array.

Lets look at it with fdisk first then re-read and look again.

# fdisk -l /dev/emcpowera

Disk /dev/emcpowera: 200 GB, 361278996480 bytes

255 heads, 63 sectors/track, 26108 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/emcpowera1 1 26108 209712478+ 83 Linux

Command (m for help): q (Quits out of fdisk)

# sfdisk -R /dev/emcpowera

# fdisk /dev/emcpowera

The number of cylinders for this disk is set to 43923.

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/emcpowera: 361.2 GB, 361278996480 bytes

255 heads, 63 sectors/track, 43923 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/emcpowera1 1 26108 209712478+ 83 Linux

Command (m for help): q

Step 5: Use fdisk to remove the existing file system partition and recreate a new larger partition. Now we need to increase the size of the partition that our file system lives on. Even though our LUN is bigger the partition still starts at cylinder 1 and ends at cylinder 26108.

# fdisk /dev/emcpowera

The number of cylinders for this disk is set to 43923.

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/emcpowera: 361.2 GB, 361278996480 bytes

255 heads, 63 sectors/track, 43923 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/emcpowera1 1 26108 209712478+ 83 Linux

Command (m for help): d

Selected partition 1

Command (m for help): p

Disk /dev/emcpowera: 361.2 GB, 361278996480 bytes

255 heads, 63 sectors/track, 43923 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-43923, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-43923, default 43923):

Using default value 43923

Command (m for help): p

Disk /dev/emcpowera: 361.2 GB, 361278996480 bytes

255 heads, 63 sectors/track, 43923 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/emcpowera1 1 43923 352811466 83 Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

# fdisk -l /dev/emcpowera

Disk /dev/emcpowera: 361.2 GB, 361278996480 bytes

255 heads, 63 sectors/track, 43923 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/emcpowera1 1 43923 352811466 83 Linux

Step 6: Perform a file system check with e2fsck. This file system check step is required before performing resize2fs.

# e2fsck -f /dev/emcpowera1

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

LUN39: 69643/26214400 files (2.0% non-contiguous), 49634603/52428119 blocks

Step 7: Expand the file system with resize2fs.

# resize2fs /dev/emcpowera1

resize2fs 1.39 (29-May-2006)

Resizing the filesystem on /dev/emcpowera1 to 88202866 (4k) blocks.

The filesystem on /dev/emcpowera1 is now 88202866 blocks long.

Step 8: Now mount the file system and check out the new size.

# mount /dev/emcpowera1 /data03

# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sde5 20G 15G 4.0G 79% /

/dev/sde1 99M 17M 78M 18% /boot

/dev/sde3 97G 48G 44G 53% /data01

/dev/sde2 144G 108G 30G 79% /data02

/dev/sdb 730G 456G 238G 66% /cpe-backup

none 4.0G 0 4.0G 0% /dev/shm

/dev/emcpowera1 332G 187G 132G 59% /data03

Leave a Comment

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top