My setup requires that some of my /etc files reside on a separate partition. For this purpose I've created a softlink:

ls -li /etc/group
956 lrwxrwxrwx 1 root root 21 May  7 15:48 /etc/group -> /var/common/etc/group

ls -li /var/common/etc/group
3145744 -rw-r--r-- 1 root root 668 May 11 11:02 /var/common/etc/group

My problem is when I try to execute commands using these files:

groupadd foo
groupadd: failure while writing changes to /etc/group

strace reports:

rename("/etc/group+", "/var/common/etc/group") = -1 EXDEV (Invalid cross-device link)
write(2, "groupadd: failure while writing "..., 54groupadd: failure while writing changes to /etc/group
) = 54

Any ideas how I can get groupadd to work?

  • Why that files are on the other partitions? you yourself did it? or it was installed so? On Which distro? – shgnInc May 11 '14 at 9:58
  • CentOS. The system has to be partitioned this way (by me) for various unrelated reasons. – ChaimKut May 11 '14 at 10:00
  • Are you executing the commands using sudo or as root? – ChrisR. May 11 '14 at 10:01
  • Also, I did not think you could make symlinks across partitions. – ChrisR. May 11 '14 at 10:08
  • @ChrisR. Commands are executed as root. Symlinks are allowed across partitions. I can successfully edit the /etc/group file by hand without problem. – ChaimKut May 11 '14 at 10:12

Splitting files in /etc across partitions is a bad idea for this reason.

What is happening is that the groupadd utility is creating a temporary file, and then replacing the real /etc/groups file (or rather, what the symlink points to) with the temporary one via a simple rename operation.
The catch is that rename() only works on the same filesystem, otherwise it throws an error.

Another potential issue you can run into here is that when something goes to do the rename, it clobbers the symlink, and now it's an ordinary file.

Another potential issue is that many files in /etc are required for proper boot, before the system has a chance to mount other volumes. Thus those files will in effect be missing.


In short, no, this can't be fixed. And it shouldn't be done anyway.

| improve this answer | |
  • I completely disagree. This should be done - /etc should be kept in initramfs if done properly. – mikeserv May 11 '14 at 10:30
  • @mikeserv If /etc/ is placed on initramfs, how do you successfully use commands like groupadd, useradd...? – ChaimKut May 11 '14 at 11:22
  • @mikeserv that would be a different setup. The problem here and what Patrick is referring to, is that /etc should not be split across multiple partitions. Not that /etc needs to be on the / partitions, only that everything under /etc be on the same partition. – terdon May 11 '14 at 13:51
  • @Chaimkut You don't need to be rid of initramfs after boot, you know. – mikeserv May 11 '14 at 15:36
  • @terdon actually it does need to be on the / partition. For example, /etc/fstab is needed to mount the other partitions (unless doing some initramfs magic). – Patrick May 11 '14 at 18:19

/etc is meant to be on the root filesystem. The sane thing to do is to keep it that way.

If you really really need to split /etc, you might get better results with a union mount. I don't know if Linux supports union mounts where one of the components matches the mount point, though, and it would be difficult to not make the real /etc on the root filesystem part of the union mount.

If you want to put all of /etc on a different partition, you can make a minimal /etc that contains just what is needed (/etc/fstab, what init needs (/etc/inittab or /etc/init and /etc/rc* or whatever your init system uses), minimal /etc/passwd and /etc/group, etc.). Early during boot (a lot earlier than /etc/rc.local!), bind-mount /var/common/etc onto /etc. But that's going to require a lot of work to get right, and it'll result in /var/common/etc being the whole /etc, which is probably not what you want. This setup mostly makes sense for some embedded systems that don't use any of the usual init systems and have a stringent contraint on the size of the root filesystem.

If you have a /var/common that is shared between many servers, you should approach the problem differently. Use a proper configuration management system to deploy shared files to /etc.

A file like /etc/passwd and /etc/group should not be shared between machines. Use these files only for local users and groups. For entries that are shared across machines, use NIS or LDAP.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.