识别 nsswitch 库的体系结构依赖位置

Identifying architecture dependent location of nsswitch libraries

我有一个 DEB 包,它在 package postinst 帮助脚本中动态创建一个 chroot 文件系统。该软件包适用于 Debian Stretch/Buster/Bullseye 和 Ubuntu Bionic/Focal/Jammy 上的 x86、amd64 和 arm64。但是,我最近尝试在 Raspbian arm32 上安装它,但失败了。

问题是 nsswitch 库的路径名构造方式与其他平台不同。换句话说,使用 uname -m 的库路径的碎片程序集与文件系统中存在的内容不匹配。

#!/bin/bash -eu

U=chroot_user
UHOME=/home/$U
ARCH=$(uname -m)

function add_executable () {
  FROM=""; shift
  TO="$(basename $FROM)"
  if [ $# -ge 1 ]; then
    TO=; shift
  fi
  cp "$FROM" "$UHOME/bin/$TO"
  ldd "$FROM" | grep "=> /" | awk '{print }' | xargs -I '{}' cp '{}' $UHOME/lib/

  LIBNAME="ld-linux-$(echo $ARCH | tr '_' '-').so*"
  if compgen -G "/lib64/${LIBNAME}" > /dev/null; then
    cp /lib64/${LIBNAME} $UHOME/lib64/
  elif compgen -G "/lib/${LIBNAME}" > /dev/null; then
    cp /lib/${LIBNAME} $UHOME/lib/
  fi
}

if [ "" = "configure" ]; then

  # Create a system user that has restricted bash as its login shell.
  IS_USER=$(grep $U /etc/passwd || true)
  if [ ! -z "$IS_USER" ]; then
    killall -u $U || true
    userdel -f $U > /dev/null 2>&1 || true
  fi
  adduser --system --home ${UHOME} --no-create-home --group --shell /bin/rbash ${U}

  # Create a clean usable chroot
  rm -rf $UHOME
  mkdir -p $UHOME
  mkdir -p $UHOME/dev/
  mknod -m 666 $UHOME/dev/null c 1 3
  mknod -m 666 $UHOME/dev/tty c 5 0
  mknod -m 666 $UHOME/dev/zero c 1 5
  mknod -m 666 $UHOME/dev/random c 1 8
  mknod -m 644 $UHOME/dev/urandom c 1 9
  chown root:root $UHOME
  chmod 0755 $UHOME
  mkdir -p $UHOME/bin
  mkdir -p $UHOME/etc
  mkdir -p $UHOME/lib
  mkdir -p $UHOME/usr
  cd $UHOME/usr
  ln -s ../bin bin
  cd - > /dev/null
  cd $UHOME
  ln -s lib lib64
  cd - > /dev/null
  mkdir $UHOME/lib/${ARCH}-linux-gnu
  cp /lib/${ARCH}-linux-gnu/libnss* $UHOME/lib/${ARCH}-linux-gnu
  cat <<EOT>$UHOME/etc/nsswitch.conf
passwd: files
group:  files
EOT
  chmod 0444 $UHOME/etc/nsswitch.conf
  echo "127.0.0.1 localhost" > $UHOME/etc/hosts
  chmod 0444 $UHOME/etc/hosts
  if [ -d /etc/terminfo/ ]; then
    cp -R /etc/terminfo $UHOME/etc
  fi
  if [ -d /lib/terminfo/ ]; then
    cp -R /lib/terminfo $UHOME/lib
  fi

  # Add restricted bash and ssh/scp executables into the chroot. There is no
  # need for any other executable.
  add_executable /bin/bash rbash
  add_executable /usr/bin/ssh
  add_executable /usr/bin/scp
  add_executable /bin/date
  add_executable /bin/ls
  add_executable /bin/rm
  add_executable /bin/mv
  add_executable /bin/cp

  grep $U /etc/passwd > $UHOME/etc/passwd
  grep $U /etc/group > $UHOME/etc/group

  mkdir -p $UHOME/.ssh
  chmod 700 $UHOME/.ssh
  chown -R $U:$U $UHOME/.ssh

  # When using SSH to get out of the jail onto localhost machine, we don't want
  # to be constantly told about fingerprints and permanently added hosts
  mkdir -p $UHOME/home/$U/.ssh
  chmod 0700 $UHOME/home/$U/.ssh
  chown -R $U:$U $UHOME/home/$U

fi

#DEBHELPER#

exit 0

# vim: set ts=2 sw=2 tw=0 et :

不在预期位置 ...好吧,更像是:uname输出中的体系结构类型与您想要的目录名称不匹配构造...

但是您可以通过不同的方式找到该目录,因为您使用的是基于 apt 的发行版。

dpkg -L libnss3 | awk '/libnss3.so/{gsub(/\/libnss3.so/,"",[=14=]);print}'

这对我在 Ubuntu 20.04Raspbian GNU/Linux 10 (buster)

上都有效

Raspbian:

$ dpkg -L libnss3  | awk '/libnss3.so/{gsub(/\/libnss3.so/,"",[=10=]);print}'
/usr/lib/arm-linux-gnueabihf

Ubuntu:

$ dpkg -L libnss3  | awk '/libnss3.so/{gsub(/\/libnss3.so/,"",[=11=]);print}'
/usr/lib/x86_64-linux-gnu