Epics@GSI Webhome

Tips Linux Dhclient Dynamic Mount Point


Using dhclient-script's exit hooks scripts allows to set a mount point depending on the network environment, in this example for the HADES setup.

Based on the articles: and its own origin

dhclient and its scripting capabilities on enter and exit hooks allows to react on dynamic network environments.

Provided you have root privileges this can be achieved by creating a script file mount_var_diskless created in /etc/dhcp/dhclient-exit-hooks.d/ (on Debian), which is sourced by dhclient after having updated/received its DHCP informations.

# Filename:     /etc/dhcp/dhclient-exit-hooks.d/mount_var_diskless
# Purpose:      Used by dhclient-script to set mount HADES's var/diskless filesystem 
#               from either the local net (preferred) or the GSI network

# Do not update hostname for virtual machine IP assignments
if [ "$interface" != "eth0" ] && [ "$interface" != "eth1" ] && [ "$interface" != "wlan0" ]

if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]


echo dhclient-exit-hooks.d/mount_var_diskless: new domain-name-servers: $new_domain_name_servers 

echo "$new_domain_name_servers" | grep -q $var_diskless_hades && var_diskless_addr=$var_diskless_hades || var_diskless_addr=$var_diskless_gsi

#clean up, but only different mounts
grep -v "$var_diskless_addr:$var_diskless_path" /etc/mtab | grep -q "$var_diskless_mount" && umount $var_diskless_mount 

[ -d "$var_diskless_mount" ] || mkdir -p $var_diskless_mount
grep "$var_diskless_addr:$var_diskless_path" /etc/mtab | grep -q "$var_diskless_mount" || mount $var_diskless_addr:$var_diskless_path $var_diskless_mount

echo dhclient-exit-hooks.d/mount_var_diskless: mounted $var_diskless_addr:$var_diskless_path

unset var_diskless_hades 
unset var_diskless_gsi 
unset var_diskless_path 
unset var_diskless_mount

Finally make sure the file is readable:
chmod a+r /etc/dhcp/dhclient-exit-hooks.d/mount_var_diskless

Local testing at the prompt:
dhclient -v

-- PeterZumbruch - 21 Oct 2013
-- PeterZumbruch - 2013-10-21
Topic revision: r3 - 2013-10-21, PeterZumbruch
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)