useradd during preinstall for custom package fails when new zone is created

I have created a custom package. The package needs to create a user, which it does in the preinstall script. pkgadd works fine for the global zone and for any already-installed non-global zones.

However, if I create a new non-global zone, the package is installed but the user is not added (so the software fails to run).

Examining /var/sadm/system/logs/install_log in the non-global zone reveals the error: "username is already in use. Choose another."

The user does not actually exist in the non-global zone. I suspect that the preinstall script actually runs in the global zone when the zone was being installed, and hence was attempting to add the user to the global zone (where the user already existed).

What is the proper way to handle this situation, where a package needs to add users or groups ?

Cheers,

Chris Miles

[868 byte] By [chrismilesa] at [2007-11-27 1:29:51]
# 1

I even tried using chroot $PKG_INSTALL_ROOT in the preinstall, which appears to be what is required. However that still failed. groupadd fails with error "Cannot update system files"

preinstall contained the following:

/usr/sbin/chroot ${PKG_INSTALL_ROOT} /usr/sbin/groupadd -g 5001 groupname

chrismilesa at 2007-7-12 0:30:02 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 2
I can't speak for building packages, but I'd do this as "zlogin <zone> useradd..."
MichaelMyersa at 2007-7-12 0:30:02 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 3
> I can't speak for building packages, but I'd do this> as "zlogin <zone> useradd..."That is not possible. The problem is when the pkg is being added to a new zone as part of the install process. The zone isn't actually operational yet.
chrismilesa at 2007-7-12 0:30:02 > top of Java-index,Solaris Operating System,Solaris 10 Features...
# 4

> I even tried using chroot $PKG_INSTALL_ROOT in the

> preinstall, which appears to be what is required.

> However that still failed. groupadd fails with

> error "Cannot update system files"

This occurred because /etc/group didn't exist yet. This was solved by making SUNWcsu & SUNWcsr dependencies of my package. That way my package is guaranteed to be added after these core system packages are installed.

chrismilesa at 2007-7-12 0:30:02 > top of Java-index,Solaris Operating System,Solaris 10 Features...