Skip to content

Commit

Permalink
Network access via DHCP / PXELINUX BOOTIF
Browse files Browse the repository at this point in the history
  • Loading branch information
cbdevnet committed May 12, 2018
1 parent d7a1b32 commit f50f2c1
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
9 changes: 7 additions & 2 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ want_lib(){
return 0
}

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

if [ -n "$moddeps" ]; then
for dep in $moddeps; do
want_module "$dep:"
want_module_internal "$dep:"
done
fi
return 0
}

want_module(){
printf "$1\n" >> modules
want_module_internal $1
}
41 changes: 40 additions & 1 deletion init
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
#!/bin/busybox sh
#set -x

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

# Install busybox links
/bin/busybox --install -s

# Create some more environment
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev

# Stop kernel messages
printf "3 4 1 3" > /proc/sys/kernel/printk

# Load kernel modules
depmod
cat modules | while read mod; do
modprobe "$mod"
done

# Bring up a network interface
if [ -n "$BOOTIF" ]; then
mac=$(printf "%s" "$BOOTIF" | cut -d "-" -f 2- | tr "-" ":" | tr -d " \n")
for ifacepath in /sys/class/net/*; do
iface=$(basename "$ifacepath")
if [ -f "$ifacepath/address" ]; then
if [ "$mac" = "$(cat $ifacepath/address | tr -d " \n")" ]; then
printf "Boot interface recognized as %s, trying DHCP\n" "$iface"
ip l set dev "$iface" up
udhcpc -i "$iface" -s ./udhcpc.script
done=1
fi
fi
done
if [ -z "$done" ]; then
printf "Boot interface %s not found, not configured\n" "$mac"
fi
else
for iface in /sys/class/net/*; do
ip l set dev "$iface" up
done

printf "Trying DHCP on all supported interfaces\n"
udhcpc -s ./udhcpc.script
fi

if [ -x "./main" ]; then
./main
else
printf "This is jamdisk"
printf "This is jamdisk\n"
sh
fi

Expand Down
1 change: 1 addition & 0 deletions jamdisk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fi

printf "Installing init\n"
cp init "$ROOT"
cp udhcpc.script "$ROOT"

printf "Building initial RAM filesystem\n"
(cd "$ROOT"; find . -print0 | cpio --null -o --format=newc | gzip -9) > "$PROJECT.initrd"
Expand Down
15 changes: 13 additions & 2 deletions stowaway.script
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
want_bin rsync
want_bin rsync
want_bin sfdisk
want_bin whiptail
want_bin partclone.btrfs
want_bin partclone.dd
want_bin partclone.exfat
want_bin partclone.extfs
want_bin partclone.fat
want_bin partclone.hfsp
want_bin partclone.ntfs
want_bin partclone.ntfsfixboot
want_bin partclone.restore
want_bin partclone.xfs
want_bin partclone.chkimg

want_module tg3
want_module igb
want_module e1000
want_module e1000e
want_module e1000
30 changes: 30 additions & 0 deletions udhcpc.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

case "$1" in
"deconfig")
ip l set dev "$interface" down
ip l set dev "$interface" up
;;
"renew")
ip a replace "$ip/$mask" dev "$interface"
echo "" > "/etc/resolv.conf"
for srv in $dns; do
printf "nameserver %s\n" "$srv" >> "/etc/resolv.conf"
done
for rtr in $router; do
ip r replace default via "$rtr" dev "$interface"
done
;;
"bound")
ip a add "$ip/$mask" dev "$interface"
for srv in $dns; do
printf "nameserver %s\n" "$srv" >> "/etc/resolv.conf"
done
for rtr in $router; do
ip r add default via "$rtr" dev "$interface"
done
;;
"nak")
printf "Failed to get a DHCP lease\n"
;;
esac

0 comments on commit f50f2c1

Please sign in to comment.