#!/bin/sh # if [ "$1" = "prereqs" ]; then exit 0 fi quiet=n . /scripts/functions # if break=sqmount STOP here maybe_break rootfs . /conf/tcos.conf . /conf/tcos-run-functions ############################################## TCOS_ENABLE_USENFS=$(read_cmdline_var "usenfs" "${TCOS_USENFS}") if [ "$TCOS_ENABLE_USENFS" != "1" ]; then _log "ROOTFS no NFS support, exiting" exit 0 fi rootfs_file=/mnt/tmp/rootfs-$(uname -r).squashfs mkdir -p /mnt/tmp /target if [ "${TCOS_USENFS}" = "nfs" ]; then value=0 log_begin_msg "Mounting NFS /mnt/tmp" MOPTS="nolock,ro" mount -n -t ramfs none /target nfsmount -o ${MOPTS} $(read_server "nfs-server"):${nfs_dir} /mnt/tmp 2>&1 > /dev/null ||\ nfsmount -o ${MOPTS} $(read_server "nfs-server"):${nfs_dir} /mnt/tmp 2>&1 > /dev/null ||\ value=1 log_end_msg $value fi ############################################## TCOS_ENABLE_ROOTFS=$(read_cmdline_var "rootfs" "${TCOS_ROOTFS}") if [ "$TCOS_ENABLE_ROOTFS" != "1" ]; then _log "ROOTFS no rootfs support, exiting" exit 0 fi if [ ! -f ${rootfs_file} ]; then _log "ROOTFS is __NOT__ in /mnt/tmp" log_begin_msg "Downloading rootfs" download_file /tcos/rootfs-$(uname -r).squashfs ${rootfs_file} log_end_msg $? else _log "ROOTFS is in /mnt/tmp" log_begin_msg "Using NFS rootfs" sync log_end_msg $? fi update_progress # Mount squashfs filesystems _log "ROOTFS mounting rootfs in /target" log_begin_msg "Mounting rootfs filesystem" mount -r -o loop -t squashfs ${rootfs_file} /target >> /tmp/initramfs.debug 2>&1 log_end_msg $? echo 36 > /tmp/progress update_progress _log "ROOTFS remounting /target as RW" log_begin_msg "Remounting /target in rw mode" mkdir -p /.target mount_unionfs /mnt/rootram /.target /target log_end_msg $? update_progress _log "ROOTFS copy some things on /target" # copy some things rm -rf /target/conf/ && cp -ra /conf/ /target/ rm -rf /target/scripts/ && cp -ra /scripts/ /target/ mkdir -p /target/tmp && cp -ra /tmp/* /target/tmp mkdir -p /var/lib/dhcp/ cp /var/lib/dhcp/dhclient.leases /target/var/lib/dhcp/dhclient.leases cp /etc/hostname /target/etc/hostname cp /etc/resolv.conf /target/etc/resolv.conf cp /etc/fstab /target/etc/fstab cp /etc/mtab /target/etc/mtab _log "ROOTFS creating init_rootfs script" # make a /sbin/init_rootfs cat << EOF >> /target/init2 #!/bin/sh echo "Loading second stage, please wait..." . /conf/initramfs.conf . /scripts/functions run_scripts /scripts/tcos-bottom EOF chmod 755 /target/init2 _log "ROOTFS pivot_root /target" cd /target pivot_root . ../ _log "ROOTFS mounting /dev /proc and /sys into /target" # mount -o bind some things log_begin_msg "Moving /dev /proc and /sys" mkdir -p /target/dev /target/proc /target/sys /target/mnt/tmp mount -n -o move /dev /target/dev mount -n -o move /sys /target/sys mount -n -o move /mnt/tmp /target/mnt/tmp mount -n -o move /proc /target/proc log_end_msg $? # enter to jail exec chroot . /scripts/init2 dev/console 2>&1 _log "ROOTFS run-init /script" #exec run-init /target/ /scripts/init2 "$@" /target/dev/console #update progress exit 0