LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-10-2006, 08:56 AM   #1
jarod_123
LQ Newbie
 
Registered: Sep 2003
Posts: 29

Rep: Reputation: 15
Resize the / root drive non-destructively


My system is setup up something like this: (ext3 filesystem)

/dev/hda1 /boot 200MB
/dev/hda2 /swap 2GB
/dev/hda3 / 83% 4GB
/dev/hda4 /home 9% 10GB
/dev/hda5 /usr/local 5% 10GB
/dev/hda6 /var 3% 5GB

I want to resize my /dev/hda3 root directory. Its presently at 83% used up and as you can see I probably should have created a partition for the /usr directory. I would like to re-allocate some space from the /usr/local and probably other free space and create a new /usr directory.

I have looked at Qparted, parted, ext2resize, resize2fs.

I was thinking of using resize2fs and fdisk to do what I need done, but was wondering if its possible with the / directory at 83%

thanks
 
Old 01-10-2006, 09:22 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
First, I think you have achieved a miracle (or my understanding is flawed). You can only have 4 primary partitions---if you need more, then you make an extended partition---an anything beyond 4 becomes a logical partition.
You cant mount an extended partition to a filesystem.....

Please post the output of fdisk:

"fdisk /dev/hda"

then "p" to list all the partitions

Also post the contents of /etc/fstab
 
Old 01-10-2006, 09:32 AM   #3
jarod_123
LQ Newbie
 
Registered: Sep 2003
Posts: 29

Original Poster
Rep: Reputation: 15
Yeah I should have been more clear.
I have 3 primary partitions and the rest are extended partitions.
These are the 3 primary:
/boot
/swap
/

The rest are on an extended partition:
/home
/usr/local
/var

I need to know if I can re-allocate some room off of /usr/local and/or /home toward a new partition /usr. I'd prefer to reduce the size of the / directory. All this non-destructively or else I'd just re-install.

thanks
 
Old 01-10-2006, 10:38 AM   #4
jarod_123
LQ Newbie
 
Registered: Sep 2003
Posts: 29

Original Poster
Rep: Reputation: 15
Under further analysis I think I have the answer. Just posting it here for those who may be interested and for those who believe that I'm wrong and correct me.

I guess I can resize my filesystem but once I try to resize the partition with fdisk I'll start to lose my data. I wanted to re-allocate more space by creating a /usr directory and reducing size from the / root directory by getting more space from /home and /usr/local directories. However they will lose their position on the cylinder and the data will not be contiguous from where it started. Therefore I can't re-distribute more space from the other partitions to create a new /usr partition.

Anyone agree?
 
Old 01-10-2006, 11:26 AM   #5
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by jarod_123
All this non-destructively or else I'd just re-install.
Always plan for a reinstall. If you can do it non-destructively, great. But if something fails at least you won't be disappointed because you already covered your bases planning for a reinstall (i.e., you have good solid backups and know how to restore!)
Quote:
/dev/hda1 /boot 200MB
/dev/hda2 /swap 2GB
/dev/hda3 / 83% 4GB
/dev/hda4 /home 9% 10GB
/dev/hda5 /usr/local 5% 10GB
/dev/hda6 /var 3% 5GB
You've got a really big /boot there. And a big swap also. Your /var and /usr/local are underutilized as well. You've got a big /home, but sizes for this filesystem can vary wildly depending on what it is you store. If you plan for MP3's and photos/videos you'll need lots of space in /home potentially.

Looks like you're dealing with about a 40Gb disk if your above partitions totally fill the thing up. Below is what I'd do based on your usage percentages above and an assumption of 512Mb or 1Gb ram. If you can manage to do it all non-destructively you have my HIGHEST respect!

