home: hub: mkinitfs

Download patch

ref: 41b8d83c6797d4002279e89961151ddc7000ba4d
parent: 1da2019c021a0ca3b9c33ae088ea8a6501b5251a
author: Natanael Copa <ncopa@alpinelinux.org>
date: Wed Jun 10 13:32:28 CDT 2009

init: let openrc load modloop, after switch_root

--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -59,7 +59,7 @@
 
 retry_mount() {
 	# usb might need some time to settle so we retry a few times
-	for i in $(seq 0 19); do
+	for i in $(seq 0 9); do
 		mount $@ 2>&1 && return 0
 		sleep 1
 	done
@@ -102,6 +102,26 @@
 	return 1
 }
 
+# find mount dir for given device in an fstab
+find_mnt() {
+	local dev="$1"
+	local fsfile="$2"
+	awk "\$ == \"$dev\" {print \$2}\"" "$fsfile" 2>/dev/null
+}
+
+# Wait for usb to settle
+wait_usb() {
+	if [ -n "$USB_DONE" ] || ! dmesg | grep '^usb-storage: waiting' >/dev/null; then
+		return 0
+	fi
+	ebegin "Waiting for USB device to settle"
+	while ! dmesg | grep 'usb-storage: device scan complete' >/dev/null; do
+		sleep 1
+	done
+	USB_DONE=yes
+	eend 0
+}
+
 # gotta start from somewhere :)
 echo "Alpine Init $VERSION"
 
@@ -140,8 +160,11 @@
 if [ "$ALPINE_DEV_FS" = "$ALPINE_DEV" ]; then
 	unset ALPINE_DEV_FS
 fi
-ALPINE_MNT=/media/$ALPINE_DEV
 
+# look for standard mountpoint locations
+ALPINE_MNT=$(find_mnt /dev/$ALPINE_DEV /etc/fstab)
+[ -z "$ALPINE_MNT" ] && ALPINE_MNT=/media/$ALPINE_DEV
+
 # hide kernel messages
 dmesg -n 1
 
@@ -199,6 +222,11 @@
 	exec /bin/busybox sh
 fi
 
+# we only want to wait for usb if really needed at this point
+if [ -z "${ALPINE_DEV##*usb*}" ]; then
+	wait_usb
+fi
+
 # locate boot media and mount it
 ebegin "Mounting boot media"
 mkdir -p $ALPINE_MNT
@@ -209,33 +237,6 @@
 retry_mount $mount_opts /dev/$ALPINE_DEV $ALPINE_MNT >/dev/null 2>&1
 eend $?
 
-ebegin "Mounting loopback device for kernel modules"
-modprobe loop
-if [ -n "$KOPT_modloop" ]; then
-	modloop=$KOPT_modloop
-else
-	modloop=$KOPT_BOOT_IMAGE.cmg
-fi
-mount -o loop,ro -t cramfs $ALPINE_MNT/$modloop /.modloop
-rc=$?
-if [ "$rc" = 0 ]; then
-	rm -rf /lib/modules
-	ln -sf /.modloop/modules /lib
-fi
-eend $?
-
-if [ -d $ALPINE_MNT/firmware ]; then
-	ebegin "Copying firmware from $ALPINE_MNT/firmware"
-	mkdir -p /lib
-	cp -R -a $ALPINE_MNT/firmware /lib/
-	eend $?
-fi
-
-mkdir -p /etc/apk
-for i in $ALPINE_MNT/*/APK_INDEX.gz $ALPINE_MNT/*/*/APK_INDEX.gz; do
-	[ -r "$i" ] && echo ${i%/APK_INDEX.gz} >> /etc/apk/repositories
-done
-
 # early console?
 if [ "$SINGLEMODE" = "yes" ]; then
 	echo "Entering single mode. Type 'exit' to continue booting."
@@ -242,11 +243,6 @@
 	sh
 fi
 
-# more drivers
-ebegin "Loading hardware drivers"
-scan_drivers
-eend 0
-
 # mount tmpfs sysroot
 root_opts=
 if [ -n "$KOPT_root_size" ]; then
@@ -254,14 +250,10 @@
 fi
 mount -t tmpfs $root_opts tmpfs $sysroot
 
+# wait for usb to settle if needed
+wait_usb
+
 # look for apkovl
-if dmesg | grep '^usb-storage: waiting' >/dev/null; then
-	ebegin "Waiting for USB device to settle"
-	while ! dmesg | grep 'usb-storage: device scan complete' >/dev/null; do
-		sleep 1
-	done
-	eend 0
-fi
 for i in usb floppy cdrom; do
 	mount /media/$i 2>/dev/null || continue
 	ovl=$(find_ovl /media/$i)
@@ -286,6 +278,21 @@
 # hack so we get openrc
 pkgs="$pkgs alpine-baselayout alpine-conf apk-tools"
 
+# move the ALPINE_MNT if ALPINE_DEV is specified in users fstab
+# this is so a generated /etc/apk/repositories will use correct mount dir
+new_mnt=$(find_mnt /dev/$ALPINE_DEV $sysroot/etc/fstab)
+if [ -n "$new_mnt" ] && [ "$new_mnt" != "$ALPINE_MNT" ]; then
+	mkdir -p $new_mnt
+	mount -o move $ALPINE_MNT $new_mnt
+	ALPINE_MNT="$new_mnt"
+fi
+
+# generate apk repositories file
+mkdir -p /etc/apk
+for i in $ALPINE_MNT/*/APK_INDEX.gz $ALPINE_MNT/*/*/APK_INDEX.gz; do
+	[ -r "$i" ] && echo ${i%/APK_INDEX.gz} >> /etc/apk/repositories
+done
+
 # install new root
 ebegin "Installing packages to root filesystem"
 if [ -n "$KOPT_chart" ]; then
@@ -321,7 +328,6 @@
 		mount -o move $DIR $sysroot/$DIR
 	fi
 done
-ln -sf /.modloop/modules $sysroot/lib/modules
 sync
 
 echo ""