How to increase ext3/ext4 disk partition in Linux, which is not on LVM ?
In this post, we will see how to increase ext filesystem partition in Linux manually when the filesystem is created directly on block device instead of LVM.
Increase Partition size directly on block device
1. Check current size of the block device
[root@ngelinux ~]# df -h /dev/sdb2 Filesystem Size Used Avail Use% Mounted on /dev/sdb2 976M 1.3M 924M 1% /testext [root@ngelinux ~]# ls -l /testext/ total 20 drwx------. 2 root root 16384 Mar 28 01:32 lost+found -rw-r--r--. 1 root root 6 Mar 29 02:52 testfile [root@ngelinux ~]# cat /testext/testfile hello
2. Umount and increase the partition size.
[root@ngelinux ~]# umount /testext/ [root@ngelinux ~]# parted /dev/sdb GNU Parted 3.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 8590MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 2 1049kB 1075MB 1074MB primary ext3 (parted) resizepart 2 2048MB (parted) p Model: ATA VBOX HARDDISK (scsi) Disk /dev/sdb: 8590MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 2 1049kB 2048MB 2047MB primary ext3 (parted) q Information: You may need to update /etc/fstab.
3. Character device size in increased, now increase the block device size.
[root@ngelinux ~]# e2fsck -f /dev/sdb2 -y e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizes Inodes that were part of a corrupted orphan linked list found. Fix? yes Inode 32812 was part of the orphaned inode list. FIXED. Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdb2: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdb2: 12/65536 files (0.0% non-contiguous), 12645/262144 blocks [root@ngelinux ~]# resize2fs /dev/sdb2 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/sdb2 to 499744 (4k) blocks. The filesystem on /dev/sdb2 is now 499744 blocks long.
4. Mount the partition back.
[root@ngelinux ~]# mount -a [root@ngelinux ~]# df -h /dev/sdb2 Filesystem Size Used Avail Use% Mounted on /dev/sdb2 1.9G 1.6M 1.8G 1% /testext [root@ngelinux ~]# ls -l /testext/ total 20 drwx------. 2 root root 16384 Mar 28 01:32 lost+found -rw-r--r--. 1 root root 6 Mar 29 02:52 testfile [root@ngelinux ~]# cat /testext/testfile hello [root@ngelinux ~]#
As we can see above, the filesystem size in increased to around 2GB, from 1GB and that the file content is intact i.e. there is no data loss observed.
The tip in above tutorial is the usage of parted and resize2fs command for increasing the partition size.