4

How to put /etc on separate partition? Obviously i can't do that by editing /etc/fstab like i did with /home, because... it's in /etc. I want /etc and /home on one partition (sda7), and the rest on the other (sda6). I guess /etc must be symlink to /mnt/part2/etc (/mnt/part2 being mount point of sda7), and same with /home. But how to tell the system to mount part2 without access to fstab?

I'm using Arch Linux x64, if that helps.

5
  • 2
    You must make your own kernel patched in way that it will automount your etc before init. Or you could make minimal bin dev etc lib proc sysdisk with minimal libraries / utilities (sh, mount and few libs). Will easily fit under 1MB... btw. this is somewhat same as asking about how to build house without walls, you can do that but it is mostly useless and it will be hard to add walls afterwards. Commented May 30, 2013 at 19:23
  • I just learned that it's pretty much undoable. But not because of Linux - because of systemd. Gonna get back to this when I'll have full week free for switching from systemd to something else. Thank you all guys for your support. And inb4: you say it's pointless. I say, maybe, but this is the reason I have Linux in the first place - to have fun while messing with it!
    – Xirdus
    Commented May 30, 2013 at 20:05
  • use lvm and don't put /etc on a different partition Commented May 30, 2013 at 20:12
  • But more seriously, dude, don't try this unless you really, really, really know what you're doing because one mistake will likely render your system unbootable. More to the point, /etc will rarely exceed a couple dozen megabytes at most unless you're doing something incredibly stupid elsewhere down the line, so it literally fits into a hollow tooth. Keep it with / like absolutely everyone does. Commented May 31, 2013 at 9:59
  • @Xirdus Again,the same thing we said about writing a kernel patch would also apply to systemd -- and it still is a bad idea. Commented Jun 1, 2013 at 14:46

5 Answers 5

11

One of the first things a linux system is doing is mounting all file systems to the correct mountpoint in order to let all other parts of the system find their files.

The root file system is usually given on the kernel command line. It will mount this file system and look in /etc/fstab for all the other mount points.

If you really want to do anything weird before this happens you can use the initrd for those kind of setup.

0
7

I want /etc and /home on one partition

No you don't. It's like asking to have your brain transplanted to your knee :-) Whatever your problem is, making /etc a separate partition or merging it with /home is not the solution. What is the actual problem you want to solve?

7
  • 2
    +1 for asking the important question of what he's trying to accomplish. Commented May 31, 2013 at 10:07
  • 1
    I don't know about the original poster, but I am interested in this because just as I can share my home folder and ~/.config among linux installations, I was wondering if I could share /etc the same way and that way installing distros / upgrading would be even more easy and require less reconfiguration.
    – Wizek
    Commented Feb 22, 2016 at 12:58
  • @Wizek Since /etc contains a lot of host-specific configuration (e.g. /etc/fstab) that is something you really can't easily share across systems. Anything that has a nodename in it is host-specific and would need special treatment.
    – Jens
    Commented Feb 22, 2016 at 13:37
  • That makes sense. But doesn't /etc contain at least some configurations that are host-independent? And might make sense to share between hosts? As a ballpark, what would you say the percentage is? 99% host specific? Or perhaps 80%, 50%, 20% or 1% host-specific?
    – Wizek
    Commented Feb 22, 2016 at 13:42
  • @Wizek Yes, but sharing at the mount point level is far too coarse. If I'd contemplate sharing /etc I'd do it at the file level (i.e. using git, mercurial, rsync, or even Makefiles with a "scp" target.) That's pretty much what Sun's YP (Yellow Pages) did in the olden days. Also consider failure scenarios such as /etc not being mountable; then you just made a large number of systems unusable.
    – Jens
    Commented Feb 22, 2016 at 14:32
7

The simple answer is you don't. /etc is where all the configuration stuff is: how can the system operate if it doesn't know where to find its configuration? Why would you even want to do that?

1
  • 1
    This is right. Any directory that must exist at the early stages of boot must be part of /.
    – jordanm
    Commented May 30, 2013 at 18:43
2

Not a straight up answer, but it may help:

The directory /etc stores the configuration for your operating system, therefore it should be considered a good idea to have your configuration with your operating system, that is on the same partition. To keep a sensible backup or maybe even share configurations, you could use git:

  • create a git repository from your /etc and clone/put it to whereever you want to store it
  • write an init script which does a git pull on "start" to get the most recent version from that special partition into /etc
  • put the script right after said partition is mounted in your bootup order, somewhere in runlevel S
  • have the script do a git commit and git push on shutdown/reboot to save your current configuration

Two advantages:

  1. when something breaks you will always have your configuration where the OS expects it to be
  2. you will have versioning and can revert and debig your configurations if you messed up
1
  • This sounds like a poor man's etckeeper, which is likely to break file permissions and compromise the system.
    – Mårten W
    Commented Sep 4, 2022 at 14:31
0

This is a terrible, terrible idea, and I can't honestly think of a single situation where it'd even be desirable.

However, if you really want to do this, your best bet would be to write a kernel patch to make it take a second argument similar to root=/dev/sda1 that lets you specify etc=/dev/sda2 as well, then have it try to mount /etc from there after mounting root and before attempting to execute init.

Note that any single mistake at this point would render your entire system unbootable unless you had the sanity to set up a safe fallback /etc on the root partition.

3
  • 2
    Here's a good reason: Making /etc a separate dataset in a zfs pool allows you to back up /etc independently.
    – FUZxxl
    Commented Dec 1, 2016 at 0:24
  • 1
    @FUZxxl And this is a substantial improvement over, say, tar -jcvf /backup/etc.tar /etc how, precisely? Commented Dec 1, 2016 at 8:58
  • 3
    I do backup with zfs snapshots, sending them over the network with zfs send. Having /etc on a separate dataset allows me to treat it the same way as all other datasets.
    – FUZxxl
    Commented Dec 1, 2016 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .