1753868 Members
7172 Online
108809 Solutions
New Discussion юеВ

Re: Extend /var

 
SOLVED
Go to solution
elias12
Advisor

Extend /var

Hello,

No LVM;Red Hat 5. df -h shows that /var is around 100% (ext3). The / is almost empty. Is there anyway to shrink the / and extend the /var? Any lost of data would result?

Thank you.
11 REPLIES 11
Matti_Kurkela
Honored Contributor
Solution

Re: Extend /var

You cannot shrink the root filesystem on-line. That would be impossible even if you had LVM. Shrinking a filesystem always requires the filesystem to be un-mounted, and you cannot un-mount the root filesystem while running the OS on it.

Shrinking a filesystem is always somewhat risky, so a good backup is a must before beginning.

Because you don't have LVM, if you un-allocate disk space by shrinking the root filesystem and the partition it's located in, you can only use the space by creating a completely new partition or by destroying and re-creating the partition that is located immediately after the root filesystem on the disk.

(I don't know of a partition management program that could move the beginning of an ext2/ext3 filesystem. Resize an ext3 partition, yes. Move its beginning point on the disk, no.)

Knowing the physical layout of your partitions would be important in determining what can be done and how best to proceed. Please show us the output of "fdisk -l".

The re-organization will very likely be a major operation, so it would be reasonable to plan it very carefully first. An important thing to consider is: what is causing /var to be full? Could it cause a need for further expansion in the future?

If you need to backup and re-create partitions anyway, it might be worth your while to take the extra trouble of converting the system (or at least some partitions) to LVM layout at the same time.

MK
MK
Vitaly Karasik_1
Honored Contributor

Re: Extend /var

can you please send us output of these commands?

- df -h

- du /var | sort -rn |head -30
elias12
Advisor

Re: Extend /var

Thank you Matti for the great information you provided.

fdisk -l is showing:

/dev/sda2 /
/dev/sda3 /usr
/dev/sda5 /var
...

Thank you.
elias12
Advisor

Re: Extend /var

sorry, previously I copied part of df -h. fdisk -l shows the below:

DeviceBoot Start End Id System
/dev/sda1 1 25 83 Linux
/dev/sda2 26 2946 83 Linux
/dev/sda3 2947 5698 83 Linux
/dev/sda4 5699 8833 5 Extended
/dev/sda5 5699 7003 83 Linux
....
Thank you.
Matti_Kurkela
Honored Contributor

Re: Extend /var

Just one confirmation first.
You said you have "Red Hat 5".

Do you mean the current Red Hat _Enterprise_ Linux 5 or the ancient RedHat Linux 5.x (released back in 1997-1998 and thoroughly obsolete now)?
If it's the latter, back up your data and reinstall with a newer version. Seriously.

Your fdisk -l output is obviously missing a few lines at the beginning that would tell the total capacity of the disk.

Nevertheless, I can see two things:

1.) Your /usr is physically located between / and /var on your disk, so you would have to manipulate both /usr and /var to make use of any space you could gain by reducing /. That may complicate things, unless...

2.) Your partial fdisk -l output shows:

> /dev/sda4 5699 8833 5 Extended
> /dev/sda5 5699 7003 83 Linux

From this, I can see that cylinders 7004 - 8833 are within the extended partition but not part of /dev/sda5 (/var). The important question is, do you have /dev/sda6 (or any further partitions on this disk) or not?

If /dev/sda5 is the last partition on this disk, cyls 7004-8833 are currently unallocated. As they are located immediately after /var, adding them to /var would be very simple.

---------------
Procedure for extending /dev/sda5, assuming that it's the last allocated partition on the disk and has some unallocated space after it:

Take a backup first.

Start fdisk with "fdisk /dev/sda", delete partition /dev/sda5 and re-create it so that the starting cylinder stays the same (5699 in your case) but the ending cylinder value is larger. If there are no partitions beyond /dev/sda5, you can use the the last cylinder of the disk (8833) as the ending cylinder, which should in your case more than double the current capacity of your /var.

Remember that the fdisk only writes the new partition table to disk when you use the "w" command. If you think you may have made a mistake, just use the "q" command instead to exit without making any actual changes. Write to disk only after triple checking you've got it right.

When writing the changes to the disk, fdisk will detect that the disk still has mounted filesystems on it, and the changes will be effective only after a reboot. The fdisk command won't force you to reboot, but you cannot proceed with the expansion until you do it.

(If there are neither mounted filesystems nor active swap partitions on a disk, the kernel can detect the new partition layout immediately. But as /dev/sda2 contains your root filesystem, that is not possible in this case.)

After a reboot, the partition has been extended and the kernel is made aware of the new size, but the filesystem still reflects the old size.

In RHEL5, that is fixed with with a simple command: "resize2fs /dev/sda5". It will automatically detect that the filesystem is mounted and smaller than the partition it's in. It will perform an on-line extension, and then the expanded capacity of /var will be available for use.
-----------

MK
MK
elias12
Advisor

Re: Extend /var

Matti,

Thanks a lot for the information you provided so far.

Just to make things clearer:
The version is the new RHEL 5

I have /dev/sda6 which means from your previous reply that both /usr and /var have to be manipulated.
In this scenario, can you please shed more lights on how to shrink the / file system and proceed with /usr and /var.

thank you.
Andrew Cowan
Honored Contributor

Re: Extend /var

I know that it is a fudge, but if you know that a particular process such as process-accounting is filling "/var/sa" for example, you could replace this directory with a soft-link to a directory in another filesystem. Its not perfect, but is low-risk, and can buy you some time whilst you plan for a rebuild etc.
D. Jackson_1
Honored Contributor

Re: Extend /var

Have you looked for any core files? Also look in /var/log to see if there are any large log files you can remove. Is /var/crash empty? Could be that /var/spool/up2date has a lot of stuff in it that could be cleaned up.

Good luck...
elias12
Advisor

Re: Extend /var

Thank you all for your inputs. I guess re-installing with LVM should be the best choice, but I still would like to know how to shrink the root file system:
booting to single user mode, fdisk and change the partition size and after resize2fs. Is it right?

Thank you.