home: hub: mkinitfs

Download patch

ref: cb013df1407dc75d033de2ce79aafc4edd510483
parent: 06e34557edb00b7962de97cf71818605a8364f9a
author: Ain <41307858+nero@users.noreply.github.com>
date: Thu Aug 23 05:07:18 CDT 2018

Move code blocks for initializing the early userspace together

--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -7,20 +7,6 @@
 splashfile=/.splash.ctrl
 repofile=/tmp/repositories
 
-/bin/busybox mkdir -p /usr/bin /usr/sbin /proc /sys /dev $sysroot \
-	/media/cdrom /media/usb /tmp /run
-/bin/busybox --install -s
-
-# basic environment
-export PATH=/usr/bin:/bin:/usr/sbin:/sbin
-
-# needed devs
-[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
-
-# basic mounts
-mount -t proc -o noexec,nosuid,nodev proc /proc
-mount -t sysfs -o noexec,nosuid,nodev sysfs /sys
-
 # some helpers
 ebegin() {
 	last_emsg="$*"
@@ -293,6 +279,34 @@
 	esac
 }
 
+/bin/busybox mkdir -p /usr/bin /usr/sbin /proc /sys /dev $sysroot \
+        /media/cdrom /media/usb /tmp /run
+
+# Spread out busybox symlinks and make them available without full path
+/bin/busybox --install -s
+export PATH=/usr/bin:/bin:/usr/sbin:/sbin
+
+# Make sure /dev/null is a device node. If /dev/null does not exist yet, the command
+# mounting the devtmpfs will create it implicitly as an file with the "2>" redirection.
+# The -c check is required to deal with initramfs with pre-seeded device nodes without
+# error message.
+[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
+
+mount -t proc -o noexec,nosuid,nodev proc /proc
+mount -t sysfs -o noexec,nosuid,nodev sysfs /sys
+mount -t devtmpfs -o exec,nosuid,mode=0755,size=2M devtmpfs /dev 2>/dev/null \
+	|| mount -t tmpfs -o exec,nosuid,mode=0755,size=2M tmpfs /dev
+
+# pty device nodes (later system will need it)
+[ -c /dev/ptmx ] || mknod -m 666 /dev/ptmx c 5 2
+[ -d /dev/pts ] || mkdir -m 755 /dev/pts
+mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
+
+# shared memory area (later system will need it)
+[ -d /dev/shm ] || mkdir /dev/shm
+mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
+
+
 # read the kernel options. we need surve things like:
 #  acpi_osi="!Windows 2006" xen-pciback.hide=(01:00.0)
 set -- $(cat /proc/cmdline)
@@ -355,18 +369,6 @@
 for i in ${KOPT_blacklist//,/ }; do
 	echo "blacklist $i" >> /etc/modprobe.d/boot-opt-blacklist.conf
 done
-
-# setup /dev
-mount -t devtmpfs -o exec,nosuid,mode=0755,size=2M devtmpfs /dev 2>/dev/null \
-	|| mount -t tmpfs -o exec,nosuid,mode=0755,size=2M tmpfs /dev
-[ -d /dev/pts ] || mkdir -m 755 /dev/pts
-[ -c /dev/ptmx ] || mknod -m 666 /dev/ptmx c 5 2
-# make sure /dev/null is setup correctly
-[ -f /dev/null ] && rm -f /dev/null
-[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
-mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
-[ -d /dev/shm ] || mkdir /dev/shm
-mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
 
 # determine if we are going to need networking
 if [ -n "$KOPT_ip" ] || [ -n "$KOPT_nbd" ] || \