The ability to automatically install Ubuntu Linux would be useful to system administrators that must deploy the operating system to new physical or virtual machines on a regular basis. While you can manually install ubuntu, automatic provision of these systems can save hundreds of man hours as well as decrease the likelihood of human error. Automation of installing Ubuntu involves supplying the operating system with the desired hostname, username, and password.
With this information, Ubuntu can install itself without the need for any user interaction. Once everything is done installing, you can boot into Ubuntu for the first time and have everything set up the way you planned.
In this tutorial, we will show you a couple examples of an Ubuntu autoinstall configuration. This will include generating an ISO file that can automatically install Ubuntu, as well as deploying an autoinstall to a new virtual machine with KVM.
Privileged access to your Linux system as root or via the sudo command.
Conventions
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command $ – requires given linux commands to be executed as a regular non-privileged user
Ubuntu autoinstall examples
Below we will cover the step by step instructions to automatically install Ubuntu. Depending on your situation and environment, you may want to either generate an Ubuntu ISO that will self install, or just deploy a virtual machine (we will use KVM in this example) to automatically install Ubuntu. Choose whichever method suits you best below.
The configuration above will set your system hostname to ubuntu-server, your username to ubuntu, and the password (which is an encrypted hash in the above code) to ubuntu.
You will also need to generate a meta-data file which can simply be left empty.
$ touch meta-data
We will now use python3 to create a very basic web server that can serve our cloud-init configuration over http.
$ cd ~/www && python3 -m http.server 3003
Create a target disk to which you will install Ubuntu. You can put this file wherever you want and adjust the size according to your needs.
For these steps, we will utilize covertsh’s Ubuntu autoinstall generator hosted on Git Hub. This is just a Bash script that helps us simplify the process of generating an autoinstall ISO, thus making everything much easier.
The first thing you will need to do is download Ubuntu 20.04. Then, download the necessary Bash script off of Git Hub:
The configuration above will set your system hostname to ubuntu-server, your username to ubuntu, and the password (which is an encrypted hash in the above code) to ubuntu.
You will also need to generate a meta-data file which can simply be left empty.
$ touch meta-data
Now you are ready to run the script and create your Ubuntu autoinstall ISO file. Execute the following command, while substituting your own paths to the ISO file, user-data file, and meta-data file.
All that is left to do now is use your ISO to install Ubuntu. This can be popped into a physical machine or used on a virtual machine like KVM, VirtualBox, VMware, etc, and the operating system will automatically be installed without user interaction.
Closing Thoughts
In this tutorial, we saw how to create an Ubuntu autoinstall configuration through two different examples on a Linux system. The first method involved deploying a cloud-init configuration to a kvm instance, and the second solution generated our own Ubuntu autoinstall ISO with the proper configuration files baked in. Regardless of your scenario, this should allow you to install Ubuntu without user interaction, cutting down on wasted hours and ultimately cost.