Software & AppsOperating SystemLinux

How To Create a Headless, Unattended Install of Ubuntu

Ubuntu 17

In this tutorial, we will walk you through the steps to create a headless, unattended install of Ubuntu. This is particularly useful if you need to set up multiple machines or if you want to automate the installation process for efficiency or consistency.

Quick Answer

To create a headless, unattended install of Ubuntu, you need to mount the ISO, copy the ISO files to a different directory, prevent the language selection menu, create a kickstart file, add packages for installation, create a preseed file, set the boot command line, and create a new ISO. This process allows you to automate the installation of Ubuntu on multiple machines without requiring any user input.

Prerequisites

Before we start, you will need to have:

  • A Ubuntu installation ISO (server or alternate installation CD)
  • Basic knowledge of Linux commands and the terminal

Step 1: Mount the ISO

The first step is to mount the ISO. This can be done by creating a directory to mount the ISO and then mounting it using the mount command. Here’s how to do it:

$ sudo su -
# mkdir -p /mnt/iso
# mount -o loop ubuntu.iso /mnt/iso

In this command, sudo su - switches the user to root, mkdir -p /mnt/iso creates a new directory to mount the ISO, and mount -o loop ubuntu.iso /mnt/iso mounts the ISO to the directory.

Step 2: Copy the ISO Files

Next, you need to copy the relevant files to a different directory. Here’s how to do it:

# mkdir -p /opt/ubuntuiso
# cp -rT /mnt/iso /opt/ubuntuiso

Here, mkdir -p /opt/ubuntuiso creates a new directory to copy the files to, and cp -rT /mnt/iso /opt/ubuntuiso copies the files from the mounted ISO to the new directory.

Step 3: Prevent Language Selection Menu

To prevent the language selection menu from appearing during installation, you can create a file named lang in the isolinux directory and add your language code to it. For English, the code is en.

# cd /opt/ubuntuiso
# echo en >isolinux/lang

Step 4: Create a Kickstart File

Kickstart is a method used by Red Hat-based distributions to automate the installation process. Ubuntu supports a subset of the Kickstart options. You can use a GUI program like system-config-kickstart to create a kickstart file named ks.cfg and save it in /opt/ubuntuiso.

Step 5: Add Packages for Installation

You can specify additional packages to be installed by appending a %packages section to the ks.cfg file. For example:

%packages
@ ubuntu-server
openssh-server
ftp
build-essential

This will install the ubuntu-server, openssh-server, ftp, and build-essential packages during the installation.

Step 6: Create a Preseed File

A preseed file is used to answer the questions asked during the installation process. You can create a preseed file named ks.preseed in the /opt/ubuntuiso directory to suppress other installation questions.

# echo 'd-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition \
select Finish partitioning and write changes to disk
d-i partman/confirm boolean true' > ks.preseed

Step 7: Set the Boot Command Line

Next, you need to set the boot command line to use the kickstart and preseed files. This can be done by editing the txt.cfg file in the isolinux directory.

# vi isolinux/txt.cfg

Add ks=cdrom:/ks.cfg and preseed/file=/cdrom/ks.preseed to the append line.

Step 8: Create a New ISO

Finally, you can create a new ISO using the mkisofs command:

# mkisofs -D -r -V "ATTENDLESS_UBUNTU" \
-cache-inodes -J -l -b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -o /opt/autoinstall.iso /opt/ubuntuiso

This command creates a new ISO with the specified options and saves it as /opt/autoinstall.iso.

Conclusion

That’s it! You have now created a CD or USB stick that will install Ubuntu on a headless machine without requiring any user input. This can be a great time-saver if you need to set up multiple machines or if you want to automate the installation process for consistency.

Remember to always test your automated installation in a controlled environment before deploying it to production. Happy automating!

What is a headless installation?

A headless installation refers to installing an operating system without a graphical user interface (GUI) or monitor connected to the machine. It is typically done remotely using command-line tools.

Why would I want to create a headless, unattended install of Ubuntu?

Creating a headless, unattended install of Ubuntu is useful when you need to set up multiple machines or want to automate the installation process for efficiency and consistency. It saves time and effort by eliminating the need for manual intervention during the installation process.

What is a Kickstart file?

A Kickstart file is a configuration file used by Red Hat-based distributions, including Ubuntu, to automate the installation process. It contains instructions and settings that specify how the system should be installed, such as partitioning, package selection, and user account creation.

How do I specify additional packages to be installed during the headless installation?

To specify additional packages, you can append a %packages section to the ks.cfg file. Inside the section, list the packages you want to install, each on a new line preceded by the @ symbol for package groups or the package name itself.

Can I customize the language used during the installation process?

Yes, you can customize the language used during the installation process. To prevent the language selection menu from appearing, create a file named lang in the isolinux directory of your Ubuntu ISO. Inside the file, add your desired language code, such as en for English.

How can I answer the installation questions without user intervention?

You can use a preseed file to answer the installation questions automatically. Create a preseed file named ks.preseed in the /opt/ubuntuiso directory and add the necessary configuration options. For example, you can specify the partitioning method, confirmations, and other settings in the preseed file.

How do I create a new ISO after making the necessary modifications?

To create a new ISO, use the mkisofs command with the appropriate options. The command should include options like -D, -r, -V, -cache-inodes, -J, -l, -b, -c, -no-emul-boot, -boot-load-size, -boot-info-table, and specify the output file path. This will generate a new ISO file with the modifications applied.

How can I test my automated installation before deploying it to production?

It is crucial to test your automated installation in a controlled environment before deploying it to production. You can set up a virtual machine or a spare machine to simulate the installation process and ensure everything works as expected. This allows you to identify and resolve any issues before deploying to production.

Leave a Comment

Your email address will not be published. Required fields are marked *