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" ]
23 # Otherwise, TFTP using an appropriate host. Start with the
27 # next, try the DHCP next-server-address
28 [ -z "$host" ] && host=${siaddr}
30 # finally, use the DHCP server we got this lease from:
31 [ -z "$host" ] && host=${serverid}
33 echo "tftp://$host/$file"
39 params="conf@${interface} method=dhcp"
42 mac=$(tr ':' '-' < /sys/class/$interface/address)
43 pb-event $params url=$basedir/01-$mac
45 # try decreasing fragments of IP lease
46 ip_hex=$(printf '%02X%02X%02X%02X' $(echo $ip | tr '.' ' '))
47 for i in $(seq 8 -1 1)
50 pb-event $params url=$basedir/$frag
54 pb-event $params url=$basedir/default
59 # Look for an explicit config file location in the DHCP config-file
61 if [ -n "${conffile}" ]
63 url=$(resolve_url ${conffile})
64 pb-event conf@${interface} url=$url method=dhcp
68 # Otherwise, we'll need the boot-file parameter. Looks like udhcpc
69 # will give us different names, depending if the parameter was in
70 # the header, or specified by options
71 [ -z "$bootfile" ] && bootfile=${boot_file}
78 # PXE behaviour is to download the config file based on a file
79 # structure relative to the pxelinux binary
81 [ -z "$file" ] && file=${boot_file}
88 # Finally, add an option for the boot_file parameter
89 k_server_ip=${rootpath%%:*}
90 k_root_dir=${rootpath#*:}
95 [ ${k_server_ip} != ${rootpath} ] || k_server_ip=${serverid}
96 args="root=/dev/nfs ip=any nfsroot=${k_server_ip}:${k_root_dir}"
99 pb-event add@${interface} \
101 image=tftp://${siaddr}/${boot_file} \
106 pb-event remove@${interface} name=netboot
120 printf "--- $1 ---\n" >> ${log}
122 printf "---------------\n" >> ${log}