Comment 0 for bug 1978862

Revision history for this message
Steven Anderson (wanfuse123) wrote : deboostrap of debian guest shows recursive symlnks according to lsof ouput which interfears with unmounting chroot

This paste expires on 2022-06-22 17:43:10.762812. Remove now. Repaste, or download this paste. Toggle word wrap. Pasted through web.

NOTE: the temporary exit of this script at the line:

' echo "temporary exit to make sure nothing else is screwing it up" && exit '

produces this error:

command: sudo lsof -x +D /root/uml-834523023462431000

lsof: WARNING: can't stat(/root/uml-834523023462431000/root_fs/var/run/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.speech-dispatcher/.speech-dispatcher/.speech-dispatcher/.cache/speech-dispatcher/.speech-dispatcher/.cache/speech-dispatcher/.speech-dispatcher/.cache/speech-dispatcher) symbolc link: Too many levels of symbolic links
lsof: WARNING: can't stat(/root/uml-834523023462431000/root_fs/var/run/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.cache/speech-dispatcher/.speech-dispatcher/.speech-dispatcher/.speech-dispatcher/.cache/speech-dispatcher/.speech-dispatcher/.speech-dispatcher/.cache/speech-dispatcher/log) symbolc link: Too many levels of symbolic links

#!/bin/bash -x

function aptUpdate_Inner {
DEBIAN_FRONTEND=noninteractive \
  apt-get update \
  -o Dpkg::Options::=--force-confold \
  -y --allow-downgrades --allow-remove-essential --allow-change-held-packages
}

aptUpdate_Inner

# https://askubuntu.com/questions/401454/how-to-get-sudo-access-to-shares-mounted-by-gigolo

logfile=dies_Inner-11.log
[ -e ~/"$logfile" ] || rm -rf "$logfile"

exec > >(tee -a "$logfile") 2> >(tee -a "$logfile" >&2)

basedir=uml-834523023462431000

thePrefix=~/"$basedir"/root_fs_img

function finish_Inner_Func {
  pushd ~
  lsof ~/"$basedir"/root_fs_img
  echo ~/"$basedir"/root_fs
  lsof ~/"$basedir"/root_fs
  lsof ~/"$basedir"/buster_uml
  read -r "Press any key to resume ..."
  read -r "Press any key to resume ..."
  read -r "Press any key to resume ..."
  echo "Trying to clean up Chroots that are left hanging..."
  umount ~/"$basedir"/root_fs_img/sys || echo "can't unmount sys"
  umount ~/"$basedir"/proc/sys/fs/binfmt_misc
  umount ~/"$basedir"/root_fs_img/proc || echo "can't unmount proc"
  umount ~/"$basedir"/root_fs_img/dev/pts || echo "can't unmount dev pts"
  umount ~/"$basedir"/root_fs_img/dev || echo "can't unmount dev"
  umount --recursive /root/"$basedir"/root_fs_img
  umount --recursive /root/"$basedir"/root_fs
  umount --recursive /root/"$basedir"
  umount ~/"$basedir"/root_fs_img || echo "can't unmountroot_fs_img" || exit
  pushd ~ || exit
  umount ~/"$basedir"/root_fs
  echo ~/"basedir"/root_fs_img
  lsof ~/"$basedir"/root_fs_img
  echo ~/"$basedir"/root_fs
  lsof ~/"$basedir"/root_fs
}

#trap finish_Inner_Func EXIT

