Photo by Desola Lanre-Ologun on Unsplash
How I Automate Building VyOS Images
3 min read
Shortly after I started using VyOS as my home router a few years ago, I discovered that the release ISOs were lacking a few packages that were important to me. Using the VyOS Docs page titled Build VyOS, I managed to build my own image with git & nano built in.
That list of packages has grown over time to five, but the process is pretty straightforward: clone a git repo, issue a few commands, wait for VyOS to build, then issue a couple more commands to build the ISO.
Using their tip to build a bash alias to handle starting the Docker container, I created two scripts that automate the process for me. This allowed me to create a cron job that kicks off the build process on the first of the month, enabling me to upgrade my VM monthly.
Here's a funny side story: As I was writing this article, I decided to test my scripts after making a couple of changes to make them suitable for publishing. After the first pass, I realized the ISO was failing to build with the correct name. After a little research, it became apparent that the
./configure script in the documentation no longer existed, so it went right on to
sudo make iso, building a generic ISO without my custom packages & a different name.
A little more investigation of the commit history on the
vyos-build git repo revealed that they're moving to a new "build_flavor" system, so my script would no longer work.
I had to modify the scripts a bit more to get them to work, but below you'll find what is now working once again for me.
This script pulls and starts the container
vyos/vyos-build:current on the Docker host. It also tells the container to execute the
isobuild.sh script immediately.
This is where the real magic happens. In this script, I'm adding
nano to my image before building.
Here's the code for both files, but if you choose to use them, you'll need to do a few things first:
- Rename the files to
isobuild.sh, or just copy/paste the code from below into new files.
- Modify the variables in each file to replace my home directory
- Review and modify the additional packages I'm adding and remove or add any you want to. Remember, if you add a
PKG5variable, you have to add a line for
build-vyos-imagesection toward the end.
Pulling it All Together
First, I clone the
vyos/vyos-build repo to my system:
git clone -b current --single-branch email@example.com:vyos/vyos-build
Then, I change to the repo directory, copy my scripts in, and run autobuild.sh:
cd vyos-build cp ~/scripts/autobuild.sh ~/scripts/isobuild.sh ./ ./autobuild.sh
That's pretty much it. At this point, I just keep an eye on the screen for any errors that stop the process. You'll see a ton of text fly by for quite some time--for reference, on my Intel Core i7 6700K (4GHz Quad-Core), it takes about 10-15 minutes.
Then, when the command completes, there's a new .iso file in the working directory. I use
scp to transfer that over to my router and then log into the router and apply the new image.
I also schedule this on my build box using a cronjob. It runs at 5am on the first day of each month. I've added the following to my crontab (
crontab -e to edit it):
# m h dom mon dow command 0 5 1 * * /path/to/autobuild.sh > /dev/null 2>&1