Discussion:
bash in chroot: I have no name!
(too old to reply)
Teddy
2005-06-08 20:25:12 UTC
Permalink
I have a chroot environment where I want to start a statically linked
bash-shell (chroot /mnt /usr/bin/env -i PS1='\u:\w\$ ' /bin/bash). I
have set /mnt/etc/password and /mnt/etc/group files (copied from a
working environment) but I always get the prompt:

I have no name!:/#

Do I have to create other files for a working bash (that shows me "root"
as user)?

Thanks
Teddy
Roger Leigh
2005-06-08 20:41:23 UTC
Permalink
Post by Teddy
I have a chroot environment where I want to start a statically linked
bash-shell (chroot /mnt /usr/bin/env -i PS1='\u:\w\$ ' /bin/bash). I
have set /mnt/etc/password and /mnt/etc/group files (copied from a
I have no name!:/#
Do I have to create other files for a working bash (that shows me
"root" as user)?
Do you mean /etc/passwd? This might be the problem. You might also
need /etc/shadow, or any other databases listed in /etc/nsswitch.conf
(copy this, too).

When I have set up chroots, I bind mount the files to keep them in
sync. For example:

$ mount | grep chroot/sid
/dev/mapper/hda_vg-sid_chroot on /srv/chroot/sid type ext3 (rw)
/dev/pts on /srv/chroot/sid/dev/pts type none (rw,bind)
tmpfs on /srv/chroot/sid/dev/shm type tmpfs (rw)
proc on /srv/chroot/sid/proc type proc (rw)
/dev/mapper/hda_vg-home on /srv/chroot/sid/home type ext3 (rw,quota,user_xattr)
/tmp on /srv/chroot/sid/tmp type none (rw,bind)
/etc/passwd on /srv/chroot/sid/etc/passwd type none (ro,bind)
/etc/shadow on /srv/chroot/sid/etc/shadow type none (ro,bind)
/etc/group on /srv/chroot/sid/etc/group type none (ro,bind)
/etc/resolv.conf on /srv/chroot/sid/etc/resolv.conf type none (ro,bind)

Depending on the need for security in the chroot, you might want to
remove some of these mounts.

$ dchroot -c sid id
(sid) id
uid=1000(rleigh) gid=1000(rleigh) groups=20(dialout),24(cdrom),25(floppy),29(audio),40(src),44(video),46(plugdev),1000(rleigh),1001(sbuild)


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
Unruh
2005-06-08 20:50:37 UTC
Permalink
Post by Teddy
I have a chroot environment where I want to start a statically linked
bash-shell (chroot /mnt /usr/bin/env -i PS1='\u:\w\$ ' /bin/bash). I
have set /mnt/etc/password and /mnt/etc/group files (copied from a
I have no name!:/#
Do I have to create other files for a working bash (that shows me "root"
as user)?
Yes. Any command you want to run and any library it uses must be in the
chroot environment. Also bash gets the name from the USER environment variable. It looks to
me like you have only one entry in the environment, and that entry is NOT
the USER entry.
Baho Utot
2005-06-08 21:00:02 UTC
Permalink
Post by Teddy
I have a chroot environment where I want to start a statically linked
bash-shell (chroot /mnt /usr/bin/env -i PS1='\u:\w\$ ' /bin/bash). I
have set /mnt/etc/password and /mnt/etc/group files (copied from a
I have no name!:/#
Do I have to create other files for a working bash (that shows me "root"
as user)?
Thanks
Teddy
Nope.

bash can not read the /etc/passwd file in your chroot enviroment.

Warning backup your /etc/passwd files in case you make a mistake

Go into chroot

Then

cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
EOF

bash should be happy.

In my opinion you should use another place for your chrppt environment as
/mnt should be used as a temporary mount place. See FHS.
--
Tayo'y Mga Pinoy
Loading...