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:
- Reboot and select recovery console in GRUB. Ubuntu should have thrown you into a root console.
- The partition I want to put /usr into is /dev/hda5. Enter the following commands:
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- Last thing to do is edit your
/etc/fstabfile. 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. - Type
rebootand press Enter. Hopefully, you should be good to go. - 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.
AC | 17-Jul-06 at 8:29 pm | Permalink
Thanks for the work man. I plan to install Ubuntu soon – and knowing me – this info will come in handy pretty soon :)
antrix | 18-Jul-06 at 1:42 pm | Permalink
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 :(
Anshul | 18-Jul-06 at 2:37 pm | Permalink
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.
Anshul | 18-Jul-06 at 2:38 pm | Permalink
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
menthol | 02-Sep-06 at 10:34 pm | Permalink
Thank you for this, very clear. You just made my Gentoo system useable again.
Swistak | 06-Sep-07 at 6:23 pm | Permalink
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.
Anshul | 06-Sep-07 at 6:25 pm | Permalink
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
Swistak | 13-Sep-07 at 10:05 pm | Permalink
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.
Swistak | 14-Sep-07 at 5:06 pm | Permalink
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.
hyperdanja » Blog Archive » Machine Admin - Ubuntu, dead HD, EeePC space, USB stick backups etc. | 12-Nov-08 at 7:55 pm | Permalink
[...] 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 [...]
hyperdanja » Blog Archive » links for 2008-11-12 | 13-Nov-08 at 8:01 am | Permalink
[...] 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) [...]
woamba | 25-Apr-09 at 5:11 am | Permalink
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”
mattgerg | 16-Jun-09 at 12:16 pm | Permalink
Excellent! This saved the day for me!
Neil | 04-Feb-10 at 8:30 pm | Permalink
Great
Thanks for that, really helped