mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-10-15 19:35:04 +00:00
Adds a logging daemon that collects logs in a ring buffer in a runc container. The tools logwrite and logread can be used to read/write logs. The logging daemon can be sent open file descriptors that will be read and included in the logs. Modifies init to start the daemon and use logwrite to capture logs from runc. Signed-off-by: Magnus Skjegstad <magnus@skjegstad.com>
115 lines
3.7 KiB
Bash
Executable File
115 lines
3.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# mount filesystems
|
|
mkdir -p -m 0755 /proc /run /tmp /sys /dev
|
|
|
|
mount -n -t proc proc /proc -o ndodev,nosuid,noexec,relatime
|
|
|
|
mount -n -t tmpfs tmpfs /run -o nodev,nosuid,noexec,relatime,size=10%,mode=755
|
|
mount -n -t tmpfs tmpfs /tmp -o nodev,nosuid,noexec,relatime,size=10%,mode=1777
|
|
|
|
# mount devfs
|
|
mount -n -t devtmpfs dev /dev -o nosuid,noexec,relatime,size=10m,nr_inodes=248418,mode=755
|
|
# devices
|
|
[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
|
|
[ -c /dev/tty1 ] || mknod -m 620 /dev/tty1 c 4 1
|
|
[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
|
|
|
|
[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
|
|
[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
|
|
|
|
# extra symbolic links not provided by default
|
|
[ -e /dev/fd ] || ln -snf /proc/self/fd /dev/fd
|
|
[ -e /dev/stdin ] || ln -snf /proc/self/fd/0 /dev/stdin
|
|
[ -e /dev/stdout ] || ln -snf /proc/self/fd/1 /dev/stdout
|
|
[ -e /dev/stderr ] || ln -snf /proc/self/fd/2 /dev/stderr
|
|
[ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
|
|
|
|
# devfs filesystems
|
|
mkdir -p -m 1777 /dev/mqueue
|
|
mkdir -p -m 1777 /dev/shm
|
|
mkdir -p -m 0755 /dev/pts
|
|
mount -n -t mqueue -o noexec,nosuid,nodev mqueue /dev/mqueue
|
|
mount -n -t tmpfs -o noexec,nosuid,nodev,mode=1777 shm /dev/shm
|
|
mount -n -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts
|
|
|
|
# mount sysfs
|
|
sysfs_opts=nodev,noexec,nosuid
|
|
mount -n -t sysfs -o ${sysfs_opts} sysfs /sys
|
|
[ -d /sys/kernel/security ] && mount -n -t securityfs -o ${sysfs_opts} securityfs /sys/kernel/security
|
|
[ -d /sys/kernel/debug ] && mount -n -t debugfs -o ${sysfs_opts} debugfs /sys/kernel/debug
|
|
[ -d /sys/kernel/config ] && mount -n -t configfs -o ${sysfs_opts} configfs /sys/kernel/config
|
|
[ -d /sys/fs/fuse/connections ] && mount -n -t fusectl -o ${sysfs_opts} fusectl /sys/fs/fuse/connections
|
|
[ -d /sys/fs/selinux ] && mount -n -t selinuxfs -o nosuid,noexec selinuxfs /sys/fs/selinux
|
|
[ -d /sys/fs/pstore ] && mount -n -t pstore pstore -o ${sysfs_opts} /sys/fs/pstore
|
|
[ -d /sys/firmware/efi/efivars ] && mount -n -t efivarfs -o ro,${sysfs_opts} efivarfs /sys/firmware/efi/efivars
|
|
|
|
# misc /proc mounted fs
|
|
[ -d /proc/sys/fs/binfmt_misc ] && mount -t binfmt_misc -o nodev,noexec,nosuid binfmt_misc /proc/sys/fs/binfmt_misc
|
|
|
|
# mount cgroups
|
|
mount -n -t tmpfs -o nodev,noexec,nosuid,mode=755,size=10m cgroup_root /sys/fs/cgroup
|
|
|
|
while read name hier groups enabled rest
|
|
do
|
|
case "${enabled}" in
|
|
1) mkdir -p /sys/fs/cgroup/${name}
|
|
mount -n -t cgroup -o ${sysfs_opts},${name} ${name} /sys/fs/cgroup/${name}
|
|
;;
|
|
esac
|
|
done < /proc/cgroups
|
|
|
|
# use hierarchy for memory
|
|
echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
|
|
|
|
# for compatibility
|
|
mkdir -p /sys/fs/cgroup/systemd
|
|
mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
|
|
|
|
# start mdev for hotplug
|
|
echo "/sbin/mdev" > /proc/sys/kernel/hotplug
|
|
|
|
# mdev -s will not create /dev/usb[1-9] devices with recent kernels
|
|
# so we trigger hotplug events for usb for now
|
|
for i in $(find /sys/devices -name 'usb[0-9]*'); do
|
|
[ -e $i/uevent ] && echo add > $i/uevent
|
|
done
|
|
|
|
mdev -s
|
|
|
|
# set hostname
|
|
if [ -s /etc/hostname ]
|
|
then
|
|
hostname -F /etc/hostname
|
|
fi
|
|
|
|
if [ $(hostname) = "moby" -a -f /sys/class/net/eth0/address ]
|
|
then
|
|
mac=$(cat /sys/class/net/eth0/address)
|
|
hostname moby-$(echo $mac | sed 's/://g')
|
|
fi
|
|
|
|
# set system clock from hwclock
|
|
hwclock --hctosys --utc
|
|
|
|
# bring up loopback interface
|
|
ip addr add 127.0.0.1/8 dev lo brd + scope host
|
|
ip route add 127.0.0.0/8 dev lo scope host
|
|
ip link set lo up
|
|
|
|
# for containerising dhcpcd and other containers that need writable etc
|
|
mkdir /tmp/etc
|
|
mv /etc/resolv.conf /tmp/etc/resolv.conf
|
|
ln -snf /tmp/etc/resolv.conf /etc/resolv.conf
|
|
|
|
# remount rootfs as readonly
|
|
mount -o remount,ro /
|
|
|
|
# make /var writeable and shared
|
|
mount -o bind /var /var
|
|
mount -o remount,rw,nodev,nosuid,noexec,relatime /var /var
|
|
mount --make-rshared /var
|
|
|
|
# make / rshared
|
|
mount --make-rshared /
|