The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Partitioning in Action, Part 2"
(Created page with "{{Article |Subtitle=Consolidating data |Summary=In this second tip on changing partition layout on a running system, Daniel Robbins shows you how to move /tmp and /var to thei...") |
|||
Line 5: | Line 5: | ||
|Previous in Series=Partitioning in Action, Part 1 | |Previous in Series=Partitioning in Action, Part 1 | ||
}} | }} | ||
=== Introduction === | === Introduction === | ||
Line 23: | Line 21: | ||
</console> | </console> | ||
== Mount it to /mnt/rwstorage == | === Mount it to /mnt/rwstorage === | ||
As in my previous tip, ??? should be replaced with the device name for the new, empty partition that you are creating. Accidentally typing the wrong name will destroy data on an existing partition, so be careful! After typing this command, you'll have a brand-new ext2 filesystem on the new partition. We're almost ready to mount it, but first, let's make a new mount point. | As in my previous tip, ??? should be replaced with the device name for the new, empty partition that you are creating. Accidentally typing the wrong name will destroy data on an existing partition, so be careful! After typing this command, you'll have a brand-new ext2 filesystem on the new partition. We're almost ready to mount it, but first, let's make a new mount point. | ||
Line 37: | Line 35: | ||
</console> | </console> | ||
== Creating a new /tmp == | === Creating a new /tmp === | ||
The partition is now mounted and we're ready to create our new /tmp directory: | The partition is now mounted and we're ready to create our new /tmp directory: | ||
Line 47: | Line 45: | ||
</console> | </console> | ||
== Drop to single-user mode == | === Drop to single-user mode === | ||
Our new directory at /mnt/rwstorage/tmp has the right permissions for a temporary directory. Now, drop to single-user mode, since we must copy over /var. As usual, we've delayed our drop to single-user mode to the last possible moment. Right now, we don't want any programs reading or writing files in /var, so we have to stop all daemons, disconnect all users, and do some quick maintenance by typing: | Our new directory at /mnt/rwstorage/tmp has the right permissions for a temporary directory. Now, drop to single-user mode, since we must copy over /var. As usual, we've delayed our drop to single-user mode to the last possible moment. Right now, we don't want any programs reading or writing files in /var, so we have to stop all daemons, disconnect all users, and do some quick maintenance by typing: | ||
Line 62: | Line 60: | ||
</console> | </console> | ||
== Copy /var == | === Copy /var === | ||
Default permissions on our new /mnt/newstorage/var directory should be correct, so now we're ready to copy all of our original /var data over to the new partition: | Default permissions on our new /mnt/newstorage/var directory should be correct, so now we're ready to copy all of our original /var data over to the new partition: | ||
Line 71: | Line 69: | ||
</console> | </console> | ||
== Back up and create symlinks == | === Back up and create symlinks === | ||
After this command completes, you'll have an exact copy of /var at /mnt/rwstorage/var. Now, you may be asking how exactly we get Linux to use /mnt/rwstorage/var and /mnt/rwstorage/tmp instead of the defaults in the root directory. This is easily done by the use of symbolic links -- we'll create the new symbolic links, /tmp and /var, which point to the correct directories in /mnt/rwstorage. First, let's back up the original directories: | After this command completes, you'll have an exact copy of /var at /mnt/rwstorage/var. Now, you may be asking how exactly we get Linux to use /mnt/rwstorage/var and /mnt/rwstorage/tmp instead of the defaults in the root directory. This is easily done by the use of symbolic links -- we'll create the new symbolic links, /tmp and /var, which point to the correct directories in /mnt/rwstorage. First, let's back up the original directories: | ||
Line 89: | Line 87: | ||
</console> | </console> | ||
== Finishing touches to /etc/fstab == | === Finishing touches to /etc/fstab === | ||
Now, when any user or program uses /var, they'll automatically be transported to /mnt/rwstorage/var! Likewise for /tmp. We have one step left; however, it can be safely performed in multiuser mode. It's time to get Apache running again, and to allow all your users to log back in. Exit from runlevel 1 by pressing CTRL-D. The system should start up normally. Log in as root. | Now, when any user or program uses /var, they'll automatically be transported to /mnt/rwstorage/var! Likewise for /tmp. We have one step left; however, it can be safely performed in multiuser mode. It's time to get Apache running again, and to allow all your users to log back in. Exit from runlevel 1 by pressing CTRL-D. The system should start up normally. Log in as root. |
Latest revision as of 01:26, January 2, 2015
Consolidating data
Introduction
In my last tip, we successfully moved /home to a new partition. Now, it's time to learn how to consolidate often-modified files onto a new partition. Why would we want to do this? Here's an example. Often-modified files contribute heavily to fragmentation. One of the best ways to contain fragmentation is to store often-modified files on their own partition. That way, the other partitions are unaffected by the fragmentation caused by the heavily modified files. In concept, this is easy to understand, but how do you actually go about doing it?
First, you must create a new partition for the specific purpose of storing frequently modified files. You might want to locate this partition on a separate disk to enhance performance. Then, I'll walk you through the steps required to move both /tmp and /var to this new partition.
The following technique describes how to move a partition(s). Although this technique is designed so that you can "back out" of a failed partition move, it doesn't protect against user error. In other words, any time that you format partitions or copy large numbers of files, there's a possibility that you will type the wrong thing, causing lots of data to be destroyed. For this reason, it's highly recommended that you take appropriate steps to back up all critical files before proceeding.
Create a filesystem on the new partition
The first step of this process is to create a new partition that's big enough to hold /var and /tmp, with a little extra space left over. You'll need either an additional drive, or a spare (unused) partition that will house the often-modified files. If you do need to use fdisk or cfdisk to create the partition, you'll need to reboot once. Then, it's time to format the new partition as follows (it's OK to be in multiuser mode while you do this; I'll let you know when to switch to single-user):
root # mkfs.ext2 /dev/???
Mount it to /mnt/rwstorage
As in my previous tip, ??? should be replaced with the device name for the new, empty partition that you are creating. Accidentally typing the wrong name will destroy data on an existing partition, so be careful! After typing this command, you'll have a brand-new ext2 filesystem on the new partition. We're almost ready to mount it, but first, let's make a new mount point.
root # mkdir /mnt/rwstorage
I chose the name rwstorage to remind us that this particular partition is going to be specifically used to house files that are read from and written to frequently. To mount the partition, type:
root # mount /dev/??? /mnt/rwstorage
Creating a new /tmp
The partition is now mounted and we're ready to create our new /tmp directory:
root # cd /mnt/rwstorage root # mkdir tmp root # chmod 1777 tmp
Drop to single-user mode
Our new directory at /mnt/rwstorage/tmp has the right permissions for a temporary directory. Now, drop to single-user mode, since we must copy over /var. As usual, we've delayed our drop to single-user mode to the last possible moment. Right now, we don't want any programs reading or writing files in /var, so we have to stop all daemons, disconnect all users, and do some quick maintenance by typing:
root # init 1
If you're prompted to enter a password to perform system maintenance, do so. You should now have a root shell, and all unnecessary daemons will be stopped. Create a new location for our /var files by typing:
root # cd /mnt/rwstorage root # mkdir var
Copy /var
Default permissions on our new /mnt/newstorage/var directory should be correct, so now we're ready to copy all of our original /var data over to the new partition:
root # cd /var root # cp -ax * /mnt/rwstorage/var
Back up and create symlinks
After this command completes, you'll have an exact copy of /var at /mnt/rwstorage/var. Now, you may be asking how exactly we get Linux to use /mnt/rwstorage/var and /mnt/rwstorage/tmp instead of the defaults in the root directory. This is easily done by the use of symbolic links -- we'll create the new symbolic links, /tmp and /var, which point to the correct directories in /mnt/rwstorage. First, let's back up the original directories:
root # cd / root # mv var var.old root # mv tmp tmp.old
The last line probably isn't necessary, since it's very likely that you don't have anything important in /tmp, but we're playing it safe. Now, let's create the symlinks:
root # cd / root # ln -s /mnt/rwstorage/var /var root # ln -s /mnt/rwstorage/tmp /tmp
Finishing touches to /etc/fstab
Now, when any user or program uses /var, they'll automatically be transported to /mnt/rwstorage/var! Likewise for /tmp. We have one step left; however, it can be safely performed in multiuser mode. It's time to get Apache running again, and to allow all your users to log back in. Exit from runlevel 1 by pressing CTRL-D. The system should start up normally. Log in as root.
The final thing we must do is configure /etc/fstab so that /dev/??? is mounted at /mnt/rwstorage. You must add a line like the following to your /etc/fstab:
/dev/??? /mnt/rwstorage ext2 defaults 1 2
After saving the changes to /etc/fstab, your system has been successfully upgraded! After verifying that everything is working properly, you'll want to remove the /tmp.old and /var.old backup directories. Congratulations -- you've successfully reconfigured your system's partitions for optimum performance.
Browse all our available articles below. Use the search field to search for topics and keywords in real-time.