Resize EXT3 Filesystem part 2

Table of Contents

Intro

If you read part 1 of Resize EXT3 Filesystem you should have a good understanding of how to shrink a Filesystem the manual way in Linux, in part 2 I will cover the process of Expanding a Filesystem which would be seen a lot more in a real life environment.

Expanding

If you recall from Shrinking we had to in theory go backwards in the process (Shrink Filesystem first then the partition), however when Expanding we will want to do the opposite (Increase the size of the Partition, then resize the Filesystem).

You will first want to identify your Filesystem which can be easily done using df.

# df -h /dev/hda1
Filesystem            Size  Used Avail Use% Mounted on
-                     252M   80K  252M   1% /dev

Now that we know which disk we want to alter we can open the disk using fdisk and have a look at the partitions.

Knowing we have some unused space lets go ahead and reclaim it by recreating the Partition by starting at the same cylinder and ending a the last available.

Command (m for help): d       
Partition number (1-4): 1

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

Command (m for help): p

Disk /dev/hda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1          13      104391   83  Linux
/dev/hda2              14         652     5132767+  8e  Linux LVM

After verifying the output above looks good we can save the new partition table using w and run partprobe to have the kernel reread the partition table.

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

Calling ioctl() to re-read partition table.

The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@redhat ~]# partprobe 

Like before we should first run a fsck on the filesystem before resizing.

# e2fsck -f /dev/hda1
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
/boot: 15/8032 files (6.7% non-contiguous), 5910/25600 blocks

And as the fsck came be fine we can resize the Filesystem.

# resize2fs /dev/hda1 
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/hda1 to 104388 (1k) blocks.
The filesystem on /dev/hda1 is now 104388 blocks long.

All that is left now is to mount the filesystem and be sure it has been resized.

[root@redhat ~]# mount /dev/hda1 /mnt/

[root@redhat ~]# df -h /dev/hda1
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1              99M  5.6M   90M   6% /mnt

And as we wanted all our data is still available and intact.

# ls -l /mnt/
total 7
-rw-r--r-- 1 root root    4 Mar  1 02:58 data
-rw-r--r-- 1 root root    4 Mar  1 02:58 file
-rw-r--r-- 1 root root    4 Mar  1 02:59 info
drwx------ 2 root root 1024 Mar  1 03:20 lost+found

Author: Jeffrey Ness <jness@flip-edesign.com>

Date: 2010-04-15 12:12:29 CDT

HTML generated by org-mode 6.21b in emacs 23