From 9166b6bbd5031f8e85a4345d7d6024392e8e0332 Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Fri, 10 Sep 2021 12:48:15 +0800 Subject: [PATCH] Make network interface names predictable Signed-off-by: Kiefer Chang --- package/harvester-os/Dockerfile | 2 ++ .../harvester-os/files/etc/cos/bootargs.cfg | 4 ++-- .../files/system/oem/90_network.yaml | 2 +- .../iso/boot/syslinux/syslinux.cfg | 20 ++++++++++++++++++ pkg/config/cos.go | 21 ++++++++----------- pkg/console/install_panels.go | 2 +- 6 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 package/harvester-os/iso/boot/syslinux/syslinux.cfg diff --git a/package/harvester-os/Dockerfile b/package/harvester-os/Dockerfile index 74e11976b..de233d166 100644 --- a/package/harvester-os/Dockerfile +++ b/package/harvester-os/Dockerfile @@ -6,6 +6,8 @@ RUN curl -sfL https://github.com/rancher/wharfie/releases/latest/download/wharfi COPY files/ / RUN chmod 0600 /system/oem/* +RUN rm -f /system/oem/05_network.yaml + ARG HARVESTER_INSTALLER_VERSION RUN echo GRUB_ENTRY_NAME="\"Harvester $HARVESTER_INSTALLER_VERSION\"" >> /etc/os-release diff --git a/package/harvester-os/files/etc/cos/bootargs.cfg b/package/harvester-os/files/etc/cos/bootargs.cfg index 4d86ff6ed..587f24898 100644 --- a/package/harvester-os/files/etc/cos/bootargs.cfg +++ b/package/harvester-os/files/etc/cos/bootargs.cfg @@ -1,9 +1,9 @@ set console_params="console=tty1" set kernel=/boot/vmlinuz if [ -n "$recoverylabel" ]; then - set kernelcmd="$console_params root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5" + set kernelcmd="$console_params root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5 net.ifnames=1" else - set kernelcmd="$console_params root=LABEL=$label cos-img/filename=$img panic=5" + set kernelcmd="$console_params root=LABEL=$label cos-img/filename=$img panic=5 net.ifnames=1" fi set initramfs=/boot/initrd diff --git a/package/harvester-os/files/system/oem/90_network.yaml b/package/harvester-os/files/system/oem/90_network.yaml index 1f7fce11c..92e1c79d4 100644 --- a/package/harvester-os/files/system/oem/90_network.yaml +++ b/package/harvester-os/files/system/oem/90_network.yaml @@ -3,7 +3,7 @@ stages: initramfs: - commands: - | - for i in /sys/class/net/eth*; do + for i in /sys/class/net/{eth*,en*,ib*}; do [ -e $i ] || continue ip link set $(basename $i) up; done diff --git a/package/harvester-os/iso/boot/syslinux/syslinux.cfg b/package/harvester-os/iso/boot/syslinux/syslinux.cfg new file mode 100644 index 000000000..b55a630a6 --- /dev/null +++ b/package/harvester-os/iso/boot/syslinux/syslinux.cfg @@ -0,0 +1,20 @@ +SERIAL 0 +PROMPT 1 +TIMEOUT 50 +DEFAULT vga + +SAY +SAY ################################################################## +SAY # # +SAY # Press to boot HarvesterOS Live or wait 5 seconds. # +SAY # # +SAY # Press to view available boot entries or enter Syslinux # +SAY # commands directly. # +SAY # # +SAY ################################################################## +SAY + +LABEL vga + LINUX /boot/kernel.xz + APPEND cdroot root=live:CDLABEL=COS_LIVE rd.live.dir=/ rd.live.squashimg=rootfs.squashfs console=tty1 console=ttyS0 rd.cos.disable net.ifnames=1 + INITRD /boot/rootfs.xz diff --git a/pkg/config/cos.go b/pkg/config/cos.go index 51dfccef1..587891c33 100644 --- a/pkg/config/cos.go +++ b/pkg/config/cos.go @@ -11,10 +11,10 @@ import ( ) const ( - cosLoginUser = "rancher" + cosLoginUser = "rancher" manifestsDirectory = "/var/lib/rancher/rke2/server/manifests/" - canalConfig = "rke2-canal-config.yaml" - harvesterConfig = "harvester-config.yaml" + canalConfig = "rke2-canal-config.yaml" + harvesterConfig = "harvester-config.yaml" ) var ( @@ -29,9 +29,6 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) { return nil, err } - preStage := yipSchema.Stage{} - preStage.Commands = append(preStage.Commands, "rm -f /etc/sysconfig/network/ifcfg-eth0") - initramfs := yipSchema.Stage{ SSHKeys: make(map[string][]string), Users: make(map[string]yipSchema.User), @@ -115,7 +112,7 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) { return nil, err } initramfs.Files = append(initramfs.Files, yipSchema.File{ - Path: manifestsDirectory+canalConfig, + Path: manifestsDirectory + canalConfig, Content: canalHelmChartConfig, Permissions: 0600, Owner: 0, @@ -129,11 +126,11 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) { return nil, err } initramfs.Files = append(initramfs.Files, yipSchema.File{ - Path: manifestsDirectory+harvesterConfig, - Content: harvesterHelmChartConfig, + Path: manifestsDirectory + harvesterConfig, + Content: harvesterHelmChartConfig, Permissions: 0600, - Owner: 0, - Group: 0, + Owner: 0, + Group: 0, }) } } @@ -141,7 +138,7 @@ func ConvertToCOS(config *HarvesterConfig) (*yipSchema.YipConfig, error) { cosConfig := &yipSchema.YipConfig{ Name: "Harvester Configuration", Stages: map[string][]yipSchema.Stage{ - "initramfs": {preStage, initramfs}, + "initramfs": {initramfs}, }, } diff --git a/pkg/console/install_panels.go b/pkg/console/install_panels.go index d0e61a61a..618bf5a5c 100644 --- a/pkg/console/install_panels.go +++ b/pkg/console/install_panels.go @@ -763,7 +763,7 @@ func addNetworkPanel(c *Console) error { if output, err := setupNetwork(); err != nil { return fmt.Sprintf("Configure network failed: %s", string(output)), nil } - return "Can't get a valid IP address from DHCP server", nil + return "", nil } askNetworkMethodVConfirm := func(g *gocui.Gui, _ *gocui.View) error { selected, err := askNetworkMethodV.GetData()