1. Introduction

Now that we have access to our switch, we are ready to install an operating system on it.

In this lesson, we first look at the Open Network Install Environment, or ONIE. Then we walk through how the actual SONiC installation works, and finally how to upgrade SONiC once it is running.

2. What is ONIE?

Before we install anything, let’s look at the ONIE bootloader that ships with every bare metal switch.

ONIE stands for Open Network Install Environment. Its job is to make it easy to install and uninstall network operating systems on a bare metal switch. ONIE is a project of the Open Compute Project Foundation, or OCP.

ONIE is often called a bootloader, but it is really a small operating system of its own. It runs a Linux kernel with BusyBox, a toolset designed for small embedded systems, which keeps it compact.

Operating systems for bare metal switches are delivered as ONIE installers. These are self-extracting archives that ONIE executes. SONiC, too, is available as ONIE installers in many flavors.

ONIE makes it simple to install an OS on one switch or on hundreds. It offers many hooks for automation, so a switch can be installed without any manual intervention. This is what we call Zero Touch Provisioning, or ZTP.

You can find more about ONIE on the OCP website, linked on the slide.

ONIE is pre-installed on a small partition of the switch storage and normally stays there. Other operating systems are installed in partitions next to it. If no other OS is installed, ONIE boots into install mode when the switch powers up.

In install mode, ONIE keeps looking for an installer image, both locally and on the network. It follows a defined search order: the local file system, any USB stick, and HTTP or TFTP servers on the network. You can also use DHCP to hand the switch a URL that points to an installer image.

If you don’t want to set up servers just to install a handful of switches, you can run an installer manually. You simply give ONIE a local file name or a URL.

The installation itself is usually fully automatic, so you can sit back and watch. One of the installer’s last steps is to configure the GRUB boot menu, so that after the next reboot the switch starts the newly installed OS. ONIE stays in the GRUB menu as an alternative entry.

The switch then reboots on its own, and you should eventually see the login prompt of the new operating system.

3. ONIE modes

Installing an OS is ONIE’s main job, but it offers a few more modes.

Uninstall mode. Anything you install may need to be removed one day. When you boot into uninstall mode, the uninstall process starts automatically. It is very thorough: it wipes and zeroes the switch’s entire permanent storage. Every partition except the ONIE partition is erased. Because the whole storage is overwritten, this can take a long time, depending on the size of the partitions. When it finishes, the switch reboots into ONIE install mode, ready for a new OS.

Rescue mode. As the name suggests, this mode is not for normal operation but for troubleshooting and repair. It looks like install mode, except that the automatic installation does not start. You could use it, for example, to regain access to the switch if you have forgotten the OS password.

Embed ONIE mode. You’ll find this mode when you boot the switch from a USB stick that contains an ONIE image for that switch. It is used to maintain ONIE itself, for example to repair a broken ONIE or to update it. You can get these images from your switch vendor.

Now that we know how ONIE helps us install an open networking OS, we’re ready to install SONiC on our switch.

4. Installation options

ONIE gives us several ways to install an OS on a switch: automated and manual.

With automated installation, we can install any number of switches without manual intervention. We prepare our ONIE or DHCP servers once, and every new switch uses them.

Manual installation can be easier when you only have a few switches and don’t want to set up servers for them. It’s also handy for installing a special image on one particular switch.

There are two automated options:

  • ONIE discovery. ONIE looks for a specific HTTP or TFTP server and for specific image names on it. These file names depend on the switch type, so they are vendor-specific.
  • DHCP. The DHCP server sends the switch a default URL that points to the installer image.

With both methods, the installation starts automatically as soon as a valid installer image has been downloaded.

Manual installation is easy too. You run the command onie-nos-install with an installer URL or a local file name. A local file could be an installer you uploaded to the switch earlier, or a file on a mounted USB stick.

All of these options work not only for SONiC, but for any OS that comes as an ONIE installer image.

Let’s look at each option in more detail.

5. The ONIE EEPROM

You may want to use different OS images depending on the switch type, or even for one particular switch.

To support this, ONIE maintains an EEPROM with information about the switch. The automated installation options use it to identify the switch or its type. It holds, for example, the platform name, product name, serial number and base MAC address.

ONIE discovery uses this information to build the installer file names it tries to download. The DHCP client uses it to fill in the client identifiers in its DHCP requests.

