-   Linux - Newbie (
-   -   LFS /tools/bin/groups not displaying supplementary groups (

grail 06-08-2010 02:56 AM

LFS /tools/bin/groups not displaying supplementary groups
Always good to become the newbie again :)

So i am at the stage of about to install the basic system and am using a derivation of the package management provided by Matthias S. Benkmann.
To this end I am using his useradd and groupadd scripts to update the files:

My issue is that when I run the commands(created as part of temporary system when installing coreutils):

/tools/bin/su linux
#then as user


(here linux is the name of the user)

This only returns the user being in the group named after user but not the additional group of 'install'

Also, prior to logging in as user, if I use this command as root:

/tools/bin/groups linux

linux install

This then returns that the user is in the correct groups.

Lines from relevant files look like:



Any help would be greatly appreciated as to which stupid error I have made :)

Cheers grail

Agrouf 06-09-2010 04:30 AM

Any pointer to Matthias S. Benkmann's scripts? What is the script code? What are they supposed to do, what did you expect them to do, and what is it actually doing?

business_kid 06-09-2010 04:32 AM

You're in the LFS book, chapter 5?
They say FBBG Follow Book - Book Good.
What page are you on? Or is this an external trick, in which case you're on your own.
I don't think you need users to start chapter 6. In chapter 6, you're in a chroot to /tools, so you don't see /tools

grail 06-09-2010 05:25 AM

@Agrouf - Yes I used "Matthias S. Benkmann's scripts" as a guideline.


if [ $# -ne 11 -o z$1 != z-d -o z$3 != z-g -o z$5 != z-G -o z$7 != z-s -o z$9 != z-u ]; then
echo 1>&2 USAGE: useradd -d home -g maingroup -G addgroup -s shell -u uid login
exit 1

#test if user already exists
grep "^${11}:.*" /etc/passwd
if [ $? -eq 0 ]; then
  echo 1>&2 $0: User does already exist
  exit 1

g=`grep ^${4}:.\* /etc/group | cut -d : -f 3 -`
if [ z${g} = z ]; then
  echo 1>&2 $0: Group ${4} does not exist!
  exit 1

grep ^${6}:.\* /etc/group >/dev/null || \
  echo 1>&2 $0: Group ${6} does not exist!
  exit 1

cp /etc/passwd /tmp/passwd123456
echo "${11}:x:${10}:$g::$2:/bin/bash" \
| sort -t : -k3,3n -m /tmp/passwd123456 - > /etc/passwd

cp /etc/group /tmp/group123456
sed  -e 's/^\('"${6}"':[^:]*:[0-9]*:..*\)$/\1,'"${11}"'/' \
    -e 's/^\('"${6}"':[^:]*:[0-9]*\):$/\1:'"${11}"'/' \
                                                    /tmp/group123456 >/etc/group


if [ $# -ne 3 -o z$1 != z-g ]; then
echo 1>&2 USAGE: groupadd -g gid groupname
exit 1

#test if group already exists
grep "^${3}:.*" /etc/group
if [ $? -eq 0 ]; then
  echo 1>&2 $0: Group does already exist
  exit 1

cp /etc/group /tmp/group123456
echo ${3}:x:${2}: | sort -t : -k3,3n -m /tmp/group123456 - > /etc/group

Both of these update the two corresponding files correctly.

@business_kid - I am on page 6.7 Linux-2.6.34 API Headers. Your following statement is not quite correct:

I don't think you need users to start chapter 6. In chapter 6, you're in a chroot to /tools, so you don't see /tools
When you chroot you are in the top level of the mounted directory which does contain tools directory

export LFS=/mnt/lfs
mkdir -pv $LFS
mount -v -t ext3 /dev/<xxx> $LFS

mkdir -v $LFS/tools

So from this you can see that tools dir is under /mnt/lfs

Then the chroot is:

chroot "$LFS" /tools/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h

So here we have chrooted into /mnt/lfs

Upshot is, I am still stuck with root being able to get the right groups with the command but not a user who is being su'ed into.

Agrouf 06-09-2010 05:38 AM


Originally Posted by grail (Post 3997610)
Upshot is, I am still stuck with root being able to get the right groups with the command but not a user who is being su'ed into.

Sorry, I read your posts 3 times and I still don't get what your problem is. Which command are you talking about in that sentence?
I understood you want linux in groups linux and install. It looks like /etc/group contains the right groups but /mnt/lfs/etc/group does not contain it?
Could you please post the commands you type one by one, the result you get and the result you expect?
something like that:

I type this:

$ ls
file1 file2 file3

And I expect this:

$ ls

Agrouf 06-09-2010 05:51 AM

Sorry, I've reread a 4th time and I think I get it now.
Basically, you do this:

# /tools/bin/groups linux
linux install
# /tools/bin/su linux
$ /tools/bin/groups

And you expect that:

# /tools/bin/groups linux
linux install
# /tools/bin/su linux
$ /tools/bin/groups
linux install


Is /tools/etc/groups readable by everybody? It should be 644

grail 06-09-2010 05:54 AM

No probs :)

As root in chroot environment:

root# groups linux

linux : linux install

root# su linux

linux$ groups


grail 06-09-2010 05:55 AM

Yes that's what I expect and yes it is readable.

grail 06-09-2010 10:57 PM

Ok ... so I have done some more testing and thought I would also explain why I thought this was necessary:

1. Extra testing - interestingly, even though when the user runs groups command on its own it does not display the extra group(s), if I submit the following:

linux$groups linux
I get:

linux : linux install
Which is the output I expected???

2. Reason for query - i was installing another program, man-pages, and this is done as the man-pages user. As per the LFS instructions the install is very simply:

make install
This now runs the following for loop as per the Makefile contained in the package:

for i in man?; do \
    install -d -m 755 $(DESTDIR)$(MANDIR)/"$$i" || exit $$?; \
    install -m 644 "$$i"/* $(DESTDIR)$(MANDIR)/"$$i" || exit $$?; \

Where DESTDIR is blank and MANDIR=/usr/share/man.

Now as part of LFS you create these directories already and also:

On my system there is an extra step where I change the group to be install and the permissions to be 775 so group can make changes.

On executing the first line in the "for" example above the script hits an error that permission is denied on changing the permissions, hence why I looked
to see what groups had been assigned to the user, in this case man-pages (linux was just shorter to type before), and on typing in the "groups" command
was told that man-pages (and later i found linux also) was not considered in the install group :(

I have since made a change to the Makefile to test if folder already exists and only then use the install -d -m line.

My question now I guess two fold:

1. Still why the erroneous output when submitting just the "groups" command as normal user?

2. Was this lack of acknowledgement of the install group the reason why the man-pages user was unable to execute the following example:

install -d -m 755 /usr/share/man/man1

All times are GMT -5. The time now is 11:18 AM.