Skip to content

Moving /usr to another partition

I recently discovered that my Ubuntu root directory was getting uncomfortably tight from a space perspective (I’d allocated about 6 GB, /home of course lives on a separate partition). The culprit, du soon told me, was /usr, eating up as much as 4 gigs of space. I guess thats because I’ve installed tons of apps, including MATLAB (which eats up a whopping 1.4 gigs).

My primary HDD has a slew of partitions, which I’ve used at various points to test out distros, so I decided to move /usr to a partition I wasn’t using anymore. Initially, I’d thought of moving root itself to another, bigger partition, but after trying to figure out what options to give to grub-install, I decided not to be too adventurous. Maybe another day. In any case, I was nervous enough about moving /usr, though in the end it went off smoothly enough. Here’s how, for anyone who might be looking:

  1. Reboot and select recovery console in GRUB. Ubuntu should have thrown you into a root console.
  2. The partition I want to put /usr into is /dev/hda5. Enter the following commands:
  3. cd /
    mkdir usr_new
    mount /dev/hda5 /usr_new/
    rm -rf /usr_new/*
    cp -dpR /usr/* /usr_new/
    umount /usr_new
    mv /usr /usr_old
    mkdir /usr
    mount /dev/hda5 /usr
  4. Last thing to do is edit your /etc/fstab file. You need to add the following line:
    /dev/hda5 /usr auto defaults,errors=remount-ro 0 1
    It’s possible that a line beginning with /dev/hda5 already exists; if so, replace it with the above.
  5. Type reboot and press Enter. Hopefully, you should be good to go.
  6. If all goes well, when you relogin to Ubuntu, fire up a Terminal and do sudo rm -rf /usr_old.

Important: Be *very careful* while executing the rm -rf commands! The standard rule of the rm command applies… type-rm-minus-rf-star-hands-off-keyboard-STOP-AND-THINK! A mistyped rm -rf /* might be an honest mistake, but it will send the entire darkness of the universe descending upon you.

That I’m going to the trouble of moving around partitions, not to mention writing this post says enough about how much I’ve taken to using Ubuntu Linux as my primary distribution at home. I still prefer Fedora at work though, more on that in another post later, though.

16 Comments

  1. AC wrote:

    Thanks for the work man. I plan to install Ubuntu soon – and knowing me – this info will come in handy pretty soon :)

    Monday, July 17, 2006 at 8:29 pm | Permalink
  2. antrix wrote:

    Why reboot? :-)

    I’ve got couple of pages of notes from my ubuntu install. Too lazy to format it into html for the web, though :(

    Tuesday, July 18, 2006 at 1:42 pm | Permalink
  3. Anshul wrote:

    Reboot to test that all works well. It’s possible to make a small error in fstab or elsewhere and when you finally reboot a few months later you don’t want a nasty surprise.

    Though of course, you can still avoid rebooting by using mount -a.

    Tuesday, July 18, 2006 at 2:37 pm | Permalink
  4. Anshul wrote:

    antrix: if you have notes, might as well put them up – text works fine on the web :D i’d be particularly interested in your RAID setup

    Tuesday, July 18, 2006 at 2:38 pm | Permalink
  5. menthol wrote:

    Thank you for this, very clear. You just made my Gentoo system useable again.

    Saturday, September 2, 2006 at 10:34 pm | Permalink
  6. Swistak wrote:

    Did you experience any problems with hardware clock? After moving /usr in Ubuntu 7.04 it turned out that the clock is set before mounting /usr. It causes improper time settings every time you reboot.

    Thursday, September 6, 2007 at 6:23 pm | Permalink
  7. Anshul wrote:

    Nope, I don’t recall a hardware clock issue. Is the clock set every time you boot? And it can’t find your locale settings? Maybe its different in 7.04

    Thursday, September 6, 2007 at 6:25 pm | Permalink
  8. Swistak wrote:

    Well, the hwclock script is run every time I boot, but for some reason it fails. I changed the name of a symlink in /etc/rcS.d from S11hwclock.sh to S38hwclock.sh, so that it is run after mounting /usr. It works fine until a update is performed. It reverts the change I made.

    Thursday, September 13, 2007 at 10:05 pm | Permalink
  9. Swistak wrote:

    Thank you for suggesting that hwclock may read locale settings. It helped me find a better solution.
    Please see http://ubuntuforums.org/showthread.php?p=3319217 if you are interested in details.

    Friday, September 14, 2007 at 5:06 pm | Permalink
  10. woamba wrote:

    1. “cp -a” is equivalent to “cp -dpR”

    2. imho, the star is not required, i.e. instead of
    “cp -dpR /usr/* /usr_new/”

    it should be possible to use this:

    “cp -a /usr /usr_new”

    Saturday, April 25, 2009 at 5:11 am | Permalink
  11. mattgerg wrote:

    Excellent! This saved the day for me!

    Tuesday, June 16, 2009 at 12:16 pm | Permalink
  12. Neil wrote:

    Great

    Thanks for that, really helped

    Thursday, February 4, 2010 at 8:30 pm | Permalink
  13. mmp wrote:

    perfectly working on a eeepc 701 with jolicloud/ubuntu 9.10.
    maybe you just forgot mkdir /usr_old but a minor issue
    thanks!

    Sunday, March 21, 2010 at 11:23 pm | Permalink
  14. Spica wrote:

    Thanks! I was trying to do this some time ago and your howto works very well on my Eeepc 701, Easy Peasy 1.6 flavor.

    Wednesday, June 2, 2010 at 2:07 pm | Permalink
  15. phirefly wrote:

    A real easy way to do it is through gparted live (or any other liveCD).
    And don’t forget chown -R root /usr

    Monday, February 21, 2011 at 9:17 pm | Permalink
  16. dvdsev wrote:

    Thanks a lot. It worked like a charm

    Wednesday, October 26, 2011 at 9:32 am | Permalink

2 Trackbacks/Pingbacks

  1. [...] filled the sda1 partition, though there was a fair bit of space left on sdb5. While the blog post Moving /usr to another partition is very handy, it doesn’t help much when there isn’t unassigned space or a free [...]

  2. hyperdanja » Blog Archive » links for 2008-11-12 on Thursday, November 13, 2008 at 8:01 am

    [...] the brook :: Moving /usr to another partition Not so easy when only free space was on full partition for /home – but booting from USB live ubuntu allowed partition resizing, bit fiddly. Be sure and back up /home and /usr just to be on the safe side. (tags: ubuntu eeepc space partitions) [...]

Post a Comment

Your email is never published nor shared.