4

I've created a chroot system in my Ubuntu using schroot and debrootstrap, based on minimal ubuntu. However whenever I can't seem to add a new user into this chroot environment. Here is what happens.

  1. I enter schroot as root and add a new user.(Tried both adduser and useradd commands)
  2. The username lists up in /etc/passwd file and I can 'su' into the new user. So far so good.
  3. When I log out of schroot, and re-enter schroot, the user I created has vanished!! There is no mention of that user in /etc/passwd either.

How do I make the new user permanent?

1
  • This sounds strange. First try to be sure that the directories are correct, both when you're inside the chroot and outside. Then, do cat /etc/passwd after creating the user, then log out, and cat the same file, now with chroot directory prefixed. Did it change?
    – maxelost
    Jan 30, 2011 at 22:18

2 Answers 2

4

Oh, I figured it out myself. Schroot has a feature called "sessions" where current environment can be preserved. Everytime one logs out without creating a "session", schroot brings everything to clean state and hence deletes the user as well. One can start a session using

schroot -c mychroot -b 
1
  • Thanks for idea, but note that anyway the users won't persist after system reboot. I added an answer which seems to deal with it.
    – NIA
    Apr 9, 2013 at 7:32
2

Actually, there is a better workaround, that I found it schroot FAQ, in section Why is schroot overwriting configuration files in the chroot?

By default, schroot copies over the system NSS databases ('passwd', 'shadow', 'group', 'gshadow', 'services', 'protocols', 'networks', and 'hosts', etc.) into the chroot. The reason for this is that the chroot environment is not a completely separate system, and it copying them over keeps them synchronised. However, this is not always desirable, particularly if installing a package in the chroot creates system users and groups which are not present on the host, since these will disappear next time the databases are copied over.

In short: each time you start a new schroot session, or after host system reboot, schroot grabs /etc/passwd and some other files from you real system and copies them into chroot, thus losing all new users from it. The suggested workaround is described in this FAQ: you can disable copying this files:

  1. Open /etc/schroot/default/nssdatabases (on your real system, of course)
  2. You will see the lis of so called NSS databases, that are copied from real system.
  3. Comment lines passwd, group and shadow, so that the file looks like this:

/etc/schroot/default/nssdatabases

# System databases to copy into the chroot from the host system.
#
# <database name>
#passwd
#shadow
#group
services
protocols
networks
hosts

Now if you go back inside your chroot and create some users, or install some postgresql etc, new users won't be lost. Even after reboot!

You must log in to answer this question.

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