Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
cancel
Showing results for 
Search instead for 
Did you mean: 

Enlarge extended partition

SOLVED
Go to solution
fawrell
Advisor

Enlarge extended partition

Hi.

I need to enlarge my extended partition on my server, because the logical partition on it is almost full. I found nice guide how to enlarge a primary partition using fdisk, but I don't know, that can I apply it on extended partition. Theroetically in fdisk I need to delete the logical and extended partition, then create new extended and logical partition with the same start as the deleted partitions but with bigger size and then write the new partition table on disk. But I don't know if it will work. Have someone experience with this?

The guide: http://howtoforge.com/linux_resizing_ext3_partitions_p2

And I am using Ret Hat Enterprise Linux 4.

Thank you for answers.
10 REPLIES
Steven E. Protter
Exalted Contributor

Re: Enlarge extended partition

Shalom,

if you are using LVM its easy, lvextend online2fs.

If not, the procedure is not supported by Red Hat.

You can try it if you want.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
skt_skt
Honored Contributor

Re: Enlarge extended partition

if LVM configured. if online extend is not possible then dismount the file system first.

# e2fsadm -L +1G /dev/vg01/lvol22
e2fsck 1.32 (09-Nov-2002)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg01/lvol22: 329/131072 files (14.0% non-contiguous), 242667/524288 blocks
lvextend -- extending logical volume "/dev/vg01/lvol22" to 1.50 GB
lvextend -- doing automatic backup of volume group "vg01"
lvextend -- logical volume "/dev/vg01/lvol22" successfully extended

resize2fs 1.32 (09-Nov-2002)
Begin pass 1 (max = 128)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 2 (max = 32)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 64)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 5 (max = 9)
Moving inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/vg01/lvol22 is now 1572864 blocks long.

e2fsadm -- ext2fs in logical volume /dev/vg01/lvol22 successfully extended to 1.50 GB
fawrell
Advisor

Re: Enlarge extended partition

Thanks for reply.

Unfortunately I do not use LVM. So I try to find other possibilities how to do this. Do you have any idea how to do this?
skt_skt
Honored Contributor

Re: Enlarge extended partition

if you meant to extend the FS w/o LVM then go ahead a nd get a new disk with targeted capacity(keep additional cap keeping your future req) and create new file system , copy the data. Finally dismount the old disk and mount the new disk on the same mount point. AFAIK, there is no other way and this is what we do. if it is database mount point like oradata1, oradata2 then you can create another oradatax w/o going through the data copy process.
Paul McCleary
Honored Contributor
Solution

Re: Enlarge extended partition

Hi,

Firstly take a backup of everything and make sure you are confident you can restore it, just in case everything goes pear shaped!!

I don't think you will have a problem doing what you want to do, I've done this before and it worked fine.

You don't show your partition table or the devices you have, so not sure on your exact situation.

I'll try to give an example:

- I have a disk that is 4GB, it has 3x1GB partitions, first two are primary and the last is an extended one with one logical volume that fills it (not best use of logical volumes, but it seems similar to what you have). So I have 1GB of free space immediately after my extended partition - this is key, if you have not got the sequential space then you can't do this.

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 375 1004062+ 5 Extended
/dev/sdb5 251 375 1004031 83 Linux

These all have ext3 filesystems and are mounted as below; /l1 is the logical volume in the extended partition that we want to increase (/p1 and /p2 are the two other primary partitions that will remain untouched):

Filesystem Size Used Avail Use% Mounted on
/dev/md1 4.2G 1.8G 2.3G 44% /
/dev/md0 104M 12M 87M 12% /boot
tmpfs 131M 0 131M 0% /dev/shm
/dev/sdb1 1.1G 19M 943M 2% /p1
/dev/sdb2 1.1G 19M 943M 2% /p2
/dev/sdb5 1.1G 19M 943M 2% /l1

There are data in these filesystems:

[root@localhost ~]# ll /l1
total 72
drwxr-xr-x 3 root root 4096 Jul 11 21:34 hal
-rw-r--r-- 1 root root 17 Jul 23 2000 host.conf
-rw-r--r-- 1 root root 187 Jul 11 21:12 hosts
-rw-r--r-- 1 root root 161 Jan 12 2000 hosts.allow
-rw-r--r-- 1 root root 347 Jan 12 2000 hosts.deny
drwxr-xr-x 4 root root 4096 Jul 11 21:27 httpd
drwx------ 2 root root 16384 Jul 31 11:43 lost+found
-rw-r--r-- 1 root root 15 Jul 31 11:45 testdata

Lets umount it and use fdisk:

[root@localhost ~]# umount /l1
[root@localhost ~]# fdisk /dev/sdb


Command (m for help): p

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 375 1004062+ 5 Extended
/dev/sdb5 251 375 1004031 83 Linux

Note down the start and end cylinder positions (251 and 375). We now need to delete the extended partition that you wish to increase in size (the scary bit!!); first delete the logical volume and then the extended partition:

Command (m for help): d
Partition number (1-5): 5

Command (m for help): p

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 375 1004062+ 5 Extended

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 375 1004062+ 5 Extended

Command (m for help): d
Partition number (1-5): 3

