# Initramfs and consistent naming of Network interfaces

## redcap

Hi there,

a few days ago I installed gentoo on a new box that will act as a small server 

at my apartment. Since I have an encrypted root fs and seperate /usr I need 

an initramfs. Most of the time I will unlock the root fs remotely over ssh, which is

why I use an initramfs that [/list]contains dropbear.

First initramfs' init script (based on http://whitehathouston.com/documentation/gentoo/initramfs_howto.htm) :

```

#!/bin/busybox sh

# dropping to a rescue shell lets you attempt to mount, cryptsetup, etc, by

# hand at least. Below, I call the rescue_shell function if mounting root fails.

# It must be defined prior to its call, so we do it up top. 

rescue_shell() {

        echo "Something went wrong. Dropping you to a shell."

                busybox --install -s

        exec /bin/sh

}

# temporarily mount proc and sys

mount -t proc none /proc

mount -t sysfs none /sys

mount -t devtmpfs none /dev #only do this if you've built devtmpfs support into your kernel

# bring up network interface

ifconfig eth0 192.168.2.102

sleep 3

# start ssh server

/usr/sbin/dropbear -FEjkm 

# activate logical volumes

lvm vgscan --mknodes

lvm lvchange -aly lvmpoolssdvolg

# mount fss 

mount -o ro /dev/mapper/lvmpoolssdvolg-volg--root /mnt/root || rescue_shell

mount -o ro /dev/mapper/lvmpoolssdvolg-volg--usr /mnt/root/usr || rescue_shell

mount -o ro /dev/sda3 /mnt/root/var || rescue_shell

#clean up. 

umount /proc

umount /sys

umount /dev

# boot

exec switch_root /mnt/root /sbin/init

```

the system has only one network card, which is named eth0 at the time of execution of the init-script. If the boot

process is finished, the interface is still named eth0.

I also have a second initramfs, without dropbear, suitable for local access to the system. The init-script looks like this:

```

#!/bin/busybox sh

# dropping to a rescue shell lets you attempt to mount, cryptsetup, etc, by

# hand at least. Below, I call the rescue_shell function if mounting root fails.

# It must be defined prior to its call, so we do it up top. 

rescue_shell() {

        echo "Something went wrong. Dropping you to a shell."

                busybox --install -s

        exec /bin/sh

}

# temporarily mount proc and sys

mount -t proc none /proc

mount -t sysfs none /sys

mount -t devtmpfs none /dev #only do this if you've built devtmpfs support into your kernel

sleep 3

# decrypt 

cryptsetup -T 5 --allow-discards luksOpen /dev/sdb2 lvmpoolssd 

# activat logical volumens

lvm vgscan --mknodes

lvm lvchange -aly lvmpoolssdvolg

# mount rfss

mount -o ro /dev/mapper/lvmpoolssdvolg-volg--root /mnt/root || rescue_shell

mount -o ro /dev/mapper/lvmpoolssdvolg-volg--usr /mnt/root/usr || rescue_shell

mount -o ro /dev/sda3 /mnt/root/var || rescue_shell

#clean up. 

umount /proc

umount /sys

umount /dev

# boot 

exec switch_root /mnt/root /sbin/init

```

Now, if I boot via the second initramfs the network interface is named enp2s0. This behaviour 

is quite annoying, since I have to configure the system taking into account  two different network interface names.

Moreover, since I work with static IPs, I have to assigns different IPs to the the network interface based on 

the name. In other words, something like

```

config_eth0="192.168.2.103 netmask 255.255.255.0"

config_enp2s0="192.168.2.103 netmask 255.255.255.0"

```

won't work (openrc will complain about assigning one address to two different interfaces). 

Right now I'm wondering about the most reasonable way to solve this issue. The following ideas

came to my mind

 Add udev to first initramfs (No idea on how to do this... doesn't seem to be that easy)

 Disable persistent naming of network interfaces as indicated here: http://wiki.gentoo.org/wiki/Udev/upgrade

 Somehow force the kernel to rename eth0 to enp2s0 after the switch from the first initramfs to the real init (don't know if this is possible)

 Any other idea that I could not come up with ....

I'd be very grateful for any comments and suggestions for the most reasonable course of action in this situation. Thanks in advance for any input.

----------

## Hu

If you have only one NIC, then the udev renaming behavior is worse than useless and should be disabled.

----------

## redcap

Thanks... will do so  :Smile: 

----------

## yzh

I had the similiar problem: https://forums.gentoo.org/viewtopic-t-962294-highlight-initramfs.html

conclusion is that gentoo's initramfs uses mdev and not udev.

I think you could also build a custom initramfs using "dracut" which has support for udev and persistent interface naming.

----------

## Aiken

Personally I would disable the renaming. With the single nic you will have eth0 every time. With udev depending on what is done with the computer you can not be confident the interface name will be the same from one boot to the next.

----------

