Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#297381 - 19/04/2007 17:02 Another easy question for the linux oracle
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3583
Loc: Columbus, OH
What's the easiest way to resize one's root partition?

I put a new 320 gig hard disk in a RHEL3 server and cloned the old 20 gig disk. Unfortunately, the partitions are all the same size that they were before. Is parted the right (and easiest?) tool to use for an ext3 partition? Do I need to boot from a livecd or something of the sort to resize the root partition?

Thanks
_________________________
~ John

Top
#297382 - 19/04/2007 17:45 Re: Another easy question for the linux oracle [Re: JBjorgen]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Not as easy as one would hope.

Depends on a lot of things. I assume that you cloned the entire disk and not partition-by-partition. That being the case, assuming that your root filesystem is not the last partition on the disk (by geometry), it's probably going to be easier to start over, if you can.

Basically, the idea is that you first need to expand the partition the filesystem is on, then you need to expand the filesystem itself. Expanding the partition means that you have to have free space directly after the existing partition. If it's not the last partition on there, then that means you have to move the other partitions, and that means nearly as much data writing as starting over, with the added advantage of doing things in kind of a hacky manner.

Before I go any further, let me know if you don't have the original disk anymore or if there's some other reason you don't want to start over.
_________________________
Bitt Faulk

Top
#297383 - 19/04/2007 18:16 Re: Another easy question for the linux oracle [Re: wfaulk]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3583
Loc: Columbus, OH
It's a production server with a whole lot of stuff on it. I definitely can't start over.

Code:

# fdisk -l /dev/hda

Disk /dev/hda: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 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 1288 10241437+ 83 Linux
/dev/hda3 1289 7476 49705110 83 Linux

# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda3 48925140 42017600 4422288 91% /
/dev/hda1 101089 9267 86603 10% /boot
/dev/hda2 10080520 2591256 6977196 28% /usr
none 240600 0 240600 0% /dev/shm

_________________________
~ John

Top
#297384 - 19/04/2007 18:35 Re: Another easy question for the linux oracle [Re: JBjorgen]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Well, since you just want to resize the root partition, and it happens to be the last partition, you got lucky.

Step one: Make a backup
Step two: Make another backup

If you're running kernel 2.6 and the filesystem is ext3 (not 2), you could do this whole process online. I don't think I'd try it, though.

Assuming you want to do it offline, you'll need to boot off a LiveCD so that you can work with the filesystem unmounted. So do that first. If you want to push the envelope, just don't.

The next thing you need to do is make the partition bigger. Unfortunately, fdisk doesn't give you the option to modify existing partition entries, so you'll have to delete partition 3 and recreate it with the same values as before except for the length/end, which you want to modify to make the partition take up the remainder of the disk. Don't worry about deleting it and recreating it, fdisk will not write the changes until you exit, so there won't be a point when that partition doesn't exist.

Um, this is actually a point where my knowledge breaks down. You may need to do something to make Linux recognize the new partition size. Or you may not. Arg. I'll look around. So let's call this step "magic happens" for now.

Next you want to tell the filesystem that it's got all this new space to play with. You do that using resize2fs, which you should already have on your computer, as it's part of the same package that includes mke2fs. Basically, you should just be able to run "resize2fs /dev/hda3" and it should see the new space and fix the filesystem to use it.

That it. You're done. Not too bad, except for the "magic happens" step. I'll get back to you on that.
_________________________
Bitt Faulk

Top
#297385 - 19/04/2007 18:38 Re: Another easy question for the linux oracle [Re: wfaulk]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Re: "magic happens"

Looks like new versions of fdisk do the appropriate ioctl (BLKRRPART) for you. So "magic happens" should be a no-op.

However, as Tony pointed out in IRC, parted has a liveCD.
_________________________
Bitt Faulk

Top
#297386 - 19/04/2007 18:44 Re: Another easy question for the linux oracle [Re: wfaulk]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3583
Loc: Columbus, OH
Thanks. I'll give it a try and report back.
_________________________
~ John

Top
#297387 - 07/08/2007 13:37 Re: Another easy question for the linux oracle [Re: JBjorgen]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3583
Loc: Columbus, OH
I forgot to report back on this a while back....the gparted live cd worked very well for me. It not only resized the partition but also resized the filesystem. It was simple to use and all the defaults just worked. Thanks.
_________________________
~ John

Top