ONIE简介
Open Network Install Environment (ONIE) 是一个开源计划,为现代网络硬件定义了一个开放的安装环境。ONIE 造就了一个开放的网络硬件生态系统,使得最终用户可以在不同的网络操作系统中进行选择。
在 ONIE 出现之前,以太网交换机使用预装的专有操作系统,这中网络设备将最终用户锁定到设备的垂直供应链上。本质上,ONIE是一个基于Linux的小型操作系统,可以在交换机上启动并发现本地网络上可用的安装程序映像,同时能够将合适的映像传输到交换机,然后提供一个安装环境,以便安装程序可以将网络操作系统加载到交换机。
最初,ONIE 通过向多个操作系统供应商开放硬件开启了 “白盒” 和 “裸机” 网络交换机生态系统。随着时间的推移, ONIE 的知名度不断提高,现在 ONIE 已经成为网络硬件行业的主流安装环境。
ONIE 定义了一个开源的安装环境,该安装环境运行在这个管理子系统的 Linux 内核和BusyBox 环境上。这个环境允许最终用户和渠道合作伙伴安装目标 NOS。
ONIE就类似PC的BIOS,在上边承载操作系统。
ONIE安装
制作启动U盘
windows和linux都可以制作启动U盘,分别看下。
1.windows下制作启动U盘
推荐使用工具Win32DiskImager,网上有很多资源可以下载。插入U盘,工具会自动识别U盘,手动选择需要写入的ONIE映像。点击写入,大概十几秒写入完成,会提示写入成功。
U盘的格式一般默认是FAT/FAT32,这种交换机可以识别。也有些U盘是默认FAT模式,就需要先改为FAT/FAT32模式(计算机-U盘右键-格式化)就可以修改。
通过Win32DiskImager制作之后的U盘空间会变小(本来15G,制作启动盘只剩下1M了),恢复需要在CMD操作(win+R,输入cmd回车进入),命令如下:
C:\WINDOWS\system32>diskpart
Microsoft DiskPart 版本 10.0.19041.964
Copyright (C) Microsoft Corporation.
在计算机上: DESKTOP-J7BOHDM
DISKPART> list disk
磁盘 ### 状态 大小 可用 Dyn Gpt
-------- ------------- ------- ------- --- ---
磁盘 0 联机 931 GB 2048 KB *
磁盘 1 联机 15 GB 15 GB
DISKPART> select disk 1
磁盘 1 现在是所选磁盘。
DISKPART> clean
DiskPart 成功地清除了磁盘。
DISKPART> create partition primary
DiskPart 成功地创建了指定分区。
DISKPART> active
DiskPart 将当前分区标为活动。
DISKPART> format fs=fat32 quick
100 百分比已完成
DiskPart 成功格式化该卷。
通过上述命令格式化之后就恢复了15G大小,如下图:
2.linux制作启动U盘
linux也有对应的工具制作启动盘,操作和windows类似。这里主要说下用dd命令制作启动盘,注意别写错磁盘,否则会损坏别的数据。直接上操作流程。
root@zhouzh:/home/zhouzh# sudo fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
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: 0xb8e3dd97
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 60913663 60911616 29G 83 Linux
/dev/sda2 60915710 62912511 1996802 975M 5 Extended
/dev/sda5 60915712 62912511 1996800 975M 82 Linux swap / Solaris
Disk /dev/sdb: 15 GiB, 16122970112 bytes, 31490176 sectors
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: 0xab9edb0b
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 31490047 31488000 15G c W95 FAT32 (LBA)
root@zhouzh:/home/zhouzh#
root@zhouzh:/home/zhouzh# dd if=/home/zhouzh/work/onie-recovery-x86_64-pegatron_common_bde-r0.iso of=/dev/sdb1
68224+0 records in
68224+0 records out
34930688 bytes (35 MB, 33 MiB) copied, 33.9418 s, 1.0 MB/s
root@zhouzh:/home/zhouzh#
U盘安装ONIE
通过U盘安装ONIE,步骤如下。
1.修改启动项为U盘启动,这里读出来是AI Mass Storage(大容量存储器)。启动时根据提示按Esc或者Del进入Bios设置启动项。设置boot option 1 为AI Mass Storage。保存并退出,等待设备重启。
2.启动后在grub引导菜单中选择“Embed ONIE”用于安装ONIE到VM硬盘上。会从U盘中读取之前写入的ONIE映像,并自动安装。
在这一步,搞了好久,一直写不进去,没办安装U盘上的系统。最开始以为是启动U盘制作的有问题,就反复windows/linux下分别制作启动盘,还是解决不了。网上查了很久,找到解决方案,研究不深,不明白具体原因,但是所幸问题得到了解决。
参考:http://t.zoukankan/busui-p-10758441.html
总结下来,就是由于反复操作不当导致垃圾项过多,系统没办法找到合适的映像文件。
只需要删除dump文件(清除NVROM中的无效/垃圾项),再重启一次就正确安装了。
# rm /sys/firmware/efi/efivars/dump-*
ONIE: Embedding ONIE ...
Platform : x86_64-pegatron_common_bde-r0
Version : pegatron_common_bde-2021.11-10
Build Date: 2021-12-03T08:08+00:00
error: no suitable video mode found.
Booting in blind mode
Info: Mounting kernel filesystems... done.
Info: Mounting ONIE-BOOT on /mnt/onie-boot ...
Info: Mounting EFI System on /boot/efi ...
Info: Secure Boot: Disabled.
Info: BIOS mode: UEFI
sd 6:0:0:0: [sdb] No Caching mode page found
sd 6:0:0:0: [sdb] Assuming drive cache: write through
Info: Using eth0 MAC address: 48:21:0b:28:68:54
Info: eth0: Checking link... up.
Info: Trying DHCPv4 on interface: eth0
Warning: Unable to configure interface using DHCPv4: eth0
ONIE: Using link-local IPv4 addr: eth0: 169.254.210.246/16
Starting: klogd... done.
Starting: dropbear ssh daemon... done.
Starting: telnetd... done.
discover: ONIE embed mode detected. Running updater.
Starting: discover... done.
Please press Enter to activate this console. To check the install status inspect /var/log/onie.log.
Try this: tail -f /var/log/onie.log
** ONIE Update Mode Enabled **
ONIE-RECOVERY:/ #
ONIE-RECOVERY:/ # Info: eth0: Checking link... up.
Info: Trying DHCPv4 on interface: eth0
Warning: Unable to configure interface using DHCPv4: eth0
ONIE: Using link-local IPv4 addr: eth0: 169.254.108.126/16
ONIE: Starting ONIE Service Discovery
Info: Found static url: file:///lib/onie/onie-updater
ONIE: Executing installer: file:///lib/onie/onie-updater
Verifying image checksum ... OK.
Preparing image archive ... OK.
ONIE: Version : pegatron_common_bde-2021.11-10
ONIE: Architecture : x86_64
ONIE: Machine : pegatron_common_bde
ONIE: Machine Rev : 0
ONIE: Config Version: 1
ONIE: Build Date : 2021-12-03T08:08+00:00
Installing ONIE on: /dev/sda
Post installation hook
INFO: Create DIAG Partition
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
mke2fs 1.46.3 (27-Jul-2021)
Discarding device blocks: done
Creating filesystem with 786432 4k blocks and 196608 inodes
Filesystem UUID: cc743a8a-6c68-40e7-b259-c34e4d91c016
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
ONIE: Success: Firmware update URL: file:///lib/onie/onie-updater
ONIE: Success: Firmware update version: pegatron_common_bde-2021.11-10
ONIE到这里就安装成功了。从打印看,设备启动之后会从DHCP服务器获取IP,创建eth0。猜测是也可以从服务器获取ONIE映像文件安装ONIE系统,但是没有这个环境,就直接采用U盘安装了。
Sonic NOS系统安装
ONIE安装之后,仅仅相当于装了一个boot,对一个交换机设备而言,还需要有操作系统,这里安装的是Sonic-Clounix操作系统平台软件。ONIE安装完成重启界面如下,选择Install OS。
这里不直接安装OS,从下面的打印可以看到,ONIE安装OS和前面U盘安装ONIE类似,首先还是从DHCP服务器获取IP,可以从服务器获取对应OS文件。并通过ONIE自带的onie-nos-install工具安装OS。同样,缺乏环境。 可以采用U盘/tftp安装,U盘安装比较简单快捷,不做赘述,这里主要说下通过TFTP安装。
Booting in blind mode
Info: Mounting kernel filesystems... done.
Info: Mounting ONIE-BOOT on /mnt/onie-boot ...
Info: Mounting EFI System on /boot/efi ...
Info: Secure Boot: Disabled.
Info: BIOS mode: UEFI
Info: Making NOS install boot mode persistent.
sd 6:0:0:0: [sdb] No Caching mode page found
sd 6:0:0:0: [sdb] Assuming drive cache: write through
Info: Using eth0 MAC address: 48:21:0b:28:68:54
Info: eth0: Checking link... up.
Info: Trying DHCPv4 on interface: eth0
Warning: Unable to configure interface using DHCPv4: eth0
ONIE: Using link-local IPv4 addr: eth0: 169.254.13.5/16
Choose device for installing NOS or wait 10 seconds to choose default device
1) ata: 256GB SATA Flash
Please select device:ONIE: Time Out!!!
ONIE: ONIE will choose default device
Starting: klogd... done.
Starting: dropbear ssh daemon... done.
Starting: telnetd... done.
discover: installer mode detected. Running installer.
Starting: discover... done.
Please press Enter to activate this console. Info: eth0: Checking link... up.
Info: Trying DHCPv4 on interface: eth0
Warning: Unable to configure interface using DHCPv4: eth0
ONIE: Using link-local IPv4 addr: eth0: 169.254.123.40/16
ONIE: Starting ONIE Service Discovery
Info: Attempting file://dev/sdb1/onie-installer-x86_64-pegatron_fn8032_bnf-r0 ...
Info: Attempting file://dev/sdb1/onie-installer-x86_64-pegatron_fn8032_bnf-r0.bin ...
Info: Attempting file://dev/sdb1/onie-installer-x86_64-pegatron_fn8032_bnf ...
Info: Attempting file://dev/sdb1/onie-installer-x86_64-pegatron_fn8032_bnf.bin ...
Info: Attempting file://dev/sdb1/onie-installer-pegatron_fn8032_bnf ...
Info: Attempting file://dev/sdb1/onie-installer-pegatron_fn8032_bnf.bin ...
Info: Attempting file://dev/sdb1/onie-installer-x86_64-nephos ...
Info: Attempting file://dev/sdb1/onie-installer-x86_64-nephos.bin ...
Info: Attempting file://dev/sdb1/onie-installer-x86_64 ...
Info: Attempting file://dev/sdb1/onie-installer-x86_64.bin ...
Info: Attempting file://dev/sdb1/onie-installer ...
Info: Attempting file://dev/sdb1/onie-installer.bin ...
Info: Attempting tftp://onie-server/48-21-0B-28-68-54/onie-installer-x86_64-pegatron_fn8032_bnf-r0 ...
Info: Attempting tftp://onie-server/onie-installer-x86_64-pegatron_fn8032_bnf-r0 ...
Info: Attempting tftp://onie-server/onie-installer-x86_64-pegatron_fn8032_bnf-r0.bin ...
Info: Attempting tftp://onie-server/onie-installer-x86_64-pegatron_fn8032_bnf ...
Info: Attempting tftp://onie-server/onie-installer-x86_64-pegatron_fn8032_bnf.bin ...
Info: Attempting tftp://onie-server/onie-installer-pegatron_fn8032_bnf ...
Info: Attempting tftp://onie-server/onie-installer-pegatron_fn8032_bnf.bin ...
Info: Attempting tftp://onie-server/onie-installer-x86_64-nephos ...
Info: Attempting tftp://onie-server/onie-installer-x86_64-nephos.bin ...
Info: Attempting tftp://onie-server/onie-installer-x86_64 ...
Info: Attempting tftp://onie-server/onie-installer-x86_64.bin ...
Info: Attempting tftp://onie-server/onie-installer ...
Info: Attempting tftp://onie-server/onie-installer.bin ...
首先,需要搭建tftp服务端,可参考:
https://blog.csdn/zaizaiguigui/article/details/127118851
ONIE会反复从DHCP服务区获取IP,并通过discover脚本获取安装程序。配置eth0 IP后,会被自动改写,保证能跟服务器稳定互通,需要先kill dhcp服务。并关掉discover服务,直接从tftp服务端获取安装安装文件。
配置IP和路由,保证网络互通。
ONIE:/ # ifconfig eth0 172.17.2.146 netmask 255.255.255.0 broadcast 172.17.2.255
ONIE:/ # route add default gw 172.17.2.1
ONIE:/ # ping 172.17.1.53
PING 172.17.1.53 (172.17.1.53): 56 data bytes
64 bytes from 172.17.1.53: seq=1 ttl=63 time=0.464 ms
64 bytes from 172.17.1.53: seq=2 ttl=63 time=1.800 ms
64 bytes from 172.17.1.53: seq=3 ttl=63 time=0.534 ms
64 bytes from 172.17.1.53: seq=4 ttl=63 time=1.140 ms
64 bytes from 172.17.1.53: seq=5 ttl=63 time=0.818 ms
64 bytes from 172.17.1.53: seq=6 ttl=63 time=0.698 ms
^C
--- 172.17.1.53 ping statistics ---
7 packets transmitted, 6 packets received, 14% packet loss
round-trip min/avg/max = 0.464/0.909/1.800 ms
ONIE:/ #
通过tftp安装sonic平台。由于OS文件比较大,所以这一步需要等待大概20+分钟,为了保证安装不会中断,避免安装过程中操作交换机。安装打印如下:
ONIE:/ # onie-nos-install tftp://172.17.1.53/sonic-clounix.bin
discover: installer mode detected.
Stopping: discover... done.
Info: Attempting tftp://172.17.1.53/sonic-clounix.bin ...
sonic-clounix.bin 0% | | 546k 0:33:36 ETA
sonic-clounix.bin 0% | | 1413k 0:25:57 ETA
sonic-clounix.bin 0% | | 2265k 0:24:16 ETA
sonic-clounix.bin 0% | | 3009k 0:24:20 ETA
......
sonic-clounix.bin 99% |****************************** | 1074M 0:00:01 ETA
sonic-clounix.bin 99% |****************************** | 1075M 0:00:00 ETA
sonic-clounix.bin 100% |*******************************| 1075M 0:00:00 ETA
sonic-clounix.bin 100% |*******************************| 1075M 0:00:00 ETA
ONIE: Executing installer: tftp://172.17.1.53/sonic-clounix.bin
Verifying image checksum ... OK.
Preparing image archive ... OK.
Installing SONiC in ONIE
ONIE Installer: platform: x86_64-clounix-r0
onie_platform: x86_64-pegatron_fn8032_bnf-r0
Partition #1 is in use.
Partition #2 is in use.
Partition #4 is in use.
Partition #3 is available
Creating new SONiC-OS partition /dev/sda3 ...
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
mke2fs 1.46.3 (27-Jul-2021)
Discarding device blocks: done
Creating filesystem with 8388608 4k blocks and 2097152 inodes
Filesystem UUID: b289f8b9-c7fb-42da-b025-9b43235faff6
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done
Installing SONiC to /tmp/tmp.mrubB5/image-dev_202012.ks_v0.0.5
Archive: fs.zip
creating: boot/
inflating: boot/config-4.19.0-12-2-amd64
inflating: boot/initrd.img-4.19.0-12-2-amd64
inflating: boot/System.map-4.19.0-12-2-amd64
inflating: boot/vmlinuz-4.19.0-12-2-amd64
creating: platform/
creating: platform/x86_64-grub/
inflating: platform/x86_64-grub/grub-pc-bin_2.02+dfsg1-20+deb10u4_amd64.deb
inflating: platform/firsttime
creating: platform/x86_64-pegatron_fn8656_bnf-r0/
inflating: platform/x86_64-pegatron_fn8656_bnf-r0/sonic-platform-pegatron-fn8656-bnf_1.0.0_amd64.deb
creating: platform/x86_64-pegatron_fn8032_bnf-r0/
inflating: platform/x86_64-pegatron_fn8032_bnf-r0/sonic-platform-pegatron-fn8032-bnf_1.0.0_amd64.deb
inflating: fs.squashfs
ONIE: Unable to find 'Part Number' TLV in EEPROM data.
Success: Support tarball created: /tmp/onie-support-pegatron_fn8032_bnf.tar.bz2
Switch CPU vendor is: GenuineIntel
Switch CPU cstates are: disabled
Installed SONiC base image SONiC-OS successfully
ONIE: NOS install successful: tftp://172.17.1.53/sonic-clounix.bin
ONIE: update_image : /var/tmp/installer
ONIE: Rebooting...
安装完成后会自动重启交换机,选择sonic系统进入。
进入系统之后,默认用户名:admin,默认密码:YourPaSsWoRd 即可进入操作页面。
简单装系统,这个过程还是比较坎坷的,发个文记录下。好记性不如烂笔头。
sonic平台没有ifconfig命令采用的是ip命令,记录下配置IP和路由的命令。
root@sonic:/home/admin# ip address add 172.17.2.146/24 dev eth0
root@sonic:/home/admin# ip route add default via 172.17.2.1 dev eth0
root@sonic:/home/admin# ping 172.17.1.53
PING 172.17.1.53 (172.17.1.53) 56(84) bytes of data.
64 bytes from 172.17.1.53: icmp_seq=1 ttl=63 time=0.808 ms
64 bytes from 172.17.1.53: icmp_seq=2 ttl=63 time=0.798 ms
64 bytes from 172.17.1.53: icmp_seq=3 ttl=63 time=0.656 ms
^C
--- 172.17.1.53 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 50ms
rtt min/avg/max/mdev = 0.656/0.754/0.808/0.069 ms
root@sonic:/home/admin#