Partitions:
-----------
/boot 25Mb (primary #1)
swap 500Mb (primary #2)
/ 250Mb (primary #3)
LVM remainder of disk (primary #4)

Create initial LVM logical volumes:
-----------------------------------
/usr 3.5Gb
/var 100Mb
/opt 750Mb
/tmp 100Mb
/home 1Gb
symlink /usr/local -> /opt

This should (very tightly) cover what you currently have installed, and still leave you with around 25Gb of available LVM space that could be incrementally added to /usr, /var, /opt, /tmp, or /home as the need arises in the future. [edit] You can also add entirely new filesystems out of this LVM available space. Maybe someday you'll decide you want a seperately mounted /videos filesystem or something. [/edit] My mode of operation for LVM is to start out as small as possible and expand in small increments only as needed. Note: If you are running Debian and attempt a "dist upgrade" the above /var space will run out REAL fast!

Simple answer is to buy a new (bigger) disk. They're dirt cheap. The peace of mind might be worth it to justify the cost. Treat your existing disk as your backup. So destructive/non-destructive becomes less of an issue.

Last edited by haertig; 01-10-2006 at 11:31 AM.
 
Old 01-10-2006, 11:33 AM   #6
Lenard
Senior Member
 
Registered: Dec 2005
Location: Indiana
Distribution: RHEL/CentOS/SL 5 i386 and x86_64 pata for IDE in use
Posts: 4,790

Rep: Reputation: 58
First you can resize partitions as long as you obey the rules, resizing you root partition is not a good idea and is not required. Everything needs to be done from a live Linux CD and not from the main system. Modifying and resizing partitions on an active filesystem is a good way to lose data and really mess up your system.

You currently have this partition;

/dev/hda5 /usr/local 5% 10GB

Would it not make sense to use this partition as your /usr partition instead.

First boot your system as you normally do copy (temporally) the contents of your /usr and /usr/local directories to your /home directory as root of course (hint: mkdir /home/usr). When done reboot the system using a live Linux CD like the SystemRescueCD; http://www.sysresccd.org/

Delete the /usr/local partition using qtparted or parted, then create the /usr partition in it's place. Mount the new partition and your /home partition, copy the contents from the home/usr directory to the new partition. Now mount the root partition and make sure that everything in the /usr directory (minus /usr/local directory of course) is exactly the same in the new /usr partition. You can safely delete this directory now if you want. No harm will come if you leave it in place after you reboot.

Make sure you modify your fstab to reflect the changes before rebooting.
As long as you use the starting position of the /dev/hda5 partition and make the fstab change correctly this should work.

It is a good idea to make a backup before starting this as I cannot guarantee this will work for you, I have no idea of your skill level.
 
Old 01-10-2006, 11:41 AM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by Lenard
Would it not make sense to use this partition as your /usr partition instead.
A very good suggestion.
Quote:
Delete the /usr/local partition using qtparted or parted, then create the /usr partition in it's place.
Why delete the partition and expose yourself to additional risk? I see zero benefit to doing this. Simply remount it as /mnt/temp or some other temporary place and overwrite it's contents from existing /usr on the root filesystem, and the /usr/local data THAT YOU PREVIOUSLY COPIED over to /home. Then rename /usr on root to /usr.old, make a new mountpoint /usr, and remount your new filesystem. Once things were all tested you could delete /usr.old and the /usr/local copy under /home.
 
Old 01-10-2006, 11:54 AM   #8
jarod_123
LQ Newbie
 
Registered: Sep 2003
Posts: 29

Original Poster
Rep: Reputation: 15
Thanks for these ideas guys they sound promising.

but I'm just wondering how I can incrementally increase the size of the LVM logical volumes once I get it the way I want. I might just buy new drive.
 
Old 01-10-2006, 12:06 PM   #9
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by jarod_123
but I'm just wondering how I can incrementally increase the size of the LVM logical volumes once I get it the way I want.
Here's how I would add 1Gb to /usr:

$ su -
# telinit 1
# umount /usr
# lvextend -L+1G /dev/vg0/usr
# e2fsck -f /dev/vg0/usr
# resize2fs /dev/vg0/usr
# mount /usr
# df
# telinit 2

All done. Takes about two minutes. You can see above that I do all this in single user mode. For safety (and to facilitate unmounting filesystems - much easier with no pesky users or programs using the filesystem!)

Other filesystem types might be slightly different. For example, XFS and JFS are resized WHILE they are mounted. You would also use a different command to resize. For example, XFS uses "xfs_growfs" rather than "resize2fs". Basic steps are, first, resize the logical volume, second, resize the filesystem sitting on top of it.

[edit] Fixed typo. Was: "lvextend -L+1Gb", should have been "lvextend -L+1G". No "b" after the "G". [/edit]

Last edited by haertig; 01-10-2006 at 12:24 PM.
 
Old 01-10-2006, 12:13 PM   #10
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Another neat thing about LVM is that you can extend things ACROSS DISKS. So when you've exhausted your current disk capacity and still need more room, just add a new disk and keep on extending your filesystems. No need to copy data from the old filled up disk to the new bigger one. The two disks are merged together into one super-big virtual disk (called a "volume group" in LVM language).

Last edited by haertig; 01-10-2006 at 12:16 PM.
 
Old 01-10-2006, 12:38 PM   #11
jarod_123
LQ Newbie
 
Registered: Sep 2003
Posts: 29

Original Poster
Rep: Reputation: 15
It look like a re-installation would probably be better. This time I'll make sure I set the size right and be minimal as possible. I just installed my distro quickly just to see if I liked it or not. I didn't think I'd like that I'd want to optimize it and keep it permanently.

By the way whats the suggestion on where to install the bootloader lilo or grub? on the MBR or on the /boot directory? I have mine on the MBR, but I was reading that having it on the /boot directory would be a safer way to go.
 
Old 01-10-2006, 12:53 PM   #12
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by jarod_123
By the way whats the suggestion on where to install the bootloader lilo or grub? on the MBR or on the /boot directory? I have mine on the MBR, but I was reading that having it on the /boot directory would be a safer way to go.
Your choice. I use grub in /boot myself. I then use XOSL as a boot manager to chose between a Windows boot, a DOS boot, or a Linux boot. If I chose Linux boot, XOSL passes control on to grub up in /boot. I have grub configured to only know about Debian. I like the fact that Windows doesn't know Linux is installed, Linux doesn't know Windows is installed, and DOS doesn't even know that DOS itself is installed! ;-)

If you have a single boot system, Linux only, I see no advantage to putting grub anywhere BUT the MBR. Nor do I see any advantage in using lilo instead of grub.
 
Old 01-10-2006, 12:59 PM   #13
jarod_123
LQ Newbie
 
Registered: Sep 2003
Posts: 29

Original Poster
Rep: Reputation: 15
Thats what I figured, since I only have Linux on the drive I installed Lilo on the MBR.

By the way, once the extended logical volume is full for one physical hard drive and I go buy a new hard drive, how do I increase the space on the (/usr /home /var ) directories located on the first Hard drive?
 
Old 01-10-2006, 01:08 PM   #14
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
I would recommend checking out the LVM HowTo for specifics. http://www.tldp.org/HOWTO/LVM-HOWTO/

The concept is simple. You start out with "Physical Volumes" (PV). This generally equates to "hard disk", but could be a "partition on a hard disk" PV's are grouped together into "Volume Groups" (VG). You can add new PV's to an existing VG with the "vgextend" command (sibling of the "lvextend" command I mentioned previously).

Then you take your VG and carve it up into "Logical Volumes" (LV). A filesystem is then allocated to an LV. When the filesystem fills, you extend it's underlying LV and resize the filesystem. When you can't extend any more LV's because the VG they reside on is fully used, you extend that VG by adding new PV's to it. Thus the new space is made available to that VG's LV's.
 
Old 01-10-2006, 01:45 PM   #15
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
If you decide to reinstall from scratch (probably the only easy way to move to LVM), take the opportunity to practice some system recovery. When you're ready to to do away with the data on your current hard disk, try destroying your partition table and see if you can recover. Practice. What I do is, AHEAD OF DISASTER, copy the partition table to some unused sector of track 0. What is "unused" will depend on whether you install grub to the MBR or not. But say, for discussion, that sector 50 is unused. Use the dd command to copy sector 0 (your MBR) to sector 50. Then trash your partition table so you can't even boot the beast anymore. Then boot off a Knoppix CD and try using dd to restore your partition table from it's backup copy out there in sector 50. Of course, a backup copy stored on the same disk as the original will not protect you if your disk goes belly up, but it can protect you from your own stupid user errors when you "accidently" hose up your MBR. Store your backup in a couple of different unused sectors just in case. And store a copy off-disk for the really big disasters!

Take advantage of your lame-duck system to practice things that you would be too fearful to practice on a system that was actually in use.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
i need to non-destructively resize a windows ntfs partition hedpe Linux - General 4 09-02-2005 07:17 PM
Resize That Root inescapeableus Linux - Software 3 11-27-2004 08:58 PM
resize hdb1 -root folder!! ngan_yine Linux - Newbie 2 01-15-2004 03:51 PM
how to resize my /root partition Perfekt Linux - Software 4 12-23-2003 09:22 PM
cant resize root thru rescue, auto mounts root dir absolutal Linux - Newbie 0 06-18-2003 03:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:31 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
Open Source Consulting | Domain Registration