Quote: Visit beautiful Wisconsin Dells.
(Courtesy of fortune cookies)

Welcome to the Cool Spot of the Sun

Migrating /usr to another partition/harddisk

These days linux distros pack a very large number of packages and for people like me, it poses a dilemma. I find myself easily engulfing a 5GB linux partition in days if not hours after installation. For eg Debian comes with about 15000+ packages for a majority of Architectures. A mirror(yeah i tried rsyncing a mirror once) is about the size of 8GB+ for the packages only. A full blown installation will i think take atleast 10GB(IMHO), but i am really not sure of the exact size it will occupy. I guess its more than 10GB. Anyways I find myself many a times filling up a partition fast, very fast.

So whenever i have an extra harddisk, I try to move some stuff on that. Major of my stuff is packages installed and not user files. As one knows most packages are installed in /usr, and this is sometimes the most filled up directory. Moving it to another harddisk is the most logical solution.

Unlike windows, Linux uses /dev to store the hardware device nodes, so basically there is no concept of a a drive like C:. This makes moving stuff easier than windows. Windows program if moved requires the corresponding links also updated.

To sum it up we will have to first make a harddisk ready and then move stuff. As our new /usr will be on the new harddisk we have to make sure that /usr entry is added to the /etc/fstab. At this point there are 2 possibilities. Either that the original /usr had its own dedicated partition or it was mounted as a subdirectory of /. If it had its own dedicated partition we need to update the /etc/fstab and point to the new partition that is if we had moved it from /dev/hda3 to /dev/hda4, but we would do the updating afterwards.

we need to mount our partition first at this point which can be done by first making a temporay directory in / say /usrtemp using the command mkdir /usrtemp . After doing that we mount our partition.

mount -t ext3 /dev/hdaX /usrtemp

Where hdaX is your partition device file name(Tip. devices on primary cable are normally hda and hdb whereas on secondary cable are hdc and hdd). Once the above is done all you have to do is copy the old partition files to the new partition.

cp -r /usr /usrtemp

CP, I am really not sure if its the right command to use for copying here. Its said 'tar' is a better option as it preserves user permissions.

Once this is done all we need to do is add the following line or update the line(if present) in /etc/fstab

/dev/hdaX /usr ext3 defaults 1 1

Again hdaX is user dependent. Please refer to format of /etc/fstab if the above confuses you. Now we made sure that when we reboot the new /usr is taken from the new partition. Now rename the old partition.

mv /usr /usrtodelete

Now reboot the machine and than delete the old /usrdelete if everything goes on fine.

rm -rf /usrdelete

Get Firefox!  Use OpenOffice.org lastRSS.php - RSS parser for PHP Valid HTML 4.01! Valid CSS! IP Address Lookup


The visitor number 13195
Disclaimer