[NTLUG:Discuss] Resizing Linux partitions

Chris Cox cjcox at acm.org
Mon Jun 18 16:34:03 CDT 2007


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?

While ext2/3 supposedly support online resizing, my experience shows
that it is deficient in that most of the time you have to do an
fsck first... and on a large filesystem, that could take an entire
day or more (e.g. say the filesystem is 7TB or so).  Even then
it's not guaranteed to work and has numerous limitations.

With that said, reiserfs supports almost instantaneous resizing
even when online and in use.  This is excellent for environments
that need to add disk FAST (very dynamic environments).

In either case, it's wise to use LVM.  LVM is a storage
abstraction.  Whole disks or individual partitions are set
aside as Physical Volumes which can belong to a Volume Group.
Then you create Logical Volumes from the Volume Group.  The
LVs are where the filesystem will reside.  Thus an LV is
just a logical area which could be spanning multiple
drives and/or partitions.

This actually has several benefits (some not as useful as
they used to be).

1. An LV has a name, it is a fixed name.  For example, an
LV called lv1 could be a part of a VG called vg1 and the
device to access it would be called /dev/vg1/lv1.  This
avoids issues where new devices change the default naming
of disk devices (e.g. where /dev/hdb suddenly becomes /dev/hdc).
This isn't such a big deal now that we have persistent
naming through /dev/disk/by-id.  But it was certainly
better than relying on ext2's disk labeling technique and
of course it worked across all filesystem types.

# pvcreate /dev/sda /dev/sdb1 /dev/hda3
(says the entire drive /dev/sda as well as /dev/sdb1 and
/dev/hda3 are Physical Volumes)

# vgcreate vg1 /dev/sda /dev/hda3
(says create a VG called vg1 which consists of the two
PVs listed)

# vgcreate vg2 /dev/sdb1
(another VG called vg2)

# lvcreate -n lv1 -L 5G vg1
(create an LV called lv1 out of the VG vg1 that is 5G in size)

# mkreiserfs /dev/vg1/lv1
(create a reiserfs on it)

The name /dev/vg1/lv1 will always be called that even
if the ordering of the disks of the PVs changes.

2. An LV can be resized easily.  Unlike a partition which
is a contiguous area on a drive, an LV is an abstraction
of area(s) across drives and partitions.  So you can resize
it very easily.  Unlike ext2/3, reiserfs is easily resized
even if mounted.

# lvextend +10G /dev/vg1/lv1
(that adds 10G to the LV)

# resize_reiserfs /dev/vg1/lv1
(this filesystem will now be approximately 15G in size)
Note: /dev/vg1/lv1 could be mounted while doing all of this

3. Physical volumes can be manipulated.  As long as there
is enough PV space inside of a VG, you can use the pvmove
command to move all logical data areas off of a particular
PV so that it could be removed from the system.  Let's say
that I don't like the fact that I'm using /dev/hda3, I could
do:

# pvmove -v /dev/hda3

I could then remove /dev/hda3 from the vg1 volume group.

=========

There are other benefits such as snapshotting that can be
used as well if you use LVM without having to have that
support built into the filesystem.  In many ways, LVM gives
you many of the features of ZFS except it is filesystem
agnostic.

So... LVM is a good thing if you think you want to
resize partitions.  Reiserfs is the most flexible
with regards to resizing.  JFS is also ok... but only
does meta-data journaling (like reiserfs used to do) and
only supports growing the filesystem.  XFS also allows
a filesystem to be grown and it requires the filesystem
to be online/mounted (similar requirement for JFS).  One
day I'll actually trust XFS (sigh).

Ext2/3/4 are difficult to resize due to their architecture
(they're not designed for this).

Shrinking a filesystem requires a filesystem to be unmounted
and you could really nuke yourself if you don't understand
what you are doing.

Because of Hans' legal battles and SUSE's changing to ext3,
many are wary of using reiserfs.  However, in my own testing,
it's the best one if you need good performance and the flexibility
of growing filesystems on the fly under LVM.  Time will tell
if another filesystem (e.g. JFS or XFS) will prove to be
a better option.  Ext2/3/4 are all based off of old filesystem
strategies and will NOT be able to satisfy this need (sorry).





More information about the Discuss mailing list