diff --git a/elements/ramdisk/binary-deps.d/ramdisk b/elements/ramdisk/binary-deps.d/ramdisk new file mode 100644 index 00000000..5d468f9b --- /dev/null +++ b/elements/ramdisk/binary-deps.d/ramdisk @@ -0,0 +1 @@ +dhclient diff --git a/elements/ramdisk/element-deps b/elements/ramdisk/element-deps new file mode 100644 index 00000000..ef25eec6 --- /dev/null +++ b/elements/ramdisk/element-deps @@ -0,0 +1 @@ +pkg-map diff --git a/elements/ramdisk/extra-data.d/scripts/init b/elements/ramdisk/extra-data.d/scripts/init index 2bba45c4..2f4eb9c0 100755 --- a/elements/ramdisk/extra-data.d/scripts/init +++ b/elements/ramdisk/extra-data.d/scripts/init @@ -34,10 +34,12 @@ mount -t proc proc /proc readonly _BOOTIF_=$(get_kernel_parameter BOOTIF) 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_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1) 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) diff --git a/elements/ramdisk/init.d/02-start-network b/elements/ramdisk/init.d/02-start-network index be5f7e87..94b352ae 100644 --- a/elements/ramdisk/init.d/02-start-network +++ b/elements/ramdisk/init.d/02-start-network @@ -26,20 +26,35 @@ if [ $rv -ne 0 ]; then troubleshoot fi fi -ifconfig "$BOOT_INTERFACE" "$BOOT_IP_ADDRESS" netmask "$BOOT_NETMASK" -route del default || true -route add default gw $BOOT_GATEWAY -echo "pinging to boot server $BOOT_SERVER" -w=30 -while [ $w -gt 0 ]; do - ping -c 5 -q "$BOOT_SERVER" > /dev/null - if [ $? -eq 0 ]; then - break +# 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" + route del default || true + route add default gw $BOOT_GATEWAY +else + dhclient -1 "$BOOT_INTERFACE" + if [[ $? == 2 ]]; then + echo "Error getting IP address for $BOOT_INTERFACE with MAC \ + $BOOT_MAC_ADDRESS" + troubleshoot fi - sleep 1 - w=`expr $w - 5` -done + + 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 echo "network ready" diff --git a/elements/ramdisk/install.d/20-install-dhcp-client b/elements/ramdisk/install.d/20-install-dhcp-client index 98fc31d6..f65ef3bf 100755 --- a/elements/ramdisk/install.d/20-install-dhcp-client +++ b/elements/ramdisk/install.d/20-install-dhcp-client @@ -2,6 +2,5 @@ set -eux set -o pipefail -if [ "opensuse" = "$DISTRO_NAME" ]; then - install-packages dhcp-client -fi +DHCP_CLIENT=$(pkg-map --element ramdisk dhcp_client) +install-packages $DHCP_CLIENT diff --git a/elements/ramdisk/pkg-map b/elements/ramdisk/pkg-map new file mode 100644 index 00000000..fa51ee75 --- /dev/null +++ b/elements/ramdisk/pkg-map @@ -0,0 +1,10 @@ +{ + "family":{ + "debian":{ + "dhcp_client":"isc-dhcp-client" + } + }, + "default":{ + "dhcp_client":"dhclient" + } +} \ No newline at end of file