function old_kill_proc {

thePrefix=~/"$basedir"
whatsFound=0
for root_file_Systems in /proc/*/root; do
    theLinks=$(readlink "$root_file_Systems")
    if [ "$theLinks" != "x" ]; then
        if [ "${theLinks:0:${#the_Prefix}}" = "$thePrefix" ]; then
            # this process is in the chroot...
            thePID="$(basename "$(dirname "$root_file_Systems")")"
            kill -9 "$thePID"
            whatsFound=1
        fi
    fi
done

if [ "$whatsFound" = "x1" ]; then

while grep -q "$thePrefix" /proc/mounts; do
    counters=$counters+1
    if [ "$counters" -ge 20 ]; then
        echo "failed to umount $thePrefix"
        if [ -x /usr/bin/lsof ]; then
            /usr/bin/lsof "$thePrefix"
        fi
    fi
    grep "$thePrefix" /proc/mounts | \
        cut -d\ -f2 | LANG=C sort -r | xargs -r -n 1 umount || sleep 1
done # repeat the above, the script I'm cargo-culting this from just re-execs itself
fi

}

# -o Dpkg::Options::=--force-confdef \

function chroot_Function {
success_chroot=0
echo "made it to build root?"
mount --rbind /dev ~/"$basedir"/root_fs/dev && echo "mounted dev" && success_chroot=1
mount devpts -t devpts --rbind /dev/pts ~/"$basedir"/root_fs/dev/pts && echo "mounted pts" && success_chroot=1
mount --rbind /proc -t proc ~/"$basedir"/root_fs/proc && echo "mounted proc" && success_chroot=1
mount --rbind /sys ~/"$basedir"/root_fs/sys && echo "mounted sys" && success_chroot=1

if ((! success_chroot==4)); then
 printf 'setting up bindings for the chrooot was unsuccessful\n' 1>&2
 exit 1
fi

}

if [[ -d ~/"$basedir" ]]
then
    printf '%s exists on your filesystem ... removing:\n ' "$basedir" && finish_Inner_Func && mkdir ~/"$basedir"
else
    printf 'basedir: does not exist so I will create root %s\n ' "$basedir" && mkdir ~/"$basedir"

fi

#chown -R "$USER:$USER" buster-uml
#chmod a+rwx buster-uml

fallocate -l 2G ~/"$basedir"/root_fs_img

mkfs -t ext4 ~/"$basedir"/root_fs_img

mkdir ~/"$basedir"/root_fs
mount -t ext4 ~/"$basedir"/root_fs_img ~/"$basedir"/root_fs
mount -o remount, rw ~/"$basedir"/root_fs

pushd ~/"$basedir" || printf 'failed to change the directory: /root/ %s \n' ~/"$basedir"
/usr/sbin/debootstrap --arch amd64 --variant minbase buster ~/"$basedir"/root_fs/ http://deb.debian.org/debian

echo "temporary exit to make sure nothing else is screwing it up" && exit
#rsync --verbose --archive --one-file-system --xattrs --hard-links --numeric-ids --sparse --acls buster-uml/ root_fs/

echo '/dev/ubd0 ext4 discard,errors=remount-ro 0 ' >> ~/"$basedir"/root_fs/etc/fstab

#if ! chroot ~/"$basedir"/root_fs_img /usr/bin/passwd; then
# printf 'failed to successfully execute the chroot\n' 1>&2
# exit 1
#fi

#if ! source /etc/environment; then
# printf 'failed to source environment\n' 1>&2
# exit 1
#fi

chroot_Function

if ! DEBIAN_FRONTEND=noninteractive apt update -y; then
        printf 'unable to install apt updates' 1>&2
        exit 1
fi

if ! DEBIAN_FRONTEND=noninteractive apt install ifupdown -y -q; then
        printf 'unable to install networking properly\n' 1>&2
 exit 1
fi

random_file="UML-$(shuf -i 2000000-7000000 -n 1))"
random_hostname="$random_file"

if ! echo "$random_hostname" > ~/"$basedir"/root_fs/etc/hostname; then
 printf 'failed to install random hostname\n' 1>&2
 exit 1
fi

~/"$basedir"/root_fs/etc/network/interfaces <<'interfaces_EOF'

# legacy UML network devices
auto eth0
iface eth0 inet dhcp

# vector UML network devices
auto vec0
iface vec0 inet dhcp
interfaces_EOF

if ! mkdir -p ~/"$basedir"/root_fs/usr/lib/modules/; then
 printf 'failed to create lib modules directory\n' 1>&2
 exit 1
fi

#if ! rsync -raHAXS /lib/modules/ ~/"$basedir"/root_fs/usr/lib/modules/; then
# printf 'rsync was not succesful files not propelry copied to the image file\n' 1>&2
# exit 1
#fi

echo 'End of SCRIPT_Inner...'

finish_Inner_Func

produces this lsof output :
Filename: None. Size: 8kb. View raw, copy, hex, or download this file.
View source code, the removal or expiry stories, or read the about page.

This website does not claim ownership of, copyright on, and assumes no liability for provided content. Toggle color scheme.