home
readme
diff
tree
note
docs
0commit f22f6539669e18155547fa8ce2a12a4c9dafb81b
1Author: lakefox <mason@lakefox.net>
2Date: Tue Dec 16 21:45:49 2025 -0700
3
4 Boots with keyboard and ethernet
5
6diff --git a/.gitignore b/.gitignore
7new file mode 100644
8index 0000000..1a0e7cf
9--- /dev/null
10+++ b/.gitignore
11@@ -0,0 +1,2 @@
12+root/
13+initramfs_router.cpio
14diff --git a/.gitignore.swp b/.gitignore.swp
15new file mode 100644
16index 0000000..5efdf33
17Binary files /dev/null and b/.gitignore.swp differ
18diff --git a/bin/xtables-legacy-multi b/bin/xtables-legacy-multi
19new file mode 100755
20index 0000000..ed7d58a
21Binary files /dev/null and b/bin/xtables-legacy-multi differ
22diff --git a/fla.sh b/fla.sh
23new file mode 100755
24index 0000000..4facd5d
25--- /dev/null
26+++ b/fla.sh
27@@ -0,0 +1,54 @@
28+#!/bin/bash
29+# make-grub-usb.sh (run as root)
30+USB=/dev/sda # <— change to your USB device
31+mnt=/tmp/usb
32+
33+umount "$mnt"
34+partprobe "$USB"
35+dd if=/dev/zero of=$USB bs=1M count=1
36+dd if=/dev/zero of=$USB bs=1M seek=$(( $(sudo blockdev --getsz $USB) / 2048 - 10 )) count=10
37+
38+# 1. wipe and re-partition
39+sgdisk --zap-all "$USB"
40+sgdisk -n 1:0:+1M -t 1:EF02 "$USB" # BIOS boot partition
41+sgdisk -n 2:0:+300M -t 2:EF00 "$USB" # FAT32 EFI / GRUB / kernel
42+partprobe "$USB"
43+sleep 2
44+
45+# 2. format the FAT32 volume
46+mkfs.vfat -F 32 "${USB}2"
47+
48+# 3. mount and copy kernel + initramfs
49+mkdir -p "$mnt"
50+mount "${USB}2" "$mnt"
51+mkdir -p "$mnt/boot/vmlinuz"
52+cp /boot/vmlinuz-* "$mnt/boot/vmlinuz"
53+cp initramfs_router.cpio "$mnt/boot/initramfs.img"
54+
55+# 4. install GRUB for UEFI (removable-media path)
56+grub-install --target=x86_64-efi \
57+ --removable \
58+ --boot-directory="$mnt/boot" \
59+ --efi-directory="$mnt" \
60+ --no-nvram \
61+ --recheck
62+
63+# 5. install GRUB for BIOS (MBR + core.img into EF02)
64+grub-install --target=i386-pc \
65+ --boot-directory="$mnt/boot" \
66+ "$USB"
67+
68+# 6. minimal grub.cfg
69+mkdir -p "$mnt/boot/grub"
70+cat > "$mnt/boot/grub/grub.cfg" <<'GRUB'
71+set timeout=3
72+menuentry "BusyBox router" {
73+ linux /boot/vmlinuz/vmlinuz-6.12.57+deb13-amd64 root=/dev/ram0 rw i8042.nomux=1 i8042.reset=1 i8042.direct=1 i8042.dumbkbd=1
74+ initrd /boot/initramfs.img
75+}
76+GRUB
77+
78+umount "$mnt"
79+rmdir "$mnt"
80+echo "USB ready – boots on both UEFI and BIOS."
81+
82diff --git a/init.sh b/init.sh
83new file mode 100755
84index 0000000..e1f19a5
85--- /dev/null
86+++ b/init.sh
87@@ -0,0 +1,103 @@
88+#!/bin/bash
89+
90+rm -rf root/
91+rm -f initramfs_router.cpio
92+
93+mkdir -p root/{bin,sbin,etc,proc,sys,usr,dev,tmp,var}
94+mkdir -p root/boot
95+
96+mkdir -p root/lib/firmware
97+cp -r /lib/firmware/rtl_nic root/lib/firmware/
98+
99+# Assuming you have a static busybox binary at this path:
100+cp /usr/bin/busybox root/bin/
101+
102+# Run scripts/iptables.sh to create
103+cp bin/xtables-legacy-multi root/bin/
104+
105+cd root/bin
106+./busybox --install ./
107+cd -
108+
109+# Add the ethernet drivers
110+#cp "/lib/modules/$(uname -r)/kernel/drivers/net/ethernet/realtek/r8169.ko.xz" root/lib/modules/
111+
112+# 1. Define your target modules
113+# Using xhci-pci usually pulls in xhci-hcd, and usbhid pulls in hid/usbcore
114+TARGET_MODS="xhci-pci usbhid hid-generic hid-apple r8169 realtek libphy"
115+
116+# 2. Clear and recreate the module directory structure
117+KVER=$(uname -r)
118+MOD_DEST="root/lib/modules/$KVER"
119+mkdir -p "$MOD_DEST"
120+
121+# 3. Copy the necessary metadata files to satisfy depmod
122+cp "/lib/modules/$KVER/modules.order" "$MOD_DEST/"
123+cp "/lib/modules/$KVER/modules.builtin" "$MOD_DEST/"
124+
125+# 4. Use modinfo to find and copy every dependency for our target modules
126+for mod in $TARGET_MODS; do
127+ # Get the path for the module and all its dependencies
128+ # then copy them while preserving the directory structure
129+ modprobe --show-depends $mod | awk '{print $2}' | while read line; do
130+ cp --parents "$line" root/
131+ done
132+done
133+
134+# 5. Run depmod pointing to your root directory
135+# The -a flag tells it to analyze all modules found
136+depmod -b root/ "$KVER"
137+
138+cat << EOF > root/init
139+#!/bin/sh
140+
141+# 1. Mount essential kernel filesystems
142+/bin/mount -t proc proc /proc
143+/bin/mount -t sysfs sysfs /sys
144+/bin/mount -t devtmpfs devtmpfs /dev
145+
146+# Start the drivers
147+/bin/modprobe xhci-pci
148+/bin/modprobe usbhid
149+/bin/modprobe hid-apple
150+/bin/modprobe hid-generic
151+/bin/modprobe realtek
152+/bin/modprobe libphy
153+/bin/modprobe r8169
154+
155+#/bin/xz -d /lib/modules/r8169.ko.xz
156+#/bin/insmod /lib/modules/r8169.ko
157+
158+# 2. Configure Networking for Router (This is where your setup logic goes)
159+
160+# Set IP forwarding (Mandatory for a router)
161+/bin/echo 1 > /proc/sys/net/ipv4/ip_forward
162+
163+# Bring up interfaces (replace with your interface names and IPs)
164+/bin/ip link set eth0 up
165+/bin/ip link set eth1 up
166+/bin/ip addr add 192.168.1.1/24 dev eth0
167+
168+# 3. Apply Firewall/NAT Rules (Using BusyBox's limited iptables support or a custom script)
169+# Note: BusyBox typically links to the full iptables binary if available, or requires a custom build.
170+# We'll just start the shell for now.
171+
172+sleep 2
173+
174+echo "--- BusyBox Router Initialized ---"
175+
176+# 4. Start the interactive root shell (PID 1 hands off to this)
177+exec setsid cttyhack /bin/sh || exec /bin/sh
178+
179+# 5. If the shell exits, prevent the panic
180+echo "Root shell exited. Shutting down."
181+/bin/poweroff -f
182+EOF
183+
184+# Make the init script executable
185+chmod +x root/init
186+
187+cd root
188+# Create the cpio archive
189+find . -print0 | cpio --null -o --format=newc > ../initramfs_router.cpio
190+cd -
191diff --git a/scripts/iptables.sh b/scripts/iptables.sh
192new file mode 100644
193index 0000000..ba3fc2b
194--- /dev/null
195+++ b/scripts/iptables.sh
196@@ -0,0 +1,19 @@
197+#!/bin/bash
198+source=(https://netfilter.org/projects/iptables/files/iptables-1.8.11.tar.xz)
199+
200+print $source
201+
202+curl -q -L -O $source
203+tar xvf iptables-1.8.11.tar.xz
204+
205+cd iptables-1.8.11
206+
207+./configure \
208+ --prefix=/ \
209+ --disable-shared \
210+ --enable-static \
211+ --disable-nftables
212+
213+make
214+cd iptables/
215+cp xtables-legacy-multi ../../../bin
216diff --git a/vm.sh b/vm.sh
217new file mode 100755
218index 0000000..a7d9396
219--- /dev/null
220+++ b/vm.sh
221@@ -0,0 +1,15 @@
222+#!/bin/bash
223+
224+KERNEL_FILE=/boot/vmlinuz-$(uname -r)
225+
226+qemu-system-x86_64 \
227+ -kernel $KERNEL_FILE \
228+ -initrd initramfs_router.cpio \
229+ -append "init=/init console=ttyS0" \
230+ -nographic \
231+ -m 512 \
232+ -smp 1 \
233+ -device virtio-net-pci,netdev=eth0,mac=52:54:00:12:34:56 \
234+ -netdev user,id=eth0,hostfwd=tcp::2222-:22 \
235+ -device virtio-net-pci,netdev=eth1,mac=52:54:00:12:34:57 \
236+ -netdev user,id=eth1