Skip to content

Instantly share code, notes, and snippets.

@joelagnel
Created September 14, 2023 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joelagnel/b4a640058d577086c2d5280cd698ee63 to your computer and use it in GitHub Desktop.
Save joelagnel/b4a640058d577086c2d5280cd698ee63 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Save this file as "init" in the root of your CPIO archive,
# and chmod +x it. This will chroot into an HDD if one is
# available. Or it will just give a prompt.
mkdir -p /proc /sys /d /pstore /dev
mount -t proc none /proc
mount -t sysfs none /sys
mount -t debugfs none /d
mount -t debugfs none /sys/kernel/debug/
mount -t pstore none /pstore >/dev/null 2>&1
cd /dev/
mknod sda b 8 0
mknod ashmem c 10 62
# If command specified on kernel cmdline, run it and quit
cmdrun=$(cat /proc/cmdline|cut -d \" -f2)
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds only\n"
# If a drive is attached, just assume its ext4 and
# chroot into it.
mkdir -p /hda
mount -t ext4 /dev/sda /hda >/dev/null 2>&1
if [ $? -eq 0 ]; then
mkdir -p /hda/proc; mount --bind /proc /hda/proc
mkdir -p /hda/sys ; mount --bind /sys /hda/sys
mkdir -p /hda/d ; mount -t debugfs none /hda/d
mount -t debugfs none /hda/sys/kernel/debug/
if [ "x$cmdrun" != "x" ]; then BASHOPTS1="-c \"$cmdrun\""; fi
echo "Chrooting into /hda"
setsid cttyhack /bin/bash -c "chroot /hda bash --rcfile /.bashrc $BASHOPTS1"
busybox poweroff -f
fi
if [ "x$cmdrun" != "x" ]; then
setsid cttyhack /bin/bash -c "$cmdrun"
else
setsid cttyhack /bin/bash
fi
busybox poweroff -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment