How can I resize /var smaller in a new LVM system?

I'm in the process of setting up a new Linux server, so I have no production data on it yet, and nothing installed or running on it yet other than the O/S.  This is Oracle's "Enterprise Linux 4" (same as RedHat 4AS).  I chose "LVM" during the install and remembered to set up separate partitions for: /home, /opt, /tmp and /usr (plus the default partitions for /boot and /swap) then left the balance of the RAID1 local SCSI disk (about 70GB) for: /var.  But, I should have set up two more separate partitions of 8GB each and left /var somewhat smaller.

I'm assuming there must be a way to resize /var smaller under LVM and create to new partitions in that space without having to do a complete O/S re-install, right?  At this point an O/S re-install would only waste about 3 hours of my time, and there would be no data loss, but I'm trying to avoid the waste of time and learn some more about what's possible in Linux too.  I may be an expert in Oracle but I have no UNIX experience and only limited Linux experience.

What are my options?  Is there a relatively easy way to make my (ext3) /var partition smaller?
LVL 36
Mark GeerlingsDatabase AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
You can easily grow a filesystem, but to shrink it is a different thing.
As /var contains log files you should do this in Single user mode.
If there is sufficient space for a new file system:
make a new (smaller) filesystem, mount it under a temporary name f.e. /var-new
and copy all files to it and remove the old one.
Don't forget to edit the fstab to point to the new lvmpartition.
The copy can be made with:

mkdir /var-new
mount /dev/..... /var-new
(cd /var; tar cf - .) | (cd /var-new; tar xvpf -  )
# now check and swap....

If there is no free space on the disk anymore then and there is sufficient space on a different file system: (let's assume /tmp is big enough)

cd /var; tar czvf /tmp/temp-var.tgz . ; cd /

then dismount /var;  delete the /var partition, recreate it smaller; mkfs the new filesystem and
mount it again.

cd /var; tar xzvpf /tmp/temp-var.tgz
then remove /tmp/temp-var.tgz

The reason for this you cannot be sure that all of a file system is below the boundary you like to have.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nociSoftware EngineerCommented:
Oh, and if there is not sufficient space available on the system you might be able to temporily plug an USB disk into the system, to add a few GB of storage..
0
Mark GeerlingsDatabase AdministratorAuthor Commented:
My in-house source of Linux information was tied up on another issue for a while today, but he got back with me recently and helped to do a reboot from the install disk one, and choose "linux rescue".  That starts Linux from the CD so it doesn't mount any of the partitions on the hard drive.  Then we could use a resize utility to make /var smaller, then reboot from the hard drive.  This seems like a lot of work, and something I can't do on a production server.

So, I think the lesson here is that even though RedHat added a Logical Volume Manager to apparently make some file system and/or partition maintenance in Linux somewhat easier than before, I still should not assume that I can ever do an on-line resize of a Linux file system/partition.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mikelfritzCommented:
Not smaller- only bigger.  IBM made this stuff up and you could not do it there either.
0
Mark GeerlingsDatabase AdministratorAuthor Commented:
You both confirmed that file systems (or partitions) in Linux can only be made larger, not smaller (at least not without major effort, and at least one reboot).  That's a key point that I was not aware of.  I heard about "Logical Volume Manager" and assumed that it would support growing and/or shrinking of volumes (or file systems or partitions).  But unless I'm willing to leave a chunk of the physical disk unpartitioned when setting up a new server, it looks like Logical Volume Manager doesn't do much for me.
0
nociSoftware EngineerCommented:
It is not only limited by LVM, it also is by the file systems.
File systems used to static, later they were built growable (fairly easy).
But to shrink a filesystem you need to move all all files to a point below the size you want to keep. AFAICT only two OS's have a move file function to support defragmentation
Windows NT and OpenVMS. So for other systems it wall allway be a guess where a file lands
when copied & deleted.
0
Mark GeerlingsDatabase AdministratorAuthor Commented:
Thank you, noci.  Those happen to be the only two OS's that I've had much experience with (DOS/Windows and VMS) so my frame of reference for what is "normal" in an OS is influenced by those two systems, not UNIX.  I realize that Linux is very much like UNIX, but since I don't know UNIX, that comparison doesn't help me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.