[Novalug] resize ext3 w/o losing data
Michael Stone
mstone at mathom.us
Wed Jan 10 09:14:15 EST 2007
On Wed, Jan 10, 2007 at 08:48:48AM -0500, gregory pryzby wrote:
>This is about resizing without losing data. This is step by step on
>how to resize with all the steps so those who aren't as savvy as to
>what is going on can resize w/ confidence (some) that the data won't
>be lost.
And as far as building confidence goes, I don't think adding
scary-sounding (spurious) warnings furthers that goal. E.g., (apart from
the ext3 issue) there was a note to make sure you don't specify too
small a value to resize2fs or you'll lose data--in fact, resize2fs won't
let you do that. Where you *can* lose data is in the repartitioning
step. The best approach to avoiding that is to resize your filesystem to
a smaller value than desired (e.g., 3G instead of 4G), partition to the
desired size, reboot if necessary--not necessary on lvm, then run
resize2fs /devname without any arguments (which grows the filesystem to
the partition size). That way you don't have to worry about stupid
off-by-one errors and such. The whole sequence is much less error prone
if you are using an lvm. E.g.:
resize2fs /dev/vg0/foo 3G
lvextend -L 4G /dev/vg0/foo
resize2fs /dev/vg0/foo
-- no possibility of math errors in fdisk, which is the part most likely
to kill you. Expanding up is even easier:
lvextend -L +1G /dev/vg0/foo
resize2fs /dev/vg0/foo
(the +1G syntax just adds that much space) Depending on your kernel
version you can even do that without unmounting (if using ext3). And if
your kernel doesn't support online resizing, resize2fs will tell you
that, also! The tool is actually fairly safe, with a lot of safeguards
and prompting built in. (E.g., in some cases you need to run fsck--it'll
tell you how.) That said, filesystem resizing is inherently somewhat
risky and it is best to have backups--but it's best to have backups
anyway... :-) Also older versions of resize2fs might not have had all
the safeguards built in. Run resize2fs --version to make sure you're
running something fairly recent. (I know at least 1.37 wouldn't let me
do anything bad when I tested it just now.)
Mike Stone
More information about the Novalug
mailing list