Add dhcp support for ramdisk element.
This change adds support for retrieving the IP through DHCP if 'ip' was not provided as a kernel command-line argument by pxelinux. This is used when the kernel/ramdisk is booted by virtual media. Change-Id: I1097ce5b56ad40f2d6dc3181681d54f924ec7145 Closes-Bug: #1321563
This commit is contained in:
parent
3cdfd9565e
commit
099493b62c
1
elements/ramdisk/binary-deps.d/ramdisk
Normal file
1
elements/ramdisk/binary-deps.d/ramdisk
Normal file
@ -0,0 +1 @@
|
|||||||
|
dhclient
|
1
elements/ramdisk/element-deps
Normal file
1
elements/ramdisk/element-deps
Normal file
@ -0,0 +1 @@
|
|||||||
|
pkg-map
|
@ -40,10 +40,12 @@ mount -t proc proc /proc
|
|||||||
readonly _BOOTIF_=$(get_kernel_parameter BOOTIF)
|
readonly _BOOTIF_=$(get_kernel_parameter BOOTIF)
|
||||||
readonly _IP_=$(get_kernel_parameter ip)
|
readonly _IP_=$(get_kernel_parameter ip)
|
||||||
readonly BOOT_MAC_ADDRESS=$(echo "$_BOOTIF_" | sed -e "s/-/:/g" | sed -e "s/^01://g" | tr 'a-f' 'A-F')
|
readonly BOOT_MAC_ADDRESS=$(echo "$_BOOTIF_" | sed -e "s/-/:/g" | sed -e "s/^01://g" | tr 'a-f' 'A-F')
|
||||||
readonly BOOT_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1)
|
|
||||||
readonly BOOT_SERVER=$(echo "$_IP_" | cut -d':' -f2)
|
readonly BOOT_SERVER=$(echo "$_IP_" | cut -d':' -f2)
|
||||||
readonly BOOT_NETMASK=$(echo "$_IP_" | cut -d':' -f4)
|
|
||||||
readonly BOOT_GATEWAY=$(echo "$_IP_" | cut -d':' -f3)
|
# IP address and other parameters may be set later in the init script
|
||||||
|
BOOT_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1)
|
||||||
|
BOOT_NETMASK=$(echo "$_IP_" | cut -d':' -f4)
|
||||||
|
BOOT_GATEWAY=$(echo "$_IP_" | cut -d':' -f3)
|
||||||
|
|
||||||
readonly DISK=$(get_kernel_parameter disk)
|
readonly DISK=$(get_kernel_parameter disk)
|
||||||
|
|
||||||
|
@ -26,20 +26,35 @@ if [ $rv -ne 0 ]; then
|
|||||||
troubleshoot
|
troubleshoot
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if boot IP address was specific or retrieve from DHCP
|
||||||
|
if [ -n "$BOOT_IP_ADDRESS" ]; then
|
||||||
ifconfig "$BOOT_INTERFACE" "$BOOT_IP_ADDRESS" netmask "$BOOT_NETMASK"
|
ifconfig "$BOOT_INTERFACE" "$BOOT_IP_ADDRESS" netmask "$BOOT_NETMASK"
|
||||||
route del default || true
|
route del default || true
|
||||||
route add default gw $BOOT_GATEWAY
|
route add default gw $BOOT_GATEWAY
|
||||||
|
else
|
||||||
echo "pinging to boot server $BOOT_SERVER"
|
dhclient -1 "$BOOT_INTERFACE"
|
||||||
w=30
|
if [[ $? == 2 ]]; then
|
||||||
while [ $w -gt 0 ]; do
|
echo "Error getting IP address for $BOOT_INTERFACE with MAC \
|
||||||
ping -c 5 -q "$BOOT_SERVER" > /dev/null
|
$BOOT_MAC_ADDRESS"
|
||||||
if [ $? -eq 0 ]; then
|
troubleshoot
|
||||||
break
|
fi
|
||||||
|
|
||||||
|
BOOT_IP_ADDRESS=$(ifconfig "$BOOT_INTERFACE" | grep 'inet addr:' | \
|
||||||
|
cut -d: -f2 | awk '{ print $1}')
|
||||||
|
BOOT_NETMASK=$(ifconfig "$BOOT_INTERFACE" | grep 'Mask:' | cut -d':' -f4)
|
||||||
|
BOOT_GATEWAY=$(route -n | grep "$BOOT_INTERFACE" | grep '^0.0.0.0' | \
|
||||||
|
awk '{print $2}')
|
||||||
|
echo "obtained the following from dhcp: "
|
||||||
|
echo " ip address = $BOOT_IP_ADDRESS"
|
||||||
|
echo " netmask = $BOOT_NETMASK"
|
||||||
|
echo " gateway = $BOOT_GATEWAY"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$BOOT_SERVER" ]; then
|
||||||
|
echo "pinging to boot server $BOOT_SERVER"
|
||||||
|
wait_for 6 1 ping -c 5 -q "$BOOT_SERVER" > /dev/null
|
||||||
fi
|
fi
|
||||||
sleep 1
|
|
||||||
w=`expr $w - 5`
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "network ready"
|
echo "network ready"
|
||||||
|
|
||||||
|
@ -2,6 +2,5 @@
|
|||||||
set -eux
|
set -eux
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
if [ "opensuse" = "$DISTRO_NAME" ]; then
|
DHCP_CLIENT=$(pkg-map --element ramdisk dhcp_client)
|
||||||
install-packages dhcp-client
|
install-packages $DHCP_CLIENT
|
||||||
fi
|
|
||||||
|
10
elements/ramdisk/pkg-map
Normal file
10
elements/ramdisk/pkg-map
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"family":{
|
||||||
|
"debian":{
|
||||||
|
"dhcp_client":"isc-dhcp-client"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default":{
|
||||||
|
"dhcp_client":"dhclient"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user