commit e45dee332afa441d00047976a992fefea087c266
parent 81966b4393623e7f701213b369df0d177696d236
Author: emmett1 <emmett1.2miligrams@protonmail.com>
Date: Sun, 21 Dec 2025 16:31:53 +0800
added support live iso
Diffstat:
| M | init | | | 104 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------- |
| M | mkinitrd | | | 3 | ++- |
2 files changed, 81 insertions(+), 26 deletions(-)
diff --git a/init b/init
@@ -29,64 +29,118 @@ for param in $cmdline; do
ro ) ro="ro" ;;
rw ) ro="rw" ;;
shell ) shell=1 ;;
+ liveos ) live=1 ;;
esac
done
# mdev
[ -f /proc/sys/kernel/hotplug ] && \
- echo $(which mdev) > /proc/sys/kernel/hotplug
+ which mdev > /proc/sys/kernel/hotplug
mdev -s
# load modules using modalias
find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -b -a 2>/dev/null
-# load modules specific modules
+# load modules
for m in virtio virtio_ring virtio_pci virtio_blk virtio_scsi nvme \
ata_piix sd_mod sr_mod cdrom loop squashfs isofs overlay mbcache \
jbd jbd2 ext2 ext3 ext4 xfs btrfs f2fs reiserfs jfs fat vfat exfat ntfs3; do
modprobe "$m" 2>/dev/null
done
-[ "$shell" ] && exec sh
+[ "$shell" ] && sh
[ "$rootflags" ] && rootflags="$rootflags,"
rootflags="$rootflags$ro"
-case "$root" in
- /dev/* ) device=$root ;;
- UUID=* ) eval $root; device="$(blkid | grep "$UUID" | cut -d : -f1 | head -n1)" ;;
- LABEL=* ) eval $root; device="$(blkid | grep "$LABEL" | cut -d : -f1 | head -n1)" ;;
- "" ) echo "!! no root device specified" ; exec sh;;
-esac
-
-if [ "$rootdelay" ]; then
- while [ ! -b "$device" ] && [ $i -lt "$rootdelay" ]; do
- echo ">> waiting for $device..."
+if [ "$live" ]; then
+ INITRAMFS=/run/initramfs
+ MEDIA=$INITRAMFS/media
+ LOWER=$INITRAMFS/lower
+ UPPER=$INITRAMFS/upper
+ WORK=$INITRAMFS/work
+ SFSIMAGE=$MEDIA/liveos/rootfs.sfs
+
+ mkdir -p $LOWER $MEDIA $UPPER $WORK
+
+ # figure out media
+ if [ -f /proc/sys/dev/cdrom/info ]; then
+ CDROM=$(grep name /proc/sys/dev/cdrom/info | awk -F : '{print $2}' | awk '{print $1}')
+ fi
+
+ while [ "$wait" != 10 ]; do
+ BLOCK=$(grep -E '[vsh]d' /proc/partitions | awk '{print $4}')
+ for i in $CDROM $BLOCK; do
+ mount -v -r /dev/"$i" $MEDIA >/dev/null 2>&1 || continue
+ [ -d $MEDIA/liveos ] || { umount $MEDIA; continue; }
+ MEDIAFOUND=1
+ break 2
+ done
+ wait=$(( wait + 1 ))
sleep 1
- i=$((i+1))
done
-fi
-while [ ! -b "$device" ] ; do
- echo "!! device '$device' not found"
- exec sh
-done
+ if [ ! "$MEDIAFOUND" ]; then
+ echo "Media not found even after 10 seconds"
+ sh
+ echo "Cannot go further"
+ sleep 99999
+ exit 1
+ fi
+
+ # mount stuff
+ loopdevice=$(losetup -f)
+ losetup -f $SFSIMAGE
+ mount -r "$loopdevice" $LOWER
+ mount -t overlay overlay -o lowerdir=$LOWER,upperdir=$UPPER,workdir=$WORK $NEWROOT
+ if [ -f $MEDIA/liveos/live.gz ]; then
+ tar -xzaf $MEDIA/liveos/live.gz -C $NEWROOT
+ fi
+else
+ case "$root" in
+ /dev/* ) device=$root ;;
+ UUID=* ) eval "$root"; device="$(blkid | grep "$UUID" | cut -d : -f1 | head -n1)" ;;
+ LABEL=* ) eval "$root"; device="$(blkid | grep "$LABEL" | cut -d : -f1 | head -n1)" ;;
+ "" ) echo "!! no root device specified" ; exec sh;;
+ esac
+
+ if [ "$rootdelay" ]; then
+ while [ ! -b "$device" ] && [ "$i" -lt "$rootdelay" ]; do
+ echo ">> waiting for $device..."
+ sleep 1
+ i=$((i+1))
+ done
+ fi
+
+ while [ ! -b "$device" ] ; do
+ echo "!! device '$device' not found"
+ exec sh
+ done
+
+ if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" $NEWROOT; then
+ echo "!! failed to mount device '$device'"
+ exec sh
+ fi
-if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" $NEWROOT; then
- echo "!! failed to mount device '$device'"
- exec sh
fi
-[ "$shell" ] && exec sh
+[ "$shell" ] && sh
+
+pkill mdev
mount --move /sys $NEWROOT/sys
mount --move /proc $NEWROOT/proc
mount --move /dev $NEWROOT/dev
mount --move /run $NEWROOT/run
+# execute live script if exist
+if [ -f $NEWROOT/"$MEDIA"/liveos/live.sh ]; then
+ chroot $NEWROOT sh "$MEDIA"/liveos/live.sh
+fi
+
# switch to newroot
-exec /bin/switch_root $NEWROOT $init $@
+exec switch_root $NEWROOT "$init" $@
echo ">> this is the end of initramfs"
echo ">> nothing further, here's the shell"
-/bin/busybox sh
+busybox sh
diff --git a/mkinitrd b/mkinitrd
@@ -10,6 +10,7 @@ add_kmod() {
add_file $path
for firmware in $(modinfo -k $K -F firmware $kmod); do
[ -f /lib/firmware/$firmware.xz ] && add_file /lib/firmware/$firmware.xz
+ [ -f /lib/firmware/$firmware.gz ] && add_file /lib/firmware/$firmware.gz
[ -f /lib/firmware/$firmware ] && add_file /lib/firmware/$firmware
done
for depends in $(modinfo -k $K -F depends $kmod | tr ',' ' '); do
@@ -137,7 +138,7 @@ else
crypto fs lib drivers/block drivers/md drivers/ata \
drivers/firewire drivers/input/keyboard drivers/input/mouse \
drivers/scsi drivers/message drivers/pcmcia drivers/virtio \
- drivers/usb/host drivers/usb/storage drivers/hid;
+ drivers/usb/host drivers/usb/storage drivers/hid drivers/cdrom;
do
for f in $(find $M/kernel/$d -name *.ko*); do
f=${f##*/}; f=${f%.ko*}