TFTP boot path fix

Post there if you plan to contribute to this SystemCd
deterenkelt
Posts: 1
Joined: 18 May 2016, 22:14

TFTP boot path fix

Postby deterenkelt » 18 May 2016, 22:46

I’ve noticed that TFTP boot doesn’t actually work out of the box. Not only /etc/init.d/pxebootsrv lacks the corresponding lines to add the netboot= parameter, the init script cannot find sysrcd.dat even when netboot was manually added to the list of parameters. This happens because of a strange line in your sysresccd_stage1_tftp() – tftpurl gets the server address instead of an actual URL, if there’s no directories in between the address and the sysrcd.dat. I made some simulations

Code: Select all

$ t='tftp://10.9.8.7/top/kek/sysrcd.dat'; url=$(echo ${t} | sed 's!tftp://!!g'); declare -p url; dirnameurl=$(busybox dirname $url); declare -p dirnameurl; tftpurl=$(busybox dirname ${url} | sed -e 's![^/]*/!!'); declare -p tftpurl
declare -- url="10.9.8.7/top/kek/sysrcd.dat"
declare -- dirnameurl="10.9.8.7/top/kek"
declare -- tftpurl="top/kek"

$ t='tftp://10.9.8.7/sysrcd.dat'; url=$(echo ${t} | sed 's!tftp://!!g'); declare -p url; dirnameurl=$(busybox dirname $url); declare -p dirnameurl; tftpurl=$(busybox dirname ${url} | sed -e 's![^/]*/!!'); declare -p tftpurl
declare -- url="10.9.8.7/sysrcd.dat"
declare -- dirnameurl="10.9.8.7"
declare -- tftpurl="10.9.8.7"
And give you a patch:

Code: Select all

--- init        2016-05-19 01:31:55.239087990 +0300
+++ init.fixed  2016-05-19 01:31:26.673295061 +0300
@@ -690,7 +690,7 @@
 
     url="$(echo ${TFTPBOOT} | sed 's!tftp://!!g')"
     tftpip="${url%%/*}"
-    tftpurl=$(busybox dirname ${url} | sed -e 's![^/]*/!!')
+    tftpurl=$(echo "$url" | sed -r 's!^[^/]+/!/!;s!/[^/]+$!/!')
 
     # in any case sysrcd.dat is required
     FILENAMES="${LOOPDAT}"
It should be working.

Code: Select all

$ t='tftp://10.9.8.7/sysrcd.dat'; url=$(echo ${t} | sed 's!tftp://!!g'); declare -p url; dirnameurl=$(busybox dirname $url); declare -p dirnameurl; tftpurl=$(echo "$url" | sed -r 's!^[^/]+/!/!;s!/[^/]+$!/!'); declare -p tftpurl
declare -- url="10.9.8.7/sysrcd.dat"
declare -- tftpurl="/"

$ t='tftp://10.9.8.7/works/fine/sysrcd.dat'; url=$(echo ${t} | sed 's!tftp://!!g'); declare -p url; dirnameurl=$(busybox dirname $url); declare -p dirnameurl; tftpurl=$(echo "$url" | sed -r 's!^[^/]+/!/!;s!/[^/]+$!/!'); declare -p tftpurl
declare -- url="10.9.8.7/works/fine/sysrcd.dat"
declare -- tftpurl="/works/fine/"

Return to “Contributions”

Who is online

Users browsing this forum: No registered users and 1 guest