Score:0

During which dracut hook can a PXE client rename predictable interfaces names with a udev rule?

jp flag

tl;dr: During load of an initramfs (execution of dracut modules) on a PXE client, I need to rename the kernel-given (predictable) interface names (right now they're unpredictable ethX names). This way, the PXE client will always boot from a predictably named interface. Currently I'm reading the hardware info with dmesg during the dracut cmdline hook. Could I cat a udev rule to /usr/lib/udev/rules.d/ here so that the system could rename the interfaces when dracut later triggers udev?

Basically I have this in the dracut cmdline hook:

# First read hardware provided
if dmesg | grep -q "SOME_BOARD_NAME"; then
    root=$(echo "$root" | sed -e 's/PLACEHOLDER_FILE/SOME_ROOTFS.sqsh/')
    # Additionally, some udev rules are needed specific to this board.
#    mkdir -p /etc/udev/rules.d
#    echo "install these boards' rules!\n"
#    echo << EOF > /etc/udev/rules.d/70-persistent-net.rules
#SUBSYSTEM=="net", DEVPATH="/devices/pci*/*1c.0/0000:07:00.0/net/*", NAME="eth0"
#SUBSYSTEM=="net", DEVPATH="/devices/pci*/*01.1/0000:05:00.0/net/*", NAME="eth1"
#SUBSYSTEM=="net", DEVPATH="/devices/pci*/*01.1/0000:05:00.1/net/*", NAME="eth2"
#EOF
elif dmesg | grep -q "SOME_OTHER_BOARD_NAME"; then
    root=$(echo "$root" | sed -e 's/PLACEHOLDER_FILE/SOME_OTHER_ROOTFS.sqsh/')
    echo "install other board-specific rules!\n"
#    mkdir -p /etc/udev/rules.d
#    echo << EOF > /etc/udev/rules.d/70-persistent-net.rules
#SUBSYSTEM=="net", DEVPATH="/devices/pci*/*1c.5/0000:09:00.0/net/*", NAME="eth0"
#SUBSYSTEM=="net", DEVPATH="/devices/pci*/*02.2/0000:02:00.0/net/*", NAME="eth1"
#SUBSYSTEM=="net", DEVPATH="/devices/pci*/*02.2/0000:02:00.1/net/*", NAME="eth2"
#EOF
else
    warn "Did not detect either board - defaulting to SOME_OTHER_ROOTFS.sqsh"
    root=$(echo "$root" | sed -e 's/PLACEHOLDER_FILE/SOME_OTHER_ROOTFS.sqsh/')
fi

More info: My team and I have a single board computer that PXE boots from an external server. This follows a sequence of:

  1. The SBC pulls an initramfs and loads that.
  2. The initramfs executes a dracut module that reads the hardware info of the SBC (during the dracut hook "cmdline").
  3. The SBC pulls down a particular root filesystem depending on its hardware.

Unfortunately, the old ethX (unpredictable) interface names sometimes cause the SBC to pull down the root filesystem over the wrong network interface.

My plan is to remove net.ifnames=0 and biosdevname=0 from the kernel command line used to PXE boot (step 1). Then after the kernel has assigned predictable names, I want to extend the dracut module to add udev rules to rename them to the old names. I'm hoping when dracut triggers udev, the SBC will then always pull the root filesystem over the correct interface.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.