Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions custom_files/disable_disconnected_nics.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Disable disconnected network interfaces on boot
After=network.target

[Service]
Type=oneshot
ExecStart=/root/scripts/disable_disconnected_nics.sh

[Install]
WantedBy=multi-user.target
11 changes: 11 additions & 0 deletions custom_files/disable_disconnected_nics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Get a list of all network interfaces (excluding loopback)
interfaces=$(ls /sys/class/net | grep -v lo)

for iface in $interfaces; do
# Check if the interface is disconnected (carrier detected)
if [[ -f "/sys/class/net/$iface/carrier" ]] && [[ "$(cat /sys/class/net/$iface/carrier)" == "0" ]]; then
ip link set dev $iface down
fi
done
10 changes: 6 additions & 4 deletions scripts/generate-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ fi
cp -r /custom_files/run_bootfile_dev.sh root/scripts
cp -r /custom_files/run_bootfile_prod.sh root/scripts
cp -r /custom_files/create-users.sh root/scripts
cp -r /custom_files/disable_disconnected_nics.sh root/scripts
cp -r /custom_files/disable_disconnected_nics.service usr/lib/systemd/system/
if [ -n "$prod_flag" ]; then
cp -r /custom_files/run_bootfile_prod.service usr/lib/systemd/system/run_bootfile.service
else
Expand Down Expand Up @@ -155,7 +157,6 @@ else
mkdir -p afs/slac.stanford.edu
fi
if [ -d "afs/slac.stanford.edu" ]; then
# echo "172.23.66.102:/afs/slac.stanford.edu /afs/slac.stanford.edu nfs _netdev,auto,x-systemd.automount,x-systemd.mount-timeout=5min,x-systemd.after=sys-subsystem-net-devices-enp7s0.device,retry=10,timeo=14 0 0" > etc/fstab
echo "s3dflclsdevnfs001:/sdf/group/ad/transition/afs/slac.stanford.edu /afs/slac.stanford.edu nfs _netdev,auto,x-systemd.automount,x-systemd.mount-timeout=5min,x-systemd.after=sys-subsystem-net-devices-enp7s0.device,retry=10,timeo=14 0 0" > etc/fstab
fi
fi
Expand All @@ -170,17 +171,18 @@ sed -i "s/#DefaultLimitRTPRIO=/DefaultLimitRTPRIO=infinity/g" etc/systemd/system
sed -i "s/#DefaultLimitMEMLOCK=/DefaultLimitMEMLOCK=infinity/g" etc/systemd/user.conf
sed -i "s/#DefaultLimitRTPRIO=/DefaultLimitRTPRIO=infinity/g" etc/systemd/user.conf


# chroot, set a blank password to root, and create the laci account. laci
# account must have UID 8412 and be part of an lcls group with GID 2211.
# The IDs are important for accessing NFS directories.
# Deactivate all NICs that are disconnected from a network.
# Activate NTP, generate required locales
chroot . \
bash -c '\
/root/scripts/create-users.sh && \
systemctl enable /usr/lib/systemd/system/run_bootfile.service && \
systemctl enable ntpd && \
localedef -i en_US -f UTF-8 en_US.utf8 && \
systemctl enable ntpd && \
systemctl enable disable_disconnected_nics.service && \
localedef -i en_US -f UTF-8 en_US.utf8 && \
exit \
'

Expand Down