Sometimes, when the installation of an operating system is carried out regularly on different servers and virtual machines, for a System Administrator, there is a need to automate these actions.
Therefore, by creating an image of an unattended installation (the entire process applies to Ubuntu, Debian, and most other Linux systems), the System Administrator:
- speeds up the installation process,
- eliminates possible random errors in the regular installation process,
- excludes the routine components of daily procedures,
- Creates a component for application in the following stages of automation of IT operational processes for Ansible, Chef, and Puppet.
To make an unattended silent bootable ISO of a customized version of Ubuntu, pre-installed running Linux, where on local disk should be stored source ISO of the operating system. The whole process, simplified, consists of the following stages:
-
unpacking of ISO in a separate directory,
-
editing contents of the unpacked image,
-
creation of a new image of ISO with the modernized system contents.
Below are the details:
1. Unpacking of ISO in a separate directory
As the initial operating system is taken as a basis the LTS-Ubuntu-server (at the moment, it is 16.04 LTS), – this edition is the most stable for productive usage, is updated for five years, as much as possible, is suitable for further continuous use, without a need to upgrade a final ready image.
Unpack it in any directory locally on a disk for a further example will be used ~/ubuntu/.
wget http://releases.ubuntu.com/14.04/ubuntu-14.04-server-amd64.iso
Mount Ubuntu ISO so that the contents can be copied to another directory and then edit the pertinent files:
mkdir -p /mnt/iso
mount -o loop ubuntu.iso /mnt/iso
As a next step, copy the ISO files to another directory for editing;
mkdir -p ~/ubuntu
cp -rT /mnt/iso ~/ubuntu
2. Editing contents of the unpacked image
Create or update the following files:
- ~/ubuntu/ks.cfg,
- ~/ubuntu/ks.preseed,
- ~/ubuntu/isolinux/lang,
- ~/ubuntu/boot/grub/grub.cfg,
- ~/ubuntu/isolinux/txt.cfg
Set the language to English:
echo en >~/ubuntu/isolinux/lang
Create a preseed file with the following content:
echo '
# Unmount drives with active partitions. Without this command, all the installation process would stop and require confirmation to unmount drives that are already mounted. d-i preseed/early_command string umount /media || true # Don't install recommended items d-i preseed base-installer/install-recommends boolean false # Install only security updates automatically d-i preseed pkgsel/update-policy select unattended-upgrades'>~/ubuntu/ks.preseed
Next, create a kickstart file that will configure Ubuntu during the installation (make sure you change the username part, and you should use encrypted passwords). Here, it’s possible to declare all packages that should be in the final system. All disk space will be automatically partitioned and formatted to use all possible space:
echo '
#System language lang en_US #Language modules to install langsupport en_US #System keyboard keyboard us #System mouse mouse #System timezone timezone Europe/Berlin #Root password rootpw --disabled #Initial useruser USERNAME --fullname "USERNAME" --password "PASSWORD"
#Reboot after installation reboot #Use text mode install text #Install OS instead of upgrade install #Use CDROM installation media cdrom #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record zerombr yes #Partition clearing information clearpart --all --initlabel #Disk partitioning information part /boot --fstype ext4 --size 512 part swap --size 2048 part / --fstype ext4 --size 1 --grow #System authorization infomation auth --useshadow --enablemd5 #Network information network --bootproto=dhcp --device=eth0 #Do not configure the X Window System skipx # Additional packages to install. %packages @ ubuntu-server openssh-server # Turn on Wake-on-LAN ethtool -s eth0 wol g'>~/ubuntu/ks.cfg
Another file to edit – the grub configuration file so when the ISO performs an EFI boot, the bootloader uses the suitable options to use the preseed and configuration files:
echo '
if loadfont /boot/grub/font.pf2 ; then set gfxmode=auto insmod efi_gop insmod efi_uga insmod gfxterm terminal_output gfxterm fi set menu_color_normal=white/light-blue set menu_color_highlight=light-blue/light-gray set timeout=10 set default=0 menuentry "Automatically Install Ubuntu Server with Custom Config" { set gfxpayload=keep linux /install/vmlinuz file=/cdrom/preseed/ubuntu-server.seed quiet ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed -- initrd /install/initrd.gz } menuentry "OEM install (for manufacturers)" { set gfxpayload=keep linux /install/vmlinuz file=/cdrom/preseed/ubuntu-server.seed quiet oem-config/enable=true -- initrd /install/initrd.gz } menuentry "Multiple server install with MAAS" { set gfxpayload=keep linux /install/vmlinuz modules=maas-enlist-udeb vga=788 initrd=/install/initrd.gz quiet -- initrd /install/initrd.gz } menuentry "Check disc for defects" { set gfxpayload=keep linux /install/vmlinuz MENU=/bin/cdrom-checker-menu quiet -- initrd /install/initrd.gz } menuentry "Rescue a broken system" { set gfxpayload=keep linux /install/vmlinuz rescue/enable=true -- initrd /install/initrd.gz } '>~/ubuntu/boot/grub/grub.cfg
Edit the isolinux boot menu for non-EFI booting (MBR booting) to use the custom config and custom press:
echo '
default install label install menu label ^Install Ubuntu Server with Custom Config kernel /install/vmlinuz append debian-installer/locale=en_US keyboard-configuration/layoutcode=us languagechooser/language-name=English localechooser/supported-locales=en_US.UTF-8 file=/cdrom/preseed/ubuntu-server.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed quiet splash noprompt noshell -- label cloud menu label ^Multiple server install with MAAS kernel /install/vmlinuz append modules=maas-enlist-udeb vga=788 initrd=/install/initrd.gz quiet -- label check menu label ^Check disc for defects kernel /install/vmlinuz append MENU=/bin/cdrom-checker-menu vga=788 initrd=/install/initrd.gz quiet -- label memtest menu label Test ^memory kernel /install/mt86plus label hd menu label ^Boot from first hard disk localboot 0x80 '>~/ubuntu/isolinux/txt.cfg
3. Creation of a new image of ISO with the modernized system contents.
Create the ISO: sudo mkisofs -U -A "ubu16LTS" -V "ubu16LTS" -volset "ubu16LTS" -J -joliet-long -r -v -T -o ../ubu16LTS.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot
In conclusion, verify the ISO has the correct style boot catalogues:
dumpet -i ~/
ubu16LTS.iso
And hence the output:
Validation Entry:
Header Indicator: 0x01 (Validation Entry)
PlatformId: 0x00 (80x86)
ID: ""
Checksum: 0x55aa
Key bytes: 0x55aa
Boot Catalog Default Entry:
Entry is bootable
Boot Media emulation type: no emulation
Media load segment: 0x0 (0000:7c00)
System type: 0 (0x00)
Load Sectors: 4 (0x0004)
Load LBA: 3100 (0x00000c1c)
Section Header Entry:
Header Indicator: 0x91 (Final Section Header Entry)
PlatformId: 0xef (EFI)
Section Entries: 1
ID: ""
Boot Catalog Section Entry:
Entry is bootable
Boot Media emulation type: no emulation
Media load address: 0 (0x0000)
System type: 0 (0x00)
Load Sectors: 4672 (0x1240)
Load LBA: 1932 (0x0000078c)
Finally, the image ran in Virtualbox, creating a completely unattended install.
As a result, the above ISO image could be used with Ubuntu systems deployment on physical servers or virtual platforms.