#! /bin/busybox sh
export PATH=/bin

# Set up standard mounts
mount -t proc -o noatime proc /proc
mount -t sysfs -o noatime sysfs /sys
mount -t devtmpfs dev /dev
chmod 666 /dev/null
chmod 666 /dev/zero
chmod 666 /dev/full
ln -s ../proc/self/fd /dev/fd
ln -s ../run/shm /dev/shm 
mkdir /dev/pts
mount -t devpts -o gid=5,mode=620,ptmxmode=000 devpts /dev/pts

# Enable magic SysRq Key
echo 1 >/proc/sys/kernel/sysrq
# Enable mdev firmware loading (mdev -s happens in svc/lazy-startup)
# This is now handled by a hotplug script which logs the request then calls mdev
#echo /bin/mdev >/proc/sys/kernel/hotplug

# Make a copy of /run in tmpfs
mount -t tmpfs -o noatime,size=10M run /tmp
cp -ar /run/* /tmp/
mount --move /tmp /run

# Create overlays to alow writing to various dirs
mkdir /run/.etc
mount -t overlayfs -o rw,noatime,upperdir=/run/.etc,lowerdir=/etc overlayfs /etc
mkdir /run/.var
mount -t overlayfs -o rw,noatime,upperdir=/run/.var,lowerdir=/var overlayfs /var
mkdir /run/.root
mount -t overlayfs -o rw,noatime,upperdir=/run/.root,lowerdir=/root overlayfs /root

# Limit size of /tmp
mount -t tmpfs -o noatime,nosuid,size=100M tmp /tmp

ifconfig lo 127.0.0.0
route add -net 127.0.0.0/8 lo
echo 0 >/proc/sys/kernel/ctrl-alt-del

mount -t nilfs2 /dev/sda4 /persistent

export PATH=/bin
export USER=root
export HOME=/root
exec /bin/daemonproxy -c /etc/svc/init.conf
