# NFS
if [ "$WITH_NET" = "1" ]; then
- MODULES="$MODULES nfs"
+ MODULES="$MODULES af_packet"
for module in /lib/modules/$KERNEL/kernel/drivers/net/{,*/}*; do
MODULES="$MODULES $(basename ${module/.ko})"
done
- install arping curl dhclient dhclient-script ping
+ install arping curl dhclient dhclient-script ping sha1sum /etc/nsswitch.conf \
+ /usr/lib/libnsl.so /usr/lib/libnss_{dns,files}.so
+ mkdir -p $TMPDIR/var/lib/dhclient
fi
# Add all storage modules
else
case $root in
/dev/disk/by-label/*)
+ type="block"
LABEL=${root#/dev/disk/by-label/}
echo "SUBSYSTEM==\"block\", PROGRAM=\"/sbin/blkid -s LABEL -o value %N\", RESULT==\"$LABEL\", SYMLINK+=\"root\"" > /etc/udev/rules.d/00-label.rules
if is_verbose; then
echo "Added udev rule 00-label.rules:"
cat /etc/udev/rules.d/00-label.rules
fi
- thingtomount=/dev/root
+ type="block"
;;
CDLABEL=*)
CDLABEL=${root#CDLABEL=}
echo "Added udev rule 00-cdlabel.rules:"
cat /etc/udev/rules.d/00-cdlabel.rules
fi
- thingtomount=/dev/root
+ type="block"
;;
LABEL=*)
LABEL=${root#LABEL=}
echo "Added udev rule 00-label.rules:"
cat /etc/udev/rules.d/00-label.rules
fi
- thingtomount=/dev/root
+ type="block"
;;
/dev/disk/by-id/*)
UUID=${root#/dev/disk/by-id/}
echo "Added udev rule 01-uuid.rules:"
cat /etc/udev/rules.d/01-uuid.rules
fi
- thingtomount=/dev/root
+ type="block"
;;
UUID=*)
UUID=${root#UUID=}
echo "Added udev rule 01-uuid.rules:"
cat /etc/udev/rules.d/01-uuid.rules
fi
- thingtomount=/dev/root
+ type="block"
;;
- NFS=*)
- NFS=${root#NFS=}
- vecho "Going on to mount $NFS"
- #mount -t nfs $NFS /mnt/source
- #rootfstype=loop
- #thingtomount=$(ls -1 /mnt/source/*.iso | head -n 1)
+ http://*|https://*|ftp*://*|ftps://*|scp://*|sftp://*)
+ thingtofetch="${root}"
+ type="download"
+
+ # When doing http(s) transfers, compress the data
+ if [ "${thingtofetch:0:4}" = "http" ]; then
+ curloptions="--compressed"
+ fi
;;
/dev/*)
ln -s $root /dev/root
- thingtomount=$root
+ type="block"
;;
*)
thingtomount=$root
esac
fi
+if [ "$type" = "block" ]; then
+ thingtomount=/dev/root
+
+elif [ "$type" = "download" ]; then
+ rootflags="loop"
+ thingtomount=/${thingtofetch##*/}
+
+ # If no network configuration was given,
+ # we'll try dhcp
+ if [ -z "${net}" ]; then
+ net="dhcp"
+ fi
+fi
+
echo "udev_log=\"error\"" >> /etc/udev/udev.conf
# rules for loading modules
echo "ACTION==\"add\", SUBSYSTEM==\"scsi_device\", SYSFS{type}==\"[45]\", RUN+=\"/sbin/modprobe sr_mod\"" >> /etc/udev/rules.d/10-modprobe.rules
echo "SUBSYSTEM==\"mmc\", RUN+=\"/sbin/modprobe mmc_block\"" >> /etc/udev/rules.d/10-modprobe.rules
-# FIXME: hack since sr_mod seems to fail to get loaded sometimes (#239657)
-modprobe sr_mod
+if [ "${type}" = "block" ]; then
+ # FIXME: hack since sr_mod seems to fail to get loaded sometimes (#239657)
+ modprobe sr_mod
+fi
modprobe loop max_loop=16
vecho "Creating devices..."
udevadm trigger
-if [ -n "$net" ]; then
+if [ "${type}" = "download" ]; then
# Wait 30 seconds for network to appear.
COUNTDOWN=30
while [ "x$COUNTDOWN" != "x0" ] ; do
vecho "Setting default gateway $gateway..."
ip route add default via $gateway
fi
- if ! ping -c3 -w10 ping.ipfire.org 2>/dev/null; then
- echo "This box does not seem to have an internet connection."
- echo "You may fix this now and continue then:"
+ if [ -n "$dns" ]; then
+ vecho "Setting up dns server $dns..."
+ echo "nameserver $dns" > /etc/resolv.conf
+ fi
+ if [ -n "$gateway" ]; then
+ vecho "Pinging gateway $gateway..."
+ if ! ping -c3 -w10 $gateway &>/dev/null; then
+ echo "This box does not seem to have a connection"
+ echo "to the default gateway $gateway."
+ echo "You may fix this now and continue then:"
+ echo
+ bash
+ fi
+ fi
+fi
+
+if [ "$type" = "download" ]; then
+ curloptions="${curloptions} --connect-timeout 30 --progress-bar --output ${thingtomount}"
+ #curloptions="${curloptions} --write-out=\"Fetched %{url_effective} in %{time_total}s (%{speed_download} bytes/s).\""
+
+ vecho "Running donwload..."
+ vecho " $thingtofetch"
+
+ curl ${curloptions} ${thingtofetch}
+
+ if [ "$?" != "0" ]; then
+ echo "An error occured when fetching ${thingtomount}:"
+ echo " Command: ${curl} ${thingtofetch}"
+ echo
+ echo "You now get a shell to download the file manually."
+ echo "Exit to continue booting."
+ echo
bash
fi
fi
bash
fi
-# Wait 90 seconds for $thingtomount to appear.
-COUNTDOWN=90
-while [ "x$COUNTDOWN" != "x0" ] ; do
- is_verbose && echo -n "."
-
- if [ -e $thingtomount ]; then
- COUNTDOWN=0
- continue
- fi
- # this is kind of lame, but we could have had a situation
- # where we were unable to read the volume id. so trigger
- # another run through the block devs
- if [ "x$COUNTDOWN" = "x30" ]; then
- udevadm trigger --subsystem-match=block
- fi
+if [ "${type}" = "block" ]; then
+ # Wait 90 seconds for $thingtomount to appear.
+ COUNTDOWN=90
+ while [ "x$COUNTDOWN" != "x0" ] ; do
+ is_verbose && echo -n "."
- COUNTDOWN=$(($COUNTDOWN - 1))
- sleep 1
-done
-vecho # Blank line
+ if [ -e $thingtomount ]; then
+ COUNTDOWN=0
+ continue
+ fi
+ # this is kind of lame, but we could have had a situation
+ # where we were unable to read the volume id. so trigger
+ # another run through the block devs
+ if [ "x$COUNTDOWN" = "x30" ]; then
+ udevadm trigger --subsystem-match=block
+ fi
+
+ COUNTDOWN=$(($COUNTDOWN - 1))
+ sleep 1
+ done
+ vecho # Blank line
+fi
if [ ! -e $thingtomount ] ; then
echo
if is_verbose; then
vecho "Mounting $thingtomount..."
- ls -l $thingtomount
+ ls -lh $thingtomount
fi
if [ "x$READONLY" == "x1" ] ; then
mountoptions=" -o$rootflags"
fi
-mount -n -t $rootfstype $mountoptions $thingtomount /mnt/source
-RES=$?
+[ -n "$rootfstype" ] && rootfstype="-t $rootfstype"
+
+mount -n $rootfstype $mountoptions $thingtomount /mnt/source
-if [ "$RES" != "0" ]; then
+if [ "$?" != "0" ]; then
echo "---------------------------------"
echo "WARNING: Cannot mount rootfs!"
echo "---------------------------------"
mount -n -t tmpfs none /mnt/tmpfs
aufsmountoptions="br:/mnt/tmpfs=rw"
-OVERLAY=$(ls /mnt/source/*.overlay 2>/dev/null || true)
-if [ -n "$OVERLAY" ]; then
- vecho "Setting up overlay for squashfs..."
- mount -t squashfs -o loop,ro $OVERLAY /mnt/overlayfs
- aufsmountoptions="$aufsmountoptions:/mnt/overlayfs=rr"
-fi
+count=0
+for overlay in $(find /mnt/source -name "*.overlay" 2>/dev/null); do
+ vecho "Setting up overlay ${overlay}..."
+ mkdir -p /mnt/overlay${count} 2>/dev/null
+ mount -n -t squashfs -o loop,ro ${overlay} /mnt/overlay${count}
+ aufsmountoptions="$aufsmountoptions:/mnt/overlay${count}=rr"
+ count=$((${count} + 1))
+done
-SQUASHED=$(ls /mnt/source/*.sfs 2>/dev/null || true)
-if [ -n "$SQUASHED" ] ; then
- vecho "Setting up embedded squashfs..."
- mount -t squashfs -o loop,ro $SQUASHED /mnt/squashfs
+count=0
+for sfs in $(find /mnt/source -name "*.sfs" 2>/dev/null); do
+ vecho "Setting up squashed fs ${sfs}..."
+ mount -n -t squashfs -o loop,ro ${sfs} /mnt/squashfs
aufsmountoptions="$aufsmountoptions:/mnt/squashfs=rr"
-fi
+ break
+done
mount -t aufs -o $aufsmountoptions none /sysroot
mount --move /mnt/$i /sysroot/mnt/$i
done
+# Shutting down network
+if [ "${type}" = "download" ]; then
+ if [ "${net}" = "dhcp" ]; then
+ kill $(pidof dhclient)
+ else
+ ip address flush dev ${netdevice}
+ fi
+ ip link set ${netdevice} down
+ ip route flush table main
+fi
+
if [ "$ESHELL" == "1" ]; then
echo "Shell requested on kernel commandline."
echo "Rootfs is mounted ro on /sysroot. Exit to continue booting."