You can view the EEPROM contents with the onie-syseeprom command. As we’ll see in the troubleshooting module, you can also query this information while the switch runs SONiC.

The onie-sysinfo command displays just the platform name.

ONIE:/ # onie-syseeprom
ONIE:/ # onie-sysinfo

6. Automated installation: ONIE discovery

Now let’s look at the installation methods themselves, starting with the ONIE discovery process.

Discovery starts automatically when ONIE boots into install mode. It repeats every 20 seconds until it finds an installer image. You can stop it with onie-stop and restart it with onie-start. In older ONIE versions, these commands are called onie-discovery-stop and onie-discovery-start.

First, ONIE looks for an HTTP or TFTP server with the host name onie-server. This name must be resolvable by DNS, so ONIE must already have received a DNS server address through DHCP.

ONIE also searches for HTTP and TFTP servers in its own VLAN. It sends broadcast pings over IPv4 and IPv6, then tries HTTP and TFTP access on every host that answers.

Once ONIE finds a server, it looks for images that follow a standard naming pattern. The names start with onie-installer and include switch-specific parts such as the CPU architecture, the vendor and the switch type. ONIE takes this information from the EEPROM we just discussed. The full list of file names it tries is in the ONIE documentation.

ONIE repeats all of these steps every 20 seconds. So it’s never too late to set up your server or fix its configuration, for example when your TFTP file doesn’t have global read permissions.

As soon as ONIE downloads a valid installer image, the installation starts automatically.

7. Automated installation: DHCP

A more flexible automated option uses the DHCP server to tell the switch where the installer image is.

ONIE already uses DHCP to get an IP address for the switch’s management interface. Along with its offer, the DHCP server can send a default URL option. ONIE then downloads the image from that URL.

ONIE also helps the DHCP server choose the right image. It includes switch-specific information from the EEPROM in its DHCP requests. The switch type is encoded in two DHCP options: option 60, the Vendor Class Identifier, and option 125, the Vendor-Identifying Vendor-Specific Information, or VIVSO for short.

Again, as soon as ONIE downloads a valid installer image from that URL, the installation starts automatically.

Here is an example of a simple DHCP server configuration file.

The first snippet shows the subnet declaration with the address pool, subnet mask, gateway and name server. We can already put the default URL option here, but then every device in that subnet receives it.

We can also add a host-specific entry based on the MAC address of the switch’s management port. That way, only this switch receives the default URL.

Or we can add a class that matches only ONIE devices of a certain type, and supply a different URL per switch type. That configuration gets a bit long, so please refer to the ONIE documentation for examples.

8. Manual installation

Now that we’ve covered the automated options, let’s do a manual install.

From a server. Our first example pulls the installer from an HTTP, FTP or TFTP server. This can be an internal server. If the switch has internet access and you have any required credentials, it can also be an external server, possibly the OS vendor’s own. Just run onie-nos-install with the URL of the installer image. The image is downloaded, verified against its checksum, and the installation begins.

ONIE:/ # onie-nos-install http://<server>/<path>/sonic-installer.bin

From a local file. You can also start a manual install from a local installer file, for example one you uploaded to the switch with SCP. You can usually save it in root’s home directory, /root, which is your working directory when you log in. If the file is too large, save it to /tmp instead. Note that both file systems are volatile, so your files are gone after a reboot. Then run onie-nos-install with the path to the file, and the installation begins.

ONIE:/ # onie-nos-install /root/sonic-installer.bin

From a USB stick. Another option is to plug a USB stick with an installer file into the switch’s USB port. The stick doesn’t need to be bootable. A plain data stick with a FAT32 file system works, and ext2 does as well.

As usual in Linux, you must mount the stick before you can access its files. In this example, we create a directory under /mnt and mount the USB file system there. The device name of your stick can vary, depending on the storage devices in the switch and the partitions on the stick. Use lsblk, gdisk or a similar command to find the right partition.

Once it’s mounted, run onie-nos-install again, with the path to the installer file under the USB mount point.

ONIE:/ # mkdir /mnt/usb
ONIE:/ # mount /dev/sdb1 /mnt/usb
ONIE:/ # onie-nos-install /mnt/usb/sonic-installer.bin

9. Licensing

Using one of these methods, we have now installed SONiC on our switch.

