<div dir="ltr"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">I am trying to run my LFS (Linux from scratch) inside a container. I created LFS from its stable version book and using that as a <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">rootfs</code> for my container.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">I created the <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">LFS</code> rootfs at <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">/home/manik/toolchain/lfs</code> . I am using this as a <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">rootfs</code> source for my container. I will copy the directories inside my container <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">rootfs</code> from this location.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">Below is the template that I created from <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">busybox</code> template of <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">lxc</code> package.I named this tempalate as <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">lxc-lfs</code> and copied into the directory <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">/usr/share/lxc/templates</code></p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;word-wrap:normal;color:rgb(17,17,17);background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:inherit">#!/bin/bash
LXC_MAPPED_UID=
LXC_MAPPED_GID=
# Make sure the usual locations are in PATH
export PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
am_in_userns() {
[ -e /proc/self/uid_map ] || { echo no; return; }
[ "$(wc -l /proc/self/uid_map | awk '{ print $1 }')" -eq 1 ] || { echo yes; return; }
line=$(awk '{ print $1 " " $2 " " $3 }' /proc/self/uid_map)
[ "$line" = "0 0 4294967295" ] && { echo no; return; }
echo yes
}
configure_lfs() {
rootfs=$1
name=$2
lfsroot=$3
res=0
tree=( \
bin \
boot \
dev \
etc \
home \
lib \
media \
mnt \
opt \
proc \
root \
run \
sbin \
srv \
sys \
tmp \
usr \
var )
for d in ${tree[@]}
do
mkdir -p $rootfs/$d
cp -r --preserve $lfsroot/$d/. $rootfs/$d
done
pushd $rootfs/dev > /dev/null || return 1
mknod -m 666 tty c 5 0 || res=1
mknod -m 666 console c 5 1 || res=1
mknod -m 666 tty0 c 4 0 || res=1
mknod -m 666 tty1 c 4 0 || res=1
mknod -m 666 tty5 c 4 0 || res=1
mknod -m 600 ram0 b 1 0 || res=1
mknod -m 666 null c 1 3 || res=1
mknod -m 666 zero c 1 5 || res=1
mknod -m 666 urandom c 1 9 || res=1
mkdir pts || res=1
popd > /dev/null
cat <<EOF >> $rootfs/etc/init.d/rcS
#!/bin/sh
/bin/syslogd
/bin/mount -a
EOF
# executable
chmod 744 $rootfs/etc/init.d/rcS || res=1
# launch rcS first then make a console available
# and propose a shell on the tty, the last one is
# not needed
cat <<EOF >> $rootfs/etc/inittab
::sysinit:/etc/init.d/rcS
tty1::respawn:/sbin/agetty -L tty1 115200 vt100
console::askfirst:/bin/sh
EOF
# writable and readable for other
chmod 644 $rootfs/etc/inittab || res=1
# /etc/fstab must exist for "mount -a"
touch $rootfs/etc/fstab || res=1
return $res
}
copy_configuration() {
path=$1
rootfs=$2
name=$3
grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.haltsignal = SIGUSR1
lxc.rebootsignal = SIGTERM
lxc.utsname = $name
lxc.tty = 1
lxc.pts = 1
lxc.cap.drop = sys_module mac_admin mac_override sys_time
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
lxc.mount.auto = cgroup:mixed proc:mixed sys:mixed
lxc.mount.entry = shm /dev/shm tmpfs defaults 0 0
EOF
echo "lxc.mount.entry = /sys/kernel/security sys/kernel/security none ro,bind,optional 0 0" >>$path/config
return 0
}
in_userns=0
[ $(am_in_userns) = "yes" ] && in_userns=1
usage()
{
cat <<EOF
$1 -h|--help -p|--path=<path> -n|--name=<name> --lfsroot=<lfsroot>[Mandatory option]
EOF
return 0
}
options=$(getopt -o hp:n: -l help,rootfs:,path:,name:,lfsroot: -- "$@")
if [ $? -ne 0 ]; then
usage $(basename $0)
exit 1
fi
eval set -- "$options"
while true
do
case "$1" in
-h|--help) usage $0 && exit 0;;
-p|--path) path=$2; shift 2;;
--rootfs) rootfs=$2; shift 2;;
--lfsroot) lfsroot=$2; shift 2;;
-n|--name) name=$2; shift 2;;
--) shift 1; break ;;
*) break ;;
esac
done
if [ -z "$lfsroot" ]; then
echo "--lfsroot argument is required."
exit 1
fi
if [ "$(id -u)" != "0" ]; then
echo "This script should be run as 'root'"
exit 1
fi
if [ -z "$path" ]; then
echo "'path' parameter is required"
exit 1
fi
# detect rootfs
config="$path/config"
rootfs="$path/rootfs"
configure_lfs $rootfs $name $lfsroot
if [ $? -ne 0 ]; then
echo "failed to configure LFS's rootfs"
exit 1
fi
copy_configuration $path $rootfs $name
if [ $? -ne 0 ]; then
echo "failed to write lfs-lxc configuration file"
exit 1
fi
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">I used the below command to create my container:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;word-wrap:normal;color:rgb(17,17,17);background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:inherit">sudo lxc-create -t lfs -n lfs-lxc-container --lxcpath=/home/manik/toolchain
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">I can successfully use the following command:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;word-wrap:normal;color:rgb(17,17,17);background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:inherit">sudo lxc-attach -n lfs-lxc-container --lxcpath=/home/manik/toolchain
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">I get root bash prompt which is understandable as the man pages for <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">lxc-attach</code> says to run the shell of the user if no specific command is given.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">However, <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">lxc-console</code> command hangs. I am triggering the command like:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;word-wrap:normal;color:rgb(17,17,17);background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:inherit">sudo lxc-console -n lfs-lxc-container --lxcpath=/home/manik/toolchain
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">Using the above <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">lxc-attach</code> since I get the bash prompt, I executed the command:</p><pre style="margin-top:0px;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;word-wrap:normal;color:rgb(17,17,17);background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:inherit">bash-4.3# ps -efa
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 22:37 ? 00:00:00 init boot
root 29 0 0 23:27 ? 00:00:00 /bin/bash
root 30 29 0 23:27 ? 00:00:00 ps -efa
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">Looks like <code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:consolas,menlo,monaco,'lucida console','liberation mono','dejavu sans mono','bitstream vera sans mono','courier new',monospace,sans-serif;white-space:pre-wrap;background-color:rgb(239,240,241)">getty</code> is not working/running.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(17,17,17);font-family:ubuntu,arial,'libra sans',sans-serif;line-height:19.5px">Anyone got any idea ? I am not an expert in terminals or its services, so if you know what is wrong please help.</p></div>