Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Initramfs and consistent naming of Network interfaces
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
redcap
n00b
n00b


Joined: 10 Jul 2010
Posts: 38

PostPosted: Sun Jun 30, 2013 6:25 pm    Post subject: Initramfs and consistent naming of Network interfaces Reply with quote

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) :
Code:

#!/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:


Code:

#!/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

Code:

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.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21635

PostPosted: Sun Jun 30, 2013 7:00 pm    Post subject: Reply with quote

If you have only one NIC, then the udev renaming behavior is worse than useless and should be disabled.
Back to top
View user's profile Send private message
redcap
n00b
n00b


Joined: 10 Jul 2010
Posts: 38

PostPosted: Mon Jul 01, 2013 6:32 pm    Post subject: Reply with quote

Thanks... will do so :-)
Back to top
View user's profile Send private message
yzh
n00b
n00b


Joined: 25 Feb 2011
Posts: 53

PostPosted: Tue Jul 02, 2013 12:38 pm    Post subject: Re: Initramfs and consistent naming of Network interfaces Reply with quote

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.
Back to top
View user's profile Send private message
Aiken
Apprentice
Apprentice


Joined: 22 Jan 2003
Posts: 239
Location: Toowoomba/Australia

PostPosted: Tue Jul 02, 2013 10:27 pm    Post subject: Reply with quote

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.
_________________
Beware the grue.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum