Archive

Resizing Partitions


Introduction

There is sometimes a need over the course of a sysadmin’s role to resize partitions. There are a few things that need to be thought about before this is done. This document serves as a guide only in doing that. It is well worth using a knoppix CD to do this, since I would never recommend resizing partitions from the drive that is being resized.

I should point out that I take no responsibility for data loss as a result of the instructions contained herein.

Procedure

I’m assuming that you’ll be resizing an ext3 partition. Other filesystems may well be different. I have no experience with resizing reiserfs, so that is not listed here. Users still of “ext2” might find the utility resize2fs of use, although the ability to resize partitions there depends on the order they exist on the drive (resizing partitions at the end of the drive is usually easier, where there is contiguous free space, etc).

As mentioned, the use of Knoppix is important. Not only does it stop disk access, but the other main reason is that by default, Knoppix comes with a program called ‘parted’. This is the program that you can use to actually resize the partitions. There is also a GUI version of parted called ‘qtparted’.

NOTE: When using Knoppix it is often helpful to run knoppix with the noswap option (“knoppix noswap” from the boot prompt) to disable the use of any swap partitions you may have on the drive.

(The following is an extract of an e-mail I sent to HantsLUG)

To mount ext3 -> ext2 (and hence resizing it), the following can be done

Note: /dev/hdX assumes the device partition in question throught these instructions.

1. Unmount the ext3 partition thus:

# umount /dev/hdX

2. Clear the journal flag from the superblock:

# tune2fs -O ^has_journal /dev/hdX

3. Do with (qt)parted what you will.

4. When all done, set the has_journal flag back in the superblock for each partition(s):

# tune2fs -O +has_journal /dev/hdX

Repeat the above as necessary for other partitions.


This page was written by ThomasAdam

Instructions for resizing an LVM / partition

By default upon installing fedora, it creates one massive Logical Volume Group which takes up your entire drive, and only creates a partition for /. This makes it extremely difficult should you wish to resize this partition/LV, as you cannot shrink an ext2/3 filesystem online. The procedure below gives the steps to enable you to shrink your default installation to enable you to create a seperate LVGroup.

I should point out that I take no responsibility for data loss as a result of the instructions contained herein.

Procedure

I’m assuming that you’ll be resizing an ext3 partition. Other filesystems may well be different. I have no experience with resizing reiserfs, so that is not listed here. You can boot off the Fedora Disc 1 and go into the rescue mode. Whilst in there, we need

Note: /dev/VolGroup00/LogVol00 assues the logical partition you wish to resize.

1. Activate the Volume Group:

# lvmchange -a y [[VolGroup00]]

2. Clear the journal flag from the superblock:

# tune2fs -O ^has_journal /dev/VolGroup00/LogVol00

3. Use the resize2fs command to shrink the partitions size (Do not shrink it past the used data size on this partition). The line below assumes we are shrinking the filesystem down to 10Gb, there was 4Gb of data on this drive, and the filesystem size was originally 29Gb. This leaves a large margin of error of 5Gb. This step will take a while.

# resize2fs /dev/VolGroup00/LogVol00 10G

4. Resize the logical volume using the lvresize command. Notice there is a 1Gb margin here, because the lv should never be reduce to less than the size of the filesystem.

# lvresize -L-18G /dev/VolGroup00/LogVol00

5. When all done, set the has_journal flag back in the superblock for each partition(s):

# tune2fs -O +has_journal /dev/VolGroup00/LogVol00

Repeat the above as necessary for other partitions.


Thse additional instructions written by Peter Savage

Leave a Reply