View previous topic :: View next topic |
Author |
Message |
redcap n00b
Joined: 10 Jul 2010 Posts: 38
|
Posted: Sun Jun 30, 2013 6:25 pm Post subject: Initramfs and consistent naming of Network interfaces |
|
|
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 |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21635
|
Posted: Sun Jun 30, 2013 7:00 pm Post subject: |
|
|
If you have only one NIC, then the udev renaming behavior is worse than useless and should be disabled. |
|
Back to top |
|
|
redcap n00b
Joined: 10 Jul 2010 Posts: 38
|
Posted: Mon Jul 01, 2013 6:32 pm Post subject: |
|
|
Thanks... will do so |
|
Back to top |
|
|
yzh n00b
Joined: 25 Feb 2011 Posts: 53
|
Posted: Tue Jul 02, 2013 12:38 pm Post subject: Re: Initramfs and consistent naming of Network interfaces |
|
|
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 |
|
|
Aiken Apprentice
Joined: 22 Jan 2003 Posts: 239 Location: Toowoomba/Australia
|
Posted: Tue Jul 02, 2013 10:27 pm Post subject: |
|
|
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 |
|
|
|
|
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
|
|