Multi purpose bootable usb stick : how to auto configure network.

Hello.
I have a bootable usb key.
I have installed 15.1 on it in a way where the usb key was the only computer drive.
I can boot from that usb key on any computer by accessing the bios during power up; then choose the usb key to boot on.
Every things is ok but I need help to auto configure network so that access to internet is enabled.

The current network configuration on the USB stick is wicked and perhaps is not the best choice.

[size=2]PREAMBLE
[/size]
I decide to name the network connection ‘eth0_usb’ for Ethernet and ‘wifi0_usb’ for Wifi.
That give the name ‘ifcfg-eth0_usb’ and ‘ifcfg-wifi0_usb’ for the configuration files.

The following configuration files contain the data that correspond to my wishes.
/etc/sysconfig/network/config
/etc/sysconfig/network/dhcp
/etc/sysconfig/network/ifcfg-eth0_usb
/etc/sysconfig/network/ifcfg-wifi0_usb
/etc/hostname
/etc/resolv.conf
/etc/sysctl.confdefinition overload
/etc/udev/rules.d/70-persistent-net.rules

After googleing I decide to add the following parameters to the kernel cmdline to help/prevent naming the card ( as far i have understood ;))

 net.ifnames=0 biosdevname=0 

What I have understood is that the file name of ‘/etc/sysconfig/network/icfg-<DEVICE_NAME>’ must meet <DEVICE_NAME> in ‘/etc/udev/rules.d/70-persistent-net.rules’ with the corresponding hardware address as :

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="12:34:56:78:9a:bc", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="<DEVICE_NAME>"

Then I modify ‘/etc/udev/rules.d/70-persistent-net.rules’ to reflect different harware on 3 computers :

# This file was automatically generated by the /usr/lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device : lan device : COMPUTER1
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="12:34:56:78:9a:bc", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0_usb"
# PCI device : wlan device : COMPUTER1
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="34:56:78:9a:bc:12", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0_usb"

# PCI device : lan device : COMPUTER2
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="56:78:9a:bc:12:34", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0_usb"
# PCI device : wlan device : COMPUTER2
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="78:9a:bc:12:34:56", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0_usb"

# # # PCI device 0x8086:0x15a1 (e1000e)
# PCI device : lan device : COMPUTER3 - NO WIFI
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="9a:bc:12:34:56:78", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0_usb"

THE PROBLEMS

  1. That works only ounce to get connection to internet.
  1. The file ‘/etc/udev/rules.d/70-persistent-net.rules’ is modified by the system.
    I did not get connection to internet

Ex 1 : some lines are merged, some lines deleted, some lines added

# You can modify it,as long as you keep each rule on a single
# line,and change only the value of the NAME= key.
# PCI device : lan device : COMPUTER1
# PCI device : wlan device : COMPUTER1                           
# PCI device : lan device : COMPUTER2
# PCI device : wlan device : COMPUTER2
# PCI device 0x8086:0x15a1 (e1000e)  initial value : PCI device : lan device : COMPUTER3
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="56:78:9a:bc:12:34", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="eth0_usb"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="78:9a:bc:12:34:56", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="wlan0_usb"

# PCI device 0x1969:0x10a1 (alx)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="9a:bc:12:34:56:78", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Ex 2 : Restarting with my initial config file and booting on the second computer :

# This file was automatically generated by the /usr/lib/udev/write_net_rules
# program,run by the persistent-net-generator.rules rules file.
#
# You can modify it,as long as you keep each rule on a single
# line,and change only the value of the NAME= key.
# PCI device 0x1969:0x1083 (atl1c)
# PCI device 0x168c:0x0032 (ath9k)
# PCI device 0x168c:0x0032 (ath9k)
# USB device 0x0b95:0x1790 (usb)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="ath9k", ATTR{dev_id}=="0x0", ATTR{type}=="1", ATTR{address}=="12:34:56:78:9a:bc", NAME="gvw_wifi0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="34:56:78:9a:bc:12", ATTR{dev_id}=="0x0", ATTR{type}=="1", ATTR{address}=="30:85:a9:28:16:f9", NAME="gvw_eth0"

# USB device 0x0b95:0x1790 (usb)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="**00:0e:c6:b9:7f:7a**", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="usb_eth0"

This address does not exists : 00:0e:c6:b9:7f:7a

  1. If I make an empty file '/etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /usr/lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

the system update this file but I can connect to internet from this computeur but not from another one.

# This file was automatically generated by the /usr/lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x1969:0x10a1 (alx)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="xx:xx:xx:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0_usb"