Command (m for help): p

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux

Now we need to create our new larger extended partition and logical volume (start at same cylinder position, 251, and set a size of 2GB):

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 3
First cylinder (251-522, default 251):
Using default value 251
Last cylinder or +size or +sizeM or +sizeK (251-522, default 522): +2048M

New Partition is created using 251 to 500 cylinders.

Command (m for help): p

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 500 2008125 5 Extended

Create the new logical volume in the extended partition and use all available cylinders (251-500):

Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (251-500, default 251):
Using default value 251
Last cylinder or +size or +sizeM or +sizeK (251-500, default 500):
Using default value 500

Command (m for help): p

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 500 2008125 5 Extended
/dev/sdb5 251 500 2008093+ 83 Linux

As you can see I have now created it as 2GB instead of 1GB. Save this and check the new size:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 125 1004031 83 Linux
/dev/sdb2 126 250 1004062+ 83 Linux
/dev/sdb3 251 500 2008125 5 Extended
/dev/sdb5 251 500 2008093+ 83 Linux

I still had /p1 and /p2 mounted from that disk which is why I get the warning. Quick reboot of the system to be safe.

[root@localhost ~]# mount /dev/sdb5 /l1
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/md1 4.2G 1.8G 2.3G 44% /
/dev/md0 104M 12M 87M 12% /boot
tmpfs 131M 0 131M 0% /dev/shm
/dev/sdb1 1.1G 19M 943M 2% /p1
/dev/sdb2 1.1G 19M 943M 2% /p2
/dev/sdb5 1.1G 19M 943M 2% /l1
[root@localhost ~]# ll /l1
total 72
drwxr-xr-x 3 root root 4096 Jul 11 21:34 hal
-rw-r--r-- 1 root root 17 Jul 23 2000 host.conf
-rw-r--r-- 1 root root 187 Jul 11 21:12 hosts
-rw-r--r-- 1 root root 161 Jan 12 2000 hosts.allow
-rw-r--r-- 1 root root 347 Jan 12 2000 hosts.deny
drwxr-xr-x 4 root root 4096 Jul 11 21:27 httpd
drwx------ 2 root root 16384 Jul 31 11:43 lost+found
-rw-r--r-- 1 root root 15 Jul 31 11:45 testdata
[root@localhost ~]# cat /l1/testdata
This is a test

The size is still the same and the data is still there. So now increase the filesystem size to size of our new partition:

[root@localhost ~]# resize2fs /dev/sdb5
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/sdb5 is mounted on /l1; on-line resizing required
Performing an on-line resize of /dev/sdb5 to 502023 (4k) blocks.
The filesystem on /dev/sdb5 is now 502023 blocks long.

[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/md1 4.2G 1.8G 2.3G 44% /
/dev/md0 104M 12M 87M 12% /boot
tmpfs 131M 0 131M 0% /dev/shm
/dev/sdb1 1.1G 19M 943M 2% /p1
/dev/sdb2 1.1G 19M 943M 2% /p2
/dev/sdb5 2.1G 19M 2.0G 1% /l1

Everything looks good and we now have a 2GB filesystem with the data we had in at the start when it was only 1GB.

Hope this is helpful,

Paul
Paul McCleary
Honored Contributor

Re: Enlarge extended partition


I should add, you probably should also fsck your disk partition before and after you finish to confirm everything is ok:

[root@localhost ~]# umount /l1
[root@localhost ~]# fsck /dev/sdb5
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/dev/sdb5: clean, 32/251392 files, 12404/502023 blocks

[root@localhost ~]# mount /dev/sdb5 /l1
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/md1 4.2G 1.8G 2.3G 44% /
/dev/md0 104M 12M 87M 12% /boot
tmpfs 131M 0 131M 0% /dev/shm
/dev/sdb1 1.1G 19M 943M 2% /p1
/dev/sdb2 1.1G 19M 943M 2% /p2
/dev/sdb5 2.1G 19M 2.0G 1% /l1
[root@localhost ~]# cat /l1/testdata
This is a test

Let me know how you get on.

Paul
fawrell
Advisor

Re: Enlarge extended partition

Thank you Paul!

This is exact what I wanted to see! Only one more question. Did you remove journal from /dev/sdb5 with:

tune2fs -O ^has_journal /dev/sda5
(it makes ext2 from ext3)

before resizing, or resize2fs can resize ext3 too?
Paul McCleary
Honored Contributor

Re: Enlarge extended partition

Hi,

Glad its been useful.

I did not try and remove the journal - though it shouldn't hurt, it probably makes sense as then your journal will be re-sized for your new size filesystem (when you set it back on).

resize2fs works fine with ext2 or ext3.

I've had no problems with this approach and fsck didn't throw any errors. So you should be fine, but there's no guarantees in life, hence ensuring you have a good backup as a plan B :-)

Let me know how you get on,

Paul
Paul McCleary
Honored Contributor

Re: Enlarge extended partition

Hi,

How did you get on with performing this?

Paul
fawrell
Advisor

Re: Enlarge extended partition

Hi.

We will do this probably this or next week. I promise, I will let you know how we get on.

Have a nice day and thank you again.