LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-11-2006, 06:56 AM   #1
RichardAnderson
LQ Newbie
 
Registered: Nov 2006
Posts: 5

Rep: Reputation: 0
/var full - need to resize


Hello,

I have a cPanel server, and it's been running for over 6 months now. The problem comes now that as we have been collecting logs and installing additional programs, the /var partition has become 100% full.

The problem is, we have to keep all the logs of the server, so deleting them is not an option, basically I need to resize the /var partition.

Now don't get me wrong, Iím no Linux beginner, but I am when it comes to partitioning, so if anyone can help with a step to step tutorial, I would be very grateful.

Current system:
Code:
root@libre [/]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol04
                       1548144    379744   1089760  26% /
/dev/sda1               101086     12584     83283  14% /boot
none                    225460         0    225460   0% /dev/shm
/dev/mapper/VolGroup00-LogVol05
                     293702680  19957648 258825764   8% /home
/dev/mapper/VolGroup00-LogVol03
                       1032088     89516    890144  10% /tmp
/dev/mapper/VolGroup00-LogVol01
                       8256952   4389464   3448060  57% /usr
/dev/mapper/VolGroup00-LogVol02
                       2064208   2064208         0 100% /var
/tmp
Really I wish to take some out of the /home (say 4GB) and then add it to the /var partition. Now I understand that it may not be possible to do that, so if it's not, how do I create a partition on the /home one (of 8GB), and move the /var over to the new partition?

Thanks,
Richard Anderson.
 