# PCI device 0x168c:0x0034 (ath9k)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="yy:yy:yy:yy:yy:yy", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0_usb"

THE CURRENT METHODE
Any way this methode does not work on an unknown computer because I will not know the hardware addresses.

THE QUESTION
How to auto configure the network during the boot up sequence on any computer.

Any help is welcome

Each computer receives an ip address by local router.

I think you’re barking up the wrong tree. The Live images these days are persistent ( they create an overlayfs ), and can be updated, upgraded and extended with your choice of software. AFAIK they default to networkmanager. This means, that on every first occasion you will have to establish the connection, but the system will remember them. I do this with a USB3.1 SSD of 32GB and it has been working fine more than a year now. Easypeasy.

I can tell you what I am doing. You will have to decide for yourself whether that is what you want.

I have a USB drive – actually an old hard drive that was once used for backups, back when 160G was big enough for that. It has Leap 15.1 installed. I’m using it as a tool that I can move between computers. I can also boot it on KVM virtual machines. And I actually set it up on a virtual machine.

I tried “wicked” for the network. That worked well on virtual machines, because they all had the same kind of virtual network device. But to use on a physical machine, I would have to first reconfigure the network.

So I switched to using NetworkManager. And that seems to use any ethernet card that it finds. So it works on all machines.

I did want to make a config change. So NetworkManager then saves a connection definition file in “/etc/NetworkManager/system-connections”. But that file has the MAC address of the ethernet card, so now it only works on one machine. I then edited that connection file, and removed all lines that are specific to the device (mostly the MAC address). And now it works on all machines again.

I did set “/etc/hostname” to contain just “localhost”. So, when booted, it usually gets the name “localhost”. I did that because, according to the documentation, “NetworkManager” does not send the hostname to the DHCP server, if that hostname is “localhost”. And it is best to not confuse the DHCP server (in my home router).

I do have it configured to get hostname via DHCP. But that rarely works, so it usually boots as “localhost.localdomain”.

I do not run an SSH server on this USB machine. That would confuse things, since the appropriate host key to use would depend on which machine I boot it on.

While I’m about it, I will comment on booting.

I used GPT for partitioning. I did create an EFI partition, which I mount at “/boot/efi”. That is formatted as vfat (FAT32).

I installed on a virtual machine using legacy booting. I set it to boot from the MBR (and I do have a bios_boot partition).

I also wanted it to be bootable with UEFI and secure-boot. So I installed support for that with:

shim-install --no-nvram --removable

However, secure-boot requires using “linuxefi” and “initrdefi” in the “grub.cfg”. So I created a file “grub.altcfg” in “/boot/grub2” by coping “grub.cfg” and then changing “linux” to “linuxefi” and “initrd” to “initrdefi” in “grub.altcfg”. I actually use a “sed” command for that. And I created a “Makefile” to do that. So whenever “grub.cfg” has been update, I can run “make” to update “grub.altcfg”.

Finally, “/boot/efi/EFI/Boot” (when booted to the USB), I edit the small file “grub.cfg”. And where that says:

source "${prefix}/grub.cfg"

I change that to

source "${prefix}/grub.altcfg"

That allows it to boot on a machine (or a virtual machine) where secure-boot is enabled.

If I correctly understand what you mean - OpenSSH supports signed keys and you can configure client to trust any host key signed by known certificate. This eliminates problem of multiple host keys for the same IP (same host key from different IP). Of course it works only if clients are under your control.

Fair enough.

I have never needed to ssh into a system booted to the USB drive. I do sometimes ssh out.

Same here. My stick is openSUSE_Leap_15.1_KDE_Live:

erlangen:~ # fdisk -l /dev/sdd
Disk /dev/sdd: 59.64 GiB, 64023257088 bytes, 125045424 sectors
Disk model: Extreme         
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x54907881

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sdd1  *          64   1824767  1824704  891M 17 Hidden HPFS/NTFS
/dev/sdd2        1824768   1855487    30720   15M ef EFI (FAT-12/16/32)
/dev/sdd3        1855488  64770047 62914560   30G 83 Linux
/dev/sdd4       64770048 125045423 60275376 28.8G 83 Linux
erlangen:~ # 

I keep it up to date by running zypper up. Enabled persistent journalling, shrank cow on sdd3 and added sdd4 with btrfs, just in case of disk full on root btrfs.

I have try to use networkmanager and it works like a charm.

Thank you very much

I have tried only on one computer with networkmanager.
I have to test with other.

I’m keeping your post close.

Thank you very much