Many operating systems need a license before you can use them. SONiC does not. Because it started as an open source project, even commercial distributions don’t require a license.

Of course, commercial vendors still need to earn money. Instead of license fees, their business is based on support contracts, which are required to use their distribution. This is similar to the model Red Hat uses for its Linux distribution.

10. Upgrading with sonic-installer

We now know how to install SONiC on a switch for the first time. But sooner or later we’ll want to upgrade it, with as little hassle as possible.

All the methods we’ve seen so far are based on ONIE, and ONIE knows nothing about the operating systems it installs.

During a switch’s life cycle, new SONiC versions will appear, with new features or security fixes, and we’ll want to install them. Since ONIE doesn’t understand SONiC, upgrading with ONIE means uninstalling the old version and installing the new one. As we’ve learned, ONIE’s uninstall wipes the entire switch storage. Along with SONiC, all data such as switch configurations and other additions would be lost.

To avoid this, SONiC has its own installation tool, called the SONiC installer. When you use it to upgrade, it prepares the new image in a new directory on the host partition and leaves the existing installation untouched.

This way, data from the read-write directories is reused. The upgrade is also much faster, because you skip the lengthy ONIE uninstall. Your existing switch configuration is kept and migrated to the new version.

Be careful, though. Small incompatibilities between Redis database versions can invalidate parts of your old configuration. This is especially likely when you move from one SONiC distribution to another, so in that case a fresh ONIE install may be the better choice. Within the same distribution, problems are less likely, but it’s always a good idea to validate your configuration after an upgrade.

The SONiC installer supports two installed images at the same time: the primary image, which is currently running, and a backup image.

To see which images are installed, use sonic-installer list. It shows all installed images and marks the active one. Note that sonic-installer always needs sudo privileges, even for this read-only list command.

Use sonic-installer set-default to choose the image that becomes the new primary. It is loaded at every following boot, so you need to reboot the switch to start using it.

There is also sonic-installer set-next-boot, which boots a different image just once. It’s a convenient way to try out a new image. This also needs a reboot to take effect.

Of course, before you can boot a new image, you must install it with sonic-installer install. Give it the URL of the new image, or upload the image first and pass its local path. The installation runs automatically, and the new image is set as the new primary. The switch does not reboot automatically, though, so you have time to warn users or save data.

Because only two images fit on the switch, you may need to remove an obsolete one. Use sonic-installer remove with the name of the image, which you can get from sonic-installer list.

admin@sonic:~$ sudo sonic-installer list
admin@sonic:~$ sudo sonic-installer install http://<server>/<path>/sonic.bin
admin@sonic:~$ sudo sonic-installer set-default <image-name>
admin@sonic:~$ sudo sonic-installer set-next-boot <image-name>
admin@sonic:~$ sudo sonic-installer remove <image-name>

11. Choosing an upgrade path

That leaves us with two ways to upgrade SONiC.

The SONiC installer. This is usually the best choice when you upgrade within the same SONiC distribution, because you keep your configuration. As mentioned, you should still verify it after the upgrade, and of course save and back it up before you start.

A fresh ONIE install. This is the ruthless option: the ONIE uninstaller removes everything on the switch, and then you install SONiC from scratch. It’s a good choice when your new installation will be very different from the old one. For example, you’re switching to a different distribution, or jumping from a very old version to a new one, where data may be incompatible. It also makes sense if you suspect your old installation is corrupted. You can still back up your old configuration and apply it to the new version, perhaps with manual or scripted changes.

For a fresh install, you first boot into ONIE uninstall mode. This usually requires console access. There are ways to modify the switch’s GRUB configuration so you can do this from a remote session, but that is beyond the scope of this training.

Once the switch boots into uninstall mode, the uninstall starts immediately, as described earlier. When it’s done, the switch reboots into ONIE install mode, and you can install your new SONiC version.


Corrections made to the original transcript

  • “pseudo privileges” → sudo privileges
  • “XT2” → ext2
  • onie-sys-eeprom / onie-sys-info → onie-syseeprom / onie-sysinfo
  • “onie discovery stop/start” → onie-discovery-stop / onie-discovery-start
  • “set default” / “set next” → sonic-installer set-default / set-next-boot
  • “vendor identifying vendor-specific information” → Vendor-Identifying Vendor-Specific Information (option 125)