I'm experiencing a problem with chroot...

I'm running on Arch Linux x86_64.

I have a 64 bit chroot and a 32 bit chroot. They are identical except that one is 32 bit and one is 64 bit.

I can enter either of them using chroot /path/to/chroot. No problems.

If I want to do that as a specific user the command is:

chroot --userspec=user:group /path/to/chroot

This also works fine for the 64 bit chroot. However it fails for the 32 bit chroot. It fails with status 125 and the message chroot: invalid user

Also, doing chroot --userspec=uid:gid /path/to/chroot works fine in both 32 and 64 bit chroots (uid and gid are the numeric ids of the required user and group).

I don't know if I am doing something wrong. is there anyone who has a 32 bit chroot and can see if the above can be reproduced ?

All commands are issued as root. The user and group used for the userspec argument need to be defined inside the chroot.

Or if I am missing something please I would appreciate knowing where I am going wrong.

Update: I am using a work around for this problem. Assuming $user has the user:group I want (e.g. john:users), I do this:

u=$(echo $user | awk -F ":" '{print $1}')
g=$(echo $user | awk -F ":" '{print $2}')
uid=$(grep $u /opt/chroot32/etc/passwd | awk -F ":" '{print $3}')
gid=$(grep $g /opt/chroot32/etc/group  | awk -F ":" '{print $3}')
echo "Using $uid:$gid in place of $user"
chroot --userspec="$uid:$gid" /opt/chroot32

This works - it looks up the desired user:group inside the chroot's passwd and group files and then uses those for the chroot. And the above workaround is not necessary when accessing a 64 bit chroot.

  • I asked the coreutils team about this and I have tested a patch to chroot that fixes the problem. I don't as of yet know if/when it will be released.
    – starfry
    May 2 '12 at 19:47
  • Which patch? does it work? Feel free to answer your own question. May 7 '12 at 14:01
  • I thought I had answered my own question. Like I said, I was sent a patch by coreutils which I applied and it fixed the problem. I thought I had said that ;) There is no "official patch" and they haven't said anything about if/when there will be one. I haven't posted the patch as it was given to me as "tentative". As soon as I hear more I will update it here.
    – starfry
    May 8 '12 at 15:20

You cannot enter a chroot with a username that is not known to the target chroot environment. Copy all required file for user authentication to each chroot: /etc/passwd, /etc/shadow, /etc/nsswitch.conf, and, eventually all files in /etc/pam.d/*. I

  • I had already covered that point in my original question where I said "The user and group used for the userspec argument need to be defined inside the chroot."
    – starfry
    Mar 15 '13 at 14:41
  • You are right.I did not correctly understood that sentence. Maybe you could also try a workaround like preceding your commands with a su --command 'sg $group -c "$command"' $user or write a wrapper script that runs inside the chroot.
    – eppesuig
    Mar 16 '13 at 7:56

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.