首次构建Yocto Kirkstone时systemd_create_users报错求助
问题背景
从Dunfell切换到Kirkstone版本为Boundary Devices i.MX8MM平台构建Yocto,所有recipe编译成功,但rootfs生成阶段执行systemd_create_users时出现错误,核心报错为configuration error - unknown item 'SYSLOG_SU_ENAB'和configuration error - unknown item 'SYSLOG_SG_ENAB',同时伴随用户/组已存在、无效UID等问题。未修改过systemd_create_users()函数及相关用户配置文件,也找不到SYSLOG_SU_ENAB的引用。
错误日志片段
NOTE: Executing systemd_create_users ... DEBUG: Executing shell function systemd_create_users configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) Usage: useradd [options] LOGIN useradd -D useradd -D [options] Options: --badnames do not check for bad names -b, --base-dir BASE_DIR base directory for the home directory of the new account --btrfs-subvolume-home use BTRFS subvolume for home directory -c, --comment COMMENT GECOS field of the new account -d, --home-dir HOME_DIR home directory of the new account -D, --defaults print or change default useradd configuration -e, --expiredate EXPIRE_DATE expiration date of the new account -f, --inactive INACTIVE password inactivity period of the new account -g, --gid GROUP name or ID of the primary group of the new account -G, --groups GROUPS list of supplementary groups of the new account -h, --help display this help message and exit -k, --skel SKEL_DIR use this alternative skeleton directory -K, --key KEY=VALUE override /etc/login.defs defaults -l, --no-log-init do not add the user to the lastlog and faillog databases -m, --create-home create the user's home directory -M, --no-create-home do not create the user's home directory -N, --no-user-group do not create a group with the same name as the user -o, --non-unique allow to create users with duplicate (non-unique) UID -p, --password PASSWORD encrypted password of the new account -r, --system create a system account -R, --root CHROOT_DIR directory to chroot into -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files -s, --shell SHELL login shell of the new account -u, --uid UID user ID of the new account -U, --user-group create a group with the same name as the user groupadd: GID '65534' already exists configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) useradd: invalid user ID '65534:65534' groupadd: group 'adm' already exists configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) groupadd: group 'utmp' already exists groupadd: group 'audio' already exists groupadd: group 'cdrom' already exists groupadd: group 'dialout' already exists groupadd: group 'disk' already exists groupadd: group 'input' already exists groupadd: group 'kmem' already exists groupadd: group 'kvm' already exists groupadd: group 'lp' already exists configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) groupadd: group 'tape' already exists groupadd: group 'tty' already exists groupadd: group 'video' already exists groupadd: group 'users' already exists configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) useradd: user 'messagebus' already exists groupadd: group 'systemd-journal' already exists configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) useradd: user 'systemd-network' already exists configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) useradd: user 'systemd-resolve' already exists configuration error - unknown item 'SYSLOG_SU_ENAB' (notify administrator) configuration error - unknown item 'SYSLOG_SG_ENAB' (notify administrator) useradd: user 'systemd-timesync' already exists DEBUG: Shell function systemd_create_users finished
解决思路
1. 定位login.defs来源
SYSLOG_SU_ENAB和SYSLOG_SG_ENAB是shadow-utils旧版本中的配置项,Kirkstone版本默认使用的shadow-utils已移除这些配置。报错说明rootfs中存在旧版的/etc/login.defs文件,可能来自:
- 自定义layer中添加的
login.defs文件 - 从Dunfell版本继承的配置文件(比如
files/目录下的旧文件未更新) - 某个recipe(如
shadow或自定义用户配置recipe)打包了旧版login.defs
执行以下命令在构建目录中搜索包含这两个配置项的文件:
grep -r "SYSLOG_SU_ENAB\|SYSLOG_SG_ENAB" build/
找到后替换为shadow-utils新版的配置,或者直接删除这两个无效项。
2. 排查用户/组重复创建问题
日志中出现的GID '65534' already exists、user 'messagebus' already exists等错误,是因为systemd_create_users执行时,部分系统用户/组已被其他流程(如base-passwd或其他用户管理recipe)创建。可以:
- 检查
DISTRO_FEATURES中是否同时启用了systemd和sysvinit,导致用户创建逻辑冲突。Kirkstone推荐纯systemd环境,确保DISTRO_FEATURES中移除sysvinit相关项。 - 检查自定义用户配置文件(如
*.user或group文件)是否与系统默认用户/组UID/GID重复,尤其注意65534(nobody用户的UID/GID)是否被重复定义。
3. 清理构建缓存
切换版本后未清理缓存可能导致旧文件残留,执行以下命令清理后重新构建:
bitbake -c cleansstate <image-name> rm -rf build/tmp
内容的提问来源于stack exchange,提问作者Kile

