My /usr
folder needs to get moved to a new partition. How can I do this without erasing the contents?
Can this be done while Ubuntu is running, or do I need to use the LiveCD for this?
My /usr
folder needs to get moved to a new partition. How can I do this without erasing the contents?
Can this be done while Ubuntu is running, or do I need to use the LiveCD for this?
It would be safest to use a Live CD, but you could do:
/usr
do not change while you are doing this./etc/fstab
so that/usr
will be mounted on the next rebootSee below for details on each step.
Note that you can't mount the new partition on
/usr
while running as there will be lots of files in/usr
that will be open.Copying the files
I would use
cp -a
.-a
is the archive option. From the man page:Editing /etc/fstab
You need to know the UUID of your new partition. You can see the mapping by doing:
or
And then add this line to
/etc/fstab
:Change the UUID to your UUID, and change
ext4
to be the file system type you are using - you should know this if you have set up the partition.Delete the old files
After the reboot, the old files in
/usr
on the root partition will be hidden by the new partition mounted on/usr
. But we can use some mount bind trickery to get to the old files and then delete them.But some slight mistyping (say, hitting Enter when you'd only typed
sudo rm -rf /mnt
) could cause disaster, so I would only use this method if you were very confident in what you were doing, really couldn't deal with any downtime, or had no physical access to the machine and hence were unable to boot off a live CD or live USB stick.Since most libraries that are used are in /usr, I would not recommend to move this directory while running Ubuntu. In fact, you probably get error messages when you try to do this. Hence, the best is to use the LiveCD.
You can use several possibilities to move/copy the files cp, rsync etc. you want to make sure that any symlinks are created and not just copied. cp and rsync both have options for this.
After moving the files to the other partition you need to add another mount in /etc/fstab to mount the new partition to /usr.
This is how I've done it (following the Hamish's answer and the comments):
Copy all the files the newly created partition (replace with the location of your partition, it should look similar to mine):
Edit
/etc/fstab
(same as in Hamish's answer, of course, replacexxxxxx
with your UUID)Reboot the system
After rebooting, open System Monitor or similar application to see whether your new
/usr
partition is mounted, and to safety-check whether everything went as planned.After checking that everything is alright, you can delete your old
/usr
partition. I will keep mine just in case something goes wrong.