[NTLUG:Discuss] Resizing Linux partitions

Robert Citek robert.citek at gmail.com
Mon Jun 18 12:27:56 CDT 2007


On 06/15/2007 07:32 PM, Leroy Tennison wrote:
> No big deal since is was a test partition anyway, just some time 
> wasted.  However, I am now very curious as to how you are supposed to go 
> about resizing both ext3 and reiserfs partitions.  Anyone have good 
> success with this using any non-commercial program?

Just to clarify, there is a difference between a filesystem and a
partition.  Partitions contain filesystems.  Put another way, a
filesystem resides inside a partition.  That distinction is important
because you can resize a filesystem without resizing the partition
containing it and vice-versa.  That is, you can shrink a filesystem so
that it is much smaller than the partition containing it.  Also, you can
expand a partition without expanding the filesystem.  Most filesystem
resizing tools prevent the obvious problem of expanding a filesystem
beyond the partition boundary.  However, most partitioning tools do not
prevent the problem of shrinking a partition below the filesystem size
(e.g. fdisk).

Filesystem resizers:
 - ext2/3 : resize2fs
 - ntfs : ntfsresize
 - reiserfs: resize_reiserfs

Partition resizers (any disk partitioning tool):
 - fdisk
 - parted

Tools that do both:
 - qtparted (gui)
 - gparted (gui)

The tools that do both use some combination of the filesystem and
partitioning tools behind the scenes, giving the appearance of "resizing
a linux partition."

BTW, you can play with resizing a filesystem using just files.  For
example, here's how to create an ext3 filesystem within a file, shrink
the filesystem without shrinking the file, grow the filesystem, grow the
file without growing the filesystem, and grow the filesystem:

$ dd if=/dev/zero of=ext3.img bs=1M count=10

$ ls -la --si ext3.img
-rw-r--r-- 1 rwcitek rwcitek 11M 2007-06-18 12:20 ext3.img

$ mkfs.ext3 -q ext3.img
ext3.img is not a block special device.
Proceed anyway? (y,n) y

$ e2fsck -n ext3.img
e2fsck 1.38 (30-Jun-2005)
ext3.img: clean, 11/2560 files, 1372/10240 blocks

$ resize2fs -f ext3.img  1372
resize2fs 1.38 (30-Jun-2005)
Resizing the filesystem on ext3.img to 1372 (1k) blocks.
The filesystem on ext3.img is now 1372 blocks long.

$ e2fsck -n ext3.img
e2fsck 1.38 (30-Jun-2005)
ext3.img: clean, 11/1280 files, 1208/1372 blocks

$ resize2fs -f ext3.img
resize2fs 1.38 (30-Jun-2005)
Resizing the filesystem on ext3.img to 10240 (1k) blocks.
The filesystem on ext3.img is now 10240 blocks long.

$ e2fsck -n ext3.img
e2fsck 1.38 (30-Jun-2005)
ext3.img: clean, 11/2560 files, 1372/10240 blocks

$ dd if=/dev/zero bs=1M count=10 >> ext3.img
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.037845 seconds, 277 MB/s

$ ls -la --si ext3.img
-rw-r--r-- 1 rwcitek rwcitek 21M 2007-06-18 12:23 ext3.img

$ resize2fs -f ext3.img
resize2fs 1.38 (30-Jun-2005)
Resizing the filesystem on ext3.img to 20480 (1k) blocks.
The filesystem on ext3.img is now 20480 blocks long.

$ e2fsck -n ext3.img
e2fsck 1.38 (30-Jun-2005)
ext3.img: clean, 11/3840 files, 1534/20480 blocks

HTH.

Regards,
- Robert




More information about the Discuss mailing list