Old 11-11-2006, 09:01 AM   #2
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Well, you're using LVM so you don't need to actually repartition anything. You can just reduce the /home partition and assign the space to /var. That is, use resize2fs (or resize_reiserfs, depending on what filesystem you're using). Then use lvreduce to reduce the size of the /dev/mapper/VolGroup00-LogVol05 logical volume by 4GB, and then assign that space to /dev/mapper/VolGroup00-LogVol02 with lvextend. Note that if you're using xfs, then you're stuffed because you can't currently shrink an xfs filesystem, only grow it.

Assuming you're using reiser or ext3, then it's straightforward. Of course, you should probably unmount the filesystems before doing anything. Reiser is a bit easier, since we can shrink it by a given amount: e.g.

Code:
resize_reiserfs -s -4G /dev/mapper/VolGroup00-LogVol05
will lop off 4GB.

resize2fs though, wants the new absolute size, so we can use python to calculate that:

Code:
# python -c 'print 293702680 - 4*1024**2'
289508376
so that will be the new size of the /home volume in K. (Note that 293702680 is in K, so the size would be '(293702680*1024)-4*1024**3' bytes, then divide by 1024 to get K, which is the same as the above). Thus,

Code:
resize2fs /dev/mapper/VolGroup00-LogVol05 $(python -c 'print 293702680 - 4*1024**2')
should do the trick. Then use

Code:
# lvreduce -L -4GB /dev/mapper/VolGroup00-LogVol05
to reduce the /home volume, and

Code:
# lvextend /dev/mapper/VolGroup00-LogVol02
to assign that space to /var (note that lvextend will eat all the available space by default, so we don't need to specify a size).

Obviously, read all the relevant man pages first, and triple check all calculations before you do anything, and make sure the filesystems are backed up of course.

Last edited by soggycornflake; 11-11-2006 at 09:02 AM.
 
Old 11-11-2006, 10:01 AM   #3
RichardAnderson
LQ Newbie
 
Registered: Nov 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thank you for the reply soggycornflake.

I think i'm on a ext3 filesystem, but how do I check I am correct? Also, to unmount it I would just use: "unmount /dev/mapper/VolGroup00-LogVol02"?
 
Old 11-11-2006, 11:30 AM   #4
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Quote:
Originally Posted by RichardAnderson
Thank you for the reply soggycornflake.

I think i'm on a ext3 filesystem, but how do I check I am correct?
mount (without arguments) will list all mounted partitions and the fs type (and a bunch of other stuff). E.g, mine is

Quote:
(~) mount
/dev/hda6 on / type reiserfs (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda7 on /var type reiserfs (rw)
/dev/hda8 on /tmp type ext2 (rw)
/dev/hda9 on /usr type reiserfs (rw)
/dev/hda10 on /data type reiserfs (rw)
usbfs on /proc/bus/usb type usbfs (rw)
Quote:
Also, to unmount it I would just use: "unmount /dev/mapper/VolGroup00-LogVol02"?
Yup, though the command is 'umount' (no n after the u, unix developers are too lazy to type unmount ). You might need to drop down to single user to umount /var, since some daemons may have open files on it.

Last edited by soggycornflake; 11-11-2006 at 11:32 AM.
 
Old 11-11-2006, 11:52 AM   #5
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian
Posts: 2,210

Rep: Reputation: 341Reputation: 341Reputation: 341Reputation: 341
You may not need to reduce anything. It depends on if your volume group is fully allocated. Run vgs to see if you have anything left in the "VFree" column to allocate to /var. If not, you'll have to reduce some other filesystem, as soggycornflake said. Or add another harddisk and use pvcreate and vgextend, and finally lvextend/resize2fs on your /var logical volume.
Quote:
Also, to unmount it I would just use: "unmount /dev/mapper/VolGroup00-LogVol02"?
That would work (without the "n"), but it would be simpler to just type umount /var You may have a bit of trouble doing this on a server in multi-user mode though. I expect /var might be in use (therefore not-unmountable). You may have to drop down to single-user mode.

[edit]Oops, I missed the part where soggycornflake already mentioned single-user mode. Sorry about that![/edit]

I would recommend you read the LVM HowTo: http://tldp.org/HOWTO/LVM-HOWTO/

Last edited by haertig; 11-11-2006 at 11:54 AM.
 
Old 11-11-2006, 01:39 PM   #6
RichardAnderson
LQ Newbie
 
Registered: Nov 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for all the help so far guys

First off, haertig;

Code:
root@libre [/]# vgs
  VG         #PV #LV #SN Attr   VSize   VFree 
  VolGroup00   1   6   0 wz--n- 297.97G 32.00M
32MB :P Not that much really.

soggycornflake;

Code:
root@libre [/]# mount
/dev/mapper/VolGroup00-LogVol04 on / type ext3 (rw,usrquota)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sda1 on /boot type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/mapper/VolGroup00-LogVol05 on /home type ext3 (rw,usrquota)
/dev/mapper/VolGroup00-LogVol03 on /tmp type ext3 (rw,noexec,nosuid)
/dev/mapper/VolGroup00-LogVol01 on /usr type ext3 (rw,usrquota)
/dev/mapper/VolGroup00-LogVol02 on /var type ext3 (rw,usrquota)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/proc on /var/named/chroot/proc type none (rw,bind)
/tmp on /var/tmp type none (rw,noexec,nosuid,bind)
Code:
/dev/mapper/VolGroup00-LogVol02 on /var type ext3 (rw,usrquota)
So ext3.

Therefore, I should run the following commands?

Quote:
# resize2fs /dev/mapper/VolGroup00-LogVol05 $(python -c 'print 293702680 - 4*1024**2')
# lvextend /dev/mapper/VolGroup00-LogVol02
Thanks.
 
Old 11-11-2006, 02:57 PM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian
Posts: 2,210

Rep: Reputation: 341Reputation: 341Reputation: 341Reputation: 341
My comments:

(1) You have a huge amount of space allocated to /home. 259Gb. You are only using 20Gb of that. It is wasteful to have all this unused space allocated to /home.

(2) My opinion ... when using LVM (as you are), allocate only what you need and leave some unallocated space for future use. It's much safer to extend a filesystem from unallocated space than to reduce a different filesystem to free up space for the one you want to extend. Filesystem reducing is MUCH scarier than extending. This does not help you for your current situation, but consider it for the future.

(3) You need to backup /home before proceding. Your current 20Gb usage should fit on 4 or 5 DVD's. I would not neglect this step unless you consider the contents under /home as expendable data. Always plan ahead for a potential disaster.

(4) I would take your /home all the way down to 22-25Gb. That will leave you LOTS of space to allocate later as needed. Allocate it to /home, /var, /usr or wherever you need it, but only AS you need it, don't preallocate and get yourself into the situation where you are now (needing to shrink a filesystem).

Quote:
Therefore, I should run the following commands?

Quote:
# resize2fs /dev/mapper/VolGroup00-LogVol05 $(python -c 'print 293702680 - 4*1024**2')
# lvextend /dev/mapper/VolGroup00-LogVol02
That will not be enough. I don't know if you're leaving out steps for clarity, or because you don't realize they are needed. For one, I doubt you can just use resize2fs to shrink a filesystem out of the blue. Your data will be scattered and fragmented and you can't just lop off the trailing end of the filesystem. I have never shrunk a filesystem personally, only extended them, so I can't tell you specific steps. I assume some form of defragmentation or consolidation must come before the resize downwards. I do not think resize2fs has this capability, but I can't say for sure. Second, after the shrinking, you will need to run lvreduce on that volume. Next, you would unmount and lvextend /home. Then run fsck on /home. Then run resize2fs on /home. Then remount /home.
 
Old 11-11-2006, 03:19 PM   #8
RichardAnderson
LQ Newbie
 
Registered: Nov 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the reply.

/home is where all the hosted files are stored, it's at 259GB as we are ever expanding (aka, this is a hosting server) I would be willing to reduce it to 200GB minimum.

On the left commands out comment, nope :P I have no idea about filesystems and partitions on linux, I have no clue about the commands or what steps I need to take, which is why I requested a step by step tutorial of sorts.

I learn by example, and i've been trying to find an example like mine for days now... But can't... Which is why I came here (Afterall, if google can't find the answers, i'm sure the experts can )

Thanks.
 
Old 11-11-2006, 03:41 PM   #9
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
Quote:
Originally Posted by haertig
That will not be enough. I don't know if you're leaving out steps for clarity, or because you don't realize they are needed. For one, I doubt you can just use resize2fs to shrink a filesystem out of the blue. Your data will be scattered and fragmented and you can't just lop off the trailing end of the filesystem. I have never shrunk a filesystem personally, only extended them, so I can't tell you specific steps. I assume some form of defragmentation or consolidation must come before the resize downwards. I do not think resize2fs has this capability, but I can't say for sure.
I assumed that resize2fs handled all that. The man page mentions block/inode relocation:

Quote:
OPTIONS
-d debug-flags
Turns on various resize2fs debugging features, if they have been compiled into the binary. debug-flags should be computed by adding
the numbers of the desired features from the following list:
1 - Print out all disk I/O
2 - Debug block relocations
8 - Debug inode relocations
16 - Debug moving the inode table
However, I also, have never shrunk a filesystem, so I could be wildly wrong, it may only apply to extending the fs.

But, in any case, haertig is correct, it's generally much easier, and safer, to extend a filesystem rather than shrink it (for future reference).
 
Old 11-11-2006, 05:46 PM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,001

Rep: Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219
Haertig gave the answer - in post #7. Applies in general - LVM or not. Backup the data, delete the offending partition(s), reallocate sensibly, and restore the data.
I keep 2 100Gig USB drives for things like this. Why 2 ??? - 2 copies ...

Resize2fs is supposed to do the job - I've never had it work satisfactorally. Other swear by it.
All that said, do you *really* need all those logs ???.
Online ...
Uncompressed ... ???

Have a look at something like logrotate. Easy to do, and could save a lot of grief.
What about moving all the logs to /home and symlink'ing ???.
 
Old 11-11-2006, 08:06 PM   #11
RichardAnderson
LQ Newbie
 
Registered: Nov 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for your replies.

One last question. If I was to add another hard drive (say 80GB) how easy would it be to give all 80GB to /var?
 
Old 11-11-2006, 09:27 PM   #12
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian
Posts: 2,210

Rep: Reputation: 341Reputation: 341Reputation: 341Reputation: 341
Quote:
Originally Posted by RichardAnderson
If I was to add another hard drive (say 80GB) how easy would it be to give all 80GB to /var?
Trivial. That is what LVM is for. Shutdown the system. Plug in the new drive. Boot into single-user mode. Run pvcreate on the new drive. Add it to your existing volume group. Unmount /home. Use lvextend to allocate more space to it. Run e2fsck on it. Run resize2fs on it. Remount it. Go to multi-user mode. You're done! Shouldn't take more than two or three minutes to complete all these steps (ignoring the powerdown, hardware install, and reboot parts). Check out the LVM HowTo I mentioned in a previous post. All these steps are covered there.
 
Old 11-11-2006, 09:49 PM   #13
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian
Posts: 2,210

Rep: Reputation: 341Reputation: 341Reputation: 341Reputation: 341
Quote:
Originally Posted by RichardAnderson
/home is where all the hosted files are stored, it's at 259GB as we are ever expanding (aka, this is a hosting server)
Given that you're a hosting service for others, I think you definitely need to learn LVM inside and out. And also RAID. And also good on and offsite backup strategies. And also redundant servers.

BTW, 80Gb is a huge amount of space for /var. Unless you're running a large database or other app that uses that much disk. If you're planning all that as online logfile storage, I think you might want to reconsider your plans. That's a pretty unusual setup. If you have some mandate to store that many logfiles, I would expect that that same mandate would specify they be stored securely, off site, as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can anyone please help me with resize /var kafnir Linux - General 1 12-08-2005 10:22 PM
/var full manoj142 Linux - General 8 10-17-2005 07:00 AM
/var really full or not? philforrest Linux - Software 6 02-22-2005 04:10 AM
resize /var caladbolg Mandriva 1 09-25-2004 02:38 PM
Wine: how to resize to full screen? spchehe Linux - Software 4 08-20-2004 09:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration