3 # Petitboot udhcpc user script. Should be run by udhcpc when
4 # there is a change in the dhcp configuration. For more info
5 # see the udhcpc man page and the Linux kernel source file
6 # Documentation/filesystems/nfsroot.txt.
9 PBOOT_USER_EVENT_SOCKET="/tmp/petitboot.ev"
10 log="/var/log/petitboot/pb-udhcpc.log"
17 if [ "$tmp" != "$file" ]
22 # Otherwise, TFTP using an appropriate host. Start with the
26 # next, try the DHCP next-server-address
27 [ -z "$host" ] && host=${siaddr}
29 # finally, use the DHCP server we got this lease from:
30 [ -z "$host" ] && host=${serverid}
32 echo "tftp://$host/$file"
38 params="conf@/net/${interface} method=dhcp"
41 mac=$(cat /sys/class/net/$interface/address)
42 pb-event $params url=$basedir/$mac
44 # try decreasing fragments of IP lease
45 ip_hex=$(printf '%02X%02X%02X%02X' $(echo $ip | tr '.' ' '))
46 for i in $(seq 8 -1 1)
49 pb-event $params url=$basedir/$frag
53 pb-event $params url=$basedir/default
58 # Look for an explicit config file location in the DHCP config-file
62 url=$(resolve_url ${conffile})
63 pb-event conf@/net/${interface} url=$url method=dhcp
67 # Otherwise, we'll need the boot-file parameter. Looks like udhcpc
68 # will give us different names, depending if the parameter was in
69 # the header, or specified by options
70 [ -n "$bootfile" ] && bootfile=${boot_file}
77 # PXE behaviour is to download the config file based on a file
78 # structure relative to the pxelinux binary
80 [ -z "$file" ] && file=${boot_file}
87 # Finally, add an option for the boot_file parameter
88 k_server_ip=${rootpath%%:*}
89 k_root_dir=${rootpath#*:}
94 [ ${k_server_ip} != ${rootpath} ] || k_server_ip=${serverid}
95 args="root=/dev/nfs ip=any nfsroot=${k_server_ip}:${k_root_dir}"
98 pb-event add@/net/${interface} \
100 image=tftp://${siaddr}/${boot_file} \
105 pb-event remove@/net/${interface} name=netboot
119 printf "--- $1 ---\n" >> ${log}
121 printf "---------------\n" >> ${log}