Skip to content

Commit f50f2c1

Browse files
committed
Network access via DHCP / PXELINUX BOOTIF
1 parent d7a1b32 commit f50f2c1

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

functions

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ want_lib(){
7171
return 0
7272
}
7373

74-
want_module(){
74+
want_module_internal(){
7575
modinfo=$(grep "$1" "/lib/modules/$(uname -r)/modules.dep" | head -n 1)
7676
modpath="/lib/modules/$(uname -r)/$(printf "%s" "$modinfo" | cut -d ":" -f 1)"
7777
moddeps="$(printf "%s" "$modinfo" | cut -d ":" -f 2 | tr " " "\n")"
@@ -87,8 +87,13 @@ want_module(){
8787

8888
if [ -n "$moddeps" ]; then
8989
for dep in $moddeps; do
90-
want_module "$dep:"
90+
want_module_internal "$dep:"
9191
done
9292
fi
9393
return 0
9494
}
95+
96+
want_module(){
97+
printf "$1\n" >> modules
98+
want_module_internal $1
99+
}

init

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,58 @@
11
#!/bin/busybox sh
2+
#set -x
23

4+
# Create directory structure if it doesn't already exist from the overlay
35
for dir in bin dev etc lib lib64 mnt proc root sys usr/sbin usr/bin sbin; do
46
/bin/busybox mkdir -p "$dir"
57
done
68

9+
# Install busybox links
710
/bin/busybox --install -s
811

12+
# Create some more environment
913
mount -t proc none /proc
1014
mount -t sysfs none /sys
1115
mount -t devtmpfs none /dev
1216

17+
# Stop kernel messages
18+
printf "3 4 1 3" > /proc/sys/kernel/printk
19+
20+
# Load kernel modules
21+
depmod
22+
cat modules | while read mod; do
23+
modprobe "$mod"
24+
done
25+
26+
# Bring up a network interface
27+
if [ -n "$BOOTIF" ]; then
28+
mac=$(printf "%s" "$BOOTIF" | cut -d "-" -f 2- | tr "-" ":" | tr -d " \n")
29+
for ifacepath in /sys/class/net/*; do
30+
iface=$(basename "$ifacepath")
31+
if [ -f "$ifacepath/address" ]; then
32+
if [ "$mac" = "$(cat $ifacepath/address | tr -d " \n")" ]; then
33+
printf "Boot interface recognized as %s, trying DHCP\n" "$iface"
34+
ip l set dev "$iface" up
35+
udhcpc -i "$iface" -s ./udhcpc.script
36+
done=1
37+
fi
38+
fi
39+
done
40+
if [ -z "$done" ]; then
41+
printf "Boot interface %s not found, not configured\n" "$mac"
42+
fi
43+
else
44+
for iface in /sys/class/net/*; do
45+
ip l set dev "$iface" up
46+
done
47+
48+
printf "Trying DHCP on all supported interfaces\n"
49+
udhcpc -s ./udhcpc.script
50+
fi
51+
1352
if [ -x "./main" ]; then
1453
./main
1554
else
16-
printf "This is jamdisk"
55+
printf "This is jamdisk\n"
1756
sh
1857
fi
1958

jamdisk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fi
3636

3737
printf "Installing init\n"
3838
cp init "$ROOT"
39+
cp udhcpc.script "$ROOT"
3940

4041
printf "Building initial RAM filesystem\n"
4142
(cd "$ROOT"; find . -print0 | cpio --null -o --format=newc | gzip -9) > "$PROJECT.initrd"

stowaway.script

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
want_bin rsync
1+
want_bin rsync
22
want_bin sfdisk
33
want_bin whiptail
4+
want_bin partclone.btrfs
5+
want_bin partclone.dd
6+
want_bin partclone.exfat
7+
want_bin partclone.extfs
8+
want_bin partclone.fat
9+
want_bin partclone.hfsp
10+
want_bin partclone.ntfs
11+
want_bin partclone.ntfsfixboot
12+
want_bin partclone.restore
13+
want_bin partclone.xfs
14+
want_bin partclone.chkimg
415

516
want_module tg3
617
want_module igb
7-
want_module e1000
818
want_module e1000e
19+
want_module e1000

udhcpc.script

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
case "$1" in
4+
"deconfig")
5+
ip l set dev "$interface" down
6+
ip l set dev "$interface" up
7+
;;
8+
"renew")
9+
ip a replace "$ip/$mask" dev "$interface"
10+
echo "" > "/etc/resolv.conf"
11+
for srv in $dns; do
12+
printf "nameserver %s\n" "$srv" >> "/etc/resolv.conf"
13+
done
14+
for rtr in $router; do
15+
ip r replace default via "$rtr" dev "$interface"
16+
done
17+
;;
18+
"bound")
19+
ip a add "$ip/$mask" dev "$interface"
20+
for srv in $dns; do
21+
printf "nameserver %s\n" "$srv" >> "/etc/resolv.conf"
22+
done
23+
for rtr in $router; do
24+
ip r add default via "$rtr" dev "$interface"
25+
done
26+
;;
27+
"nak")
28+
printf "Failed to get a DHCP lease\n"
29+
;;
30+
esac

0 commit comments

Comments
 (0)