diff options
Diffstat (limited to 'initramfs-tools/scripts/live-bottom')
| -rwxr-xr-x | initramfs-tools/scripts/live-bottom/08persistence_excludes | 77 | ||||
| -rwxr-xr-x | initramfs-tools/scripts/live-bottom/10validateroot | 29 | ||||
| -rwxr-xr-x | initramfs-tools/scripts/live-bottom/12fstab | 89 | ||||
| -rwxr-xr-x | initramfs-tools/scripts/live-bottom/23networking | 157 |
4 files changed, 352 insertions, 0 deletions
diff --git a/initramfs-tools/scripts/live-bottom/08persistence_excludes b/initramfs-tools/scripts/live-bottom/08persistence_excludes new file mode 100755 index 0000000..633f6ac --- /dev/null +++ b/initramfs-tools/scripts/live-bottom/08persistence_excludes @@ -0,0 +1,77 @@ +#!/bin/sh + +# Persistence enhancer script +# This script saves precious time on slow persistence devices/image files +# and writes on flash based device. +# a tmpfs on $PERSTMP is mounted and directories listed in +# /etc/live-persistence.binds will be copied there and then bind mounted back. + +#set -e + +# initramfs-tools header + +PREREQ="" + +prereqs() +{ + echo "${PREREQ}" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +# live-boot header + +if [ -z "${PERSISTENCE}" ] || [ -n "${NOPERSISTENCE}" ] || [ -z "${PERSISTENCE_IS_ON}" ] || [ ! -f /root/etc/live-persistence.binds ] +then + exit 0 +fi + +. /scripts/live-functions + +# live-boot script + +dirs="$(sed -e '/^ *$/d' -e '/^#.*$/d' /root/etc/live-persistence.binds | tr '\n' '\0')" +if [ -z "${dirs}" ] +then + exit 0 +fi + +log_begin_msg "Moving persistence bind mounts" + +PERSTMP="/root/live/persistence-binds" +CPIO="/bin/cpio" + +if [ ! -d "${PERSTMP}" ] +then + mkdir -p "${PERSTMP}" +fi + +mount -t tmpfs tmpfs "${PERSTMP}" + +for dir in $(echo "${dirs}" | tr '\0' '\n') +do + if [ ! -e "/root/${dir}" ] && [ ! -L "/root/${dir}" ] + then + # directory do not exists, create it + mkdir -p "/root/${dir}" + elif [ ! -d "/root/${dir}" ] + then + # it is not a directory, skip it + break + fi + + # Copy previous content if any + cd "/root/${dir}" + find . -print0 | ${CPIO} -pumd0 "${PERSTMP}/${dir}" + cd "${OLDPWD}" + + # Bind mount it to origin + mount -o bind "${PERSTMP}/${dir}" "/root/${dir}" +done + +log_end_msg diff --git a/initramfs-tools/scripts/live-bottom/10validateroot b/initramfs-tools/scripts/live-bottom/10validateroot new file mode 100755 index 0000000..d4d1620 --- /dev/null +++ b/initramfs-tools/scripts/live-bottom/10validateroot @@ -0,0 +1,29 @@ +#!/bin/sh + +# Error out in case a "wrong" file system was chosen. + +#set -e + +# initramfs-tools header + +PREREQ="" + +prereqs() +{ + echo "${PREREQ}" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +. /scripts/live-functions +. /scripts/live-helpers + +if ! [ -d "/root/usr/share/live-boot" ] +then + panic "A wrong rootfs was mounted." +fi diff --git a/initramfs-tools/scripts/live-bottom/12fstab b/initramfs-tools/scripts/live-bottom/12fstab new file mode 100755 index 0000000..7f43937 --- /dev/null +++ b/initramfs-tools/scripts/live-bottom/12fstab @@ -0,0 +1,89 @@ +#!/bin/sh + +#set -e + +# initramfs-tools header + +PREREQ="" +FSTAB=/root/etc/fstab + +prereqs() +{ + echo "${PREREQ}" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +# live-boot header + +. /scripts/live-functions + +if [ -n "${NOFSTAB}" ] +then + exit 0 +fi + +log_begin_msg "Configuring fstab" + +# live-boot script + +if ! grep -qs "^${UNIONTYPE}" "${FSTAB}" +then + echo "${UNIONTYPE} / ${UNIONTYPE} rw 0 0" >> "${FSTAB}" +fi + +if ! grep -qs "^tmpfs /tmp" "${FSTAB}" +then + echo "tmpfs /tmp tmpfs nosuid,nodev 0 0" >> "${FSTAB}" +fi + +if [ -n "${SWAPON}" ] +then + devices="" + + for device in /dev/[hs]d[a-z][0-9]* + do + if ! [ -b "${device}" ] + then + continue + fi + + /sbin/blkid -o udev -p ${device%%[0-9]*} | grep -q "^ID_FS_USAGE=raid" && continue + + magic=$(/bin/dd if="${device}" bs=4086 skip=1 count=1 2>/dev/null | /bin/dd bs=10 count=1 2>/dev/null) || continue + + if [ "${magic}" = "SWAPSPACE2" -o "${magic}" = "SWAP-SPACE" ] + then + #log "Found ${device}" + devices="${devices} ${device}" + fi + done + + # Remove all auto swap entries + if grep -qs "swap swap" "${FSTAB}" + then + grep -v "swap swap" "${FSTAB}" > "${FSTAB}".tmp + mv "${FSTAB}".tmp "${FSTAB}" + fi + + # Add new swap entries + for device in ${devices} + do + echo "${device} swap swap defaults 0 0" >> "${FSTAB}" + done +fi + +# disabled for now +#rm -f /root/etc/rcS.d/S*checkroot.sh + +if [ "${NOFASTBOOT}" != "Yes" ] +then + touch root/fastboot +fi + +log_end_msg diff --git a/initramfs-tools/scripts/live-bottom/23networking b/initramfs-tools/scripts/live-bottom/23networking new file mode 100755 index 0000000..86d4562 --- /dev/null +++ b/initramfs-tools/scripts/live-bottom/23networking @@ -0,0 +1,157 @@ +#!/bin/sh + +#set -e + +# initramfs-tools header + +PREREQ="" + +prereqs() +{ + echo "${PREREQ}" +} + +case "${1}" in + prereqs) + prereqs + exit 0 + ;; +esac + +# live-boot header + +if [ -n "${NONETWORKING}" ] +then + exit 0 +fi + +. /scripts/live-functions + +log_begin_msg "Preconfiguring networking" + +# live-boot script + +IFFILE="/root/etc/network/interfaces" + +if [ "${STATICIP}" = "frommedia" -a -e "${IFFILE}" ] +then + # will use existent /etc/network/interfaces + log_end_msg + exit 0 +fi + +cat > "${IFFILE}" << EOF +auto lo +iface lo inet loopback + +EOF + +udevadm trigger +udevadm settle + +if [ -z "${NETBOOT}" -a -n "${STATICIP}" -a "${STATICIP}" != "frommedia" ] +then + parsed=$(echo "${STATICIP}" | sed -e 's/,/ /g') + + for ifline in ${parsed} + do + ifname="$(echo ${ifline} | cut -f1 -d ':')" + ifaddress="$(echo ${ifline} | cut -f2 -d ':')" + ifnetmask="$(echo ${ifline} | cut -f3 -d ':')" + ifgateway="$(echo ${ifline} | cut -f4 -d ':')" + +cat >> "${IFFILE}" << EOF +allow-hotplug ${ifname} +iface ${ifname} inet static + address ${ifaddress} + netmask ${ifnetmask} +EOF + +if [ -n "${ifgateway}" ] +then + +cat >> "${IFFILE}" << EOF + gateway ${ifgateway} + +EOF + +fi + + done +else + if [ -z "${NETBOOT}" ] || [ -n "${DHCP}" ] + then + # default, dhcp assigned + method="dhcp" + else + # make sure that the preconfigured interface would not get reassigned by dhcp + # on startup by ifup script - otherwise our root fs might be disconnected! + method="manual" + fi + + # iterate the physical interfaces and add them to the interfaces list and also add when ethdevice= called on cmdline + if [ "${method}" != dhcp ] || ([ ! -x /root/usr/sbin/NetworkManager ] && [ ! -x /root/usr/sbin/wicd ]) || [ ! -z "${ETHDEVICE}" ] + then + for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan* + do + [ -e ${interface} ] || continue + i="$(basename ${interface})" + +cat >> "${IFFILE}" << EOF +allow-hotplug ${i} +iface ${i} inet ${method} + +EOF + + done + fi + + if [ ! -f /root/etc/resolv.conf ] || [ -z "$(cat /root/etc/resolv.conf)" ] + then + if [ -f /netboot.config ] + then + # create a resolv.conf if it is not present or empty + cp /netboot.config /root/var/log/netboot.config + + rc_search=$(cat netboot.config | awk '/domain/{print $3}') + rc_server0=$(cat netboot.config | awk '/dns0/{print $5}') + rc_server1=$(cat netboot.config | awk '/dns0/{print $8}') + rc_server0="nameserver ${rc_server0}" + + if [ "${rc_server1}" = "0.0.0.0" ] + then + rc_server1="" + else + rc_server1="nameserver ${rc_server1}" + fi + +cat > /root/etc/resolv.conf << EOF +# /etc/resolv.conf +# Autogenerated by live-boot +search ${rc_search} +domain ${rc_search} +${rc_server0} +${rc_server1} +EOF + + cat /root/etc/resolv.conf >> /root/var/log/netboot.config + fi + fi +fi + +#if [ ! -x /root/usr/sbin/NetworkManager ] +#then +# for i in eth0 eth1 eth2 ath0 wlan0 +# do +# grep -q "iface ${i}" ${IFFILE} && continue +# +#cat >> "${IFFILE}" << EOF +#allow-hotplug ${i} +#iface ${i} inet dhcp +# +#EOF +# +# done +#fi + +log_end_msg |
