By Kurt Seifried, [email protected]
Please note: these are advanced filesystem management tricks. You may break things. You may break your system. These tricks (usually) work on my test systems (please note I mostly test this under VMWare so that I can "refresh" the OS quickly if it does break horribly, this will not be so easy on a real system).
This is a question I've seen quite a few times, it's dangerous, but useful. You can't make /etc a separate partition with setting things up first, for one thing when the system boots there won't be an /etc/fstab to read and figure out how to mount anything. This means that portions of /etc must exist at boot time. The trick is, on most UNIX systems, you can mount a partition over a non-empty directory. This means that by leaving a "stub" /etc partition containing the necessary boot files you can easily boot the system and then have it mount a different partition onto /etc.
The reasons for doing this are numerous, for one thing you could conceivably mount your /etc over NFS, although what circumstances would lead to this are beyond my imagination. A more common reason is out of security concerns, by mounting /etc as a partition you can prevent hard links to files in /etc, you can mount it read only (although you will be unable to change system configuration or user passwords unless you remount the partition writeable), and so on. Mounting /etc as a ramdisk is another conceivable desire, this would speed up access, however is lookups of usernames/etc are an issue you may consider running something like the name service cache daemon.
For this example the stub /etc/ resides on /dev/wd0a, and the /etc partition we wish to mount is on /dev/wd0d.
Step one is making sure you have enough files in the stub /etc to run the system, this is pretty easy, simply leaving all the files in there from the installation will typically do. The next step is to create and format a different partition, such as "/dev/wd0d", it need not be very large, a few megabytes will suffice. Backup the stub /etc using tar, make sure you preserve file permissions and symbolic links:
# cd /etc # tar -cvpf /etc.tar *
Now mount the partition you wish to host /etc on in a different directory and untar the files onto it:
# mount /etc2 # cd /etc2 # tar -xvf /etc.tar
Now simply modify the fstab file in the stub /etc directory on /dev/wd0a so that it mounts /dev/wd0d as /etc:
/dev/wd0d /etc ffs rw 1 2
You can now manually mount /etc. or simply reboot the system for the changes to take effect.
Of course this creates a new problem, how do you access the stub partition? Unmounting the /dev/wd0d /etc to access /etc on /dev/wd0a is one option, but things may break since files are suddenly missing or changes such as adding users are no longer there. One solution is to simply create a directory such as /etc-real and in it create hard links to the files in the stub /etc, since hard links point to the file inode even if the "real" files are inaccessible you can access them via the hard links.
Last updated on 18/7/2002
Copyright Kurt Seifried 2002 [email protected]