aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile27
-rw-r--r--scripts/init.rootfs19
-rw-r--r--skeleton/etc/.placeholder0
-rwxr-xr-xskeleton/usr/share/udhcpc/default.script63
4 files changed, 102 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 3008a2d..684ee0b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,9 @@
ARCH=$(shell uname -m)
+NET_BRIDGE ?= br0
+NET_HWADDR ?= 66:66:66:66:66:66
+NET_IP4 ?=
-BUILDJOBS ?= 5
+BUILDJOBS ?= $(shell cat /proc/cpuinfo | grep -o '^processor' | wc -l)
THIS_DIR=$(realpath .)
DL_DIR=$(THIS_DIR)/dl
@@ -87,6 +90,8 @@ $(LINUX_TARGET):
make -C '$(LINUX_BUILD_DIR)' kvmconfig
make -C '$(LINUX_BUILD_DIR)' -j$(BUILDJOBS) ARCH='$(ARCH)' bzImage
make -C '$(LINUX_BUILD_DIR)' -j$(BUILDJOBS) ARCH='$(ARCH)' INSTALL_HDR_PATH='$(ROOTFS_DIR)/usr' headers_install
+ make -C '$(LINUX_BUILD_DIR)' -j$(BUILDJOBS) ARCH='$(ARCH)' INSTALL_MOD_PATH='$(ROOTFS_DIR)/usr' modules
+ make -C '$(LINUX_BUILD_DIR)' -j$(BUILDJOBS) ARCH='$(ARCH)' INSTALL_MOD_PATH='$(ROOTFS_DIR)/usr' modules_install
$(MUSL_TARGET):
cd '$(MUSL_BUILD_DIR)' && (test -r ./config.mak || ./configure --prefix='$(ROOTFS_DIR)/usr')
@@ -105,7 +110,7 @@ build: extract $(LINUX_TARGET) $(MUSL_TARGET) $(BUSYBOX_TARGET)
$(INITRD_TARGET):
cp -v '$(SCRIPT_DIR)/init.rootfs' '$(ROOTFS_DIR)/init'
- cp -rfvT '$(SKEL_DIR)' '$(ROOTFS_DIR)'
+ cp -rfvTp '$(SKEL_DIR)' '$(ROOTFS_DIR)'
chmod 0755 '$(ROOTFS_DIR)/init'
cd '$(ROOTFS_DIR)' && find . -print0 | cpio --null -ov --format=newc | gzip -9 > '$(INITRD_TARGET)'
@@ -115,10 +120,15 @@ define DO_BUILD
make
endef
-image-rebuild:
- rm -rf '$(ROOTFS_DIR)'
+force-remove:
rm -f $(LINUX_TARGET) $(MUSL_TARGET) $(BUSYBOX_TARGET)
rm -f '$(INITRD_TARGET)'
+
+image-rebuild: force-remove
+ rm -rf '$(ROOTFS_DIR)'
+ $(DO_BUILD)
+
+image-reinstall: force-remove
$(DO_BUILD)
image-repack:
@@ -126,4 +136,11 @@ image-repack:
$(DO_BUILD)
qemu: image
- qemu-system-x86_64 -kernel '$(LINUX_BUILD_DIR)/arch/x86_64/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm
+ qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -vga qxl -display sdl
+
+qemu-console: image
+ qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -curses
+
+qemu-net: image
+ qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -vga qxl -display sdl \
+ -net nic,macaddr=$(NET_HWADDR) -net tap,ifname=linux-qemu-test,br=$(NET_BRIDGE) -append 'net $(if $(NET_IP4),ip4)'
diff --git a/scripts/init.rootfs b/scripts/init.rootfs
index c4011a6..9f0bd8d 100644
--- a/scripts/init.rootfs
+++ b/scripts/init.rootfs
@@ -24,7 +24,22 @@ Welcome to mini_linux
!
+for arg in $(cat /proc/cmdline | tr '[:upper:]' '[:lower:]'); do
+ if [ x"${arg}" = xip4 ]; then
+ sysctl -w net.ipv6.conf.all.disable_ipv6=1
+ fi
+done
+
+for arg in $(cat /proc/cmdline | tr '[:upper:]' '[:lower:]'); do
+ if [ x"${arg}" = xnet ]; then
+ echo '*** INIT NETWORK ***'
+ for netif in $(ls /sys/class/net); do
+ ifconfig ${netif} 0.0.0.0 up
+ done
+ udhcpc -R
+ fi
+done
+
loadkmap </usr/share/keymaps/i386/qwertz/de-latin1.bmap
setsid cttyhack sh
-poweroff
-echo q >/proc/sysrq-trigger
+poweroff -f
diff --git a/skeleton/etc/.placeholder b/skeleton/etc/.placeholder
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/skeleton/etc/.placeholder
diff --git a/skeleton/usr/share/udhcpc/default.script b/skeleton/usr/share/udhcpc/default.script
new file mode 100755
index 0000000..843f026
--- /dev/null
+++ b/skeleton/usr/share/udhcpc/default.script
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+# udhcpc config script
+
+# $interface is the name of the device udhcpc is using
+# $router is the (space_separated) list of gateways
+# $broadcast is the broadcast address
+# $ip is the ip address that we get from the dhcp server
+# $dns is the list of dns servers we get from the dhcp server
+# $domain is the domain of the network
+
+# constants for the resolv.conf and backup files
+resolv_conf="/etc/resolv.conf"
+resolv_bak="/etc/resolv.backup_dhcp"
+
+
+case $1 in
+ deconfig)
+ # deconfig - put the interface up but deconfigured
+ # called when udhcpc is started or a lease is lost
+
+ # replace resolv.conf with the backup, if the backup exists:
+ if [ -f "$resolv_bak" ]; then
+ mv "$resolv_bak" "$resolv_conf"
+ fi
+
+ # set the interface's address to 0.0.0.0 for now
+ ifconfig $interface 0.0.0.0;;
+
+ renew|bound)
+ # renew - lease is renewed
+ # bound - move from unbound to bound state
+
+ # configure the interface with the given ip, broadcast address, and netmask
+ ifconfig $interface $ip ${broadcast:+broadcast $broadcast} ${subnet:+netmask $subnet}
+
+ # for each given gateway, overwrite the defaults??? hell if I know.
+ for i in $router; do
+ route add default gw $i dev $interface
+ done
+
+ if [ ! -f "$resolv_bak" ] && [ -f "$resolv_conf" ]; then
+ mv "$resolv_conf" "$resolv_bak"
+ fi
+
+ # clear `resolv.conf`
+ echo -n "" > "$resolv_conf"
+
+ # if there's a domain given, add it to `resolv.conf`.
+ if [ -n "$domain" ]; then
+ echo "search $domain" >> "$resolv_conf"
+ fi
+
+ # for each given dns server, add it to `resolv.conf`.
+ for i in $dns; do
+ echo "nameserver $i" >> "$resolv_conf"
+ done;;
+esac
+
+exit 0
+
+# adapted from http://lists.debian.org/debian-boot/2002/11/msg00500.html
+# from https://gist.githubusercontent.com/startling/2165518/raw/415b307b8441c236461296c648b7d975ef9b0dde/gistfile1.sh