📜 ⬆️ ⬇️

Ubuntu pre-configured automatic installation: isolinux and preseed

As you know, Ubuntu Linux has long been a complete set of tools required for the majority of office workers. And what does not, you can install, or run from the server, for example, using FreeRDP and Remmina . The result is cost savings and a strong simplification of customer administration. Many companies have already begun to slowly replace their fleet with thin clients and full-fledged computers with Linux. And if you also want to transfer a couple of departments to Ubuntu, then maybe I can help you save some time.

In this article, I will explain how to create a pre-configured, automatically installed system based on Ubuntu (as well as any modifications to it, including Ubuntu Sever ) or Debian . Having understood the very uncomplicated material described below, you can make your own Ubuntu builds with the applications and settings you need that can be installed in a fully automatic mode, both from disk and over the network. As a result, if you wish, you can achieve that it will be enough for you to simply turn on the computer and go and have tea to return to see the system installed and fully customized for your needs with all the software you need to work.

To begin with, this article contains several Ubuntu-specific things, but the general guidelines will be true for any distributions that can be used to install Debain Installer . In addition, I will not tell you how to configure the boot of computers over the network (for this you will need a TFTP server, which is usually 2 minutes to deploy) and will focus on booting from the disk. However, in the end I will still tell you how to apply all the described techniques for networked computer startup.

So, first you need to get the source image of the system with Debain Installer . Ubuntu Desktop LiveCD uses a different installer, so it’s not suitable for us. Any non-LiveCD disc from the Ubuntu family can be used absolutely safely. All further instructions are written for Ubuntu Alternate , although it is unlikely to be at least something different for other system options.

Work with iso

After you download the desired iso image, it will need to be unpacked. I use the following script for this:

#!/bin/bash BUILD=iso IMAGE=ubuntu-10.04-alternate-i386.iso #     rm -rf $BUILD/ mkdir $BUILD/ echo "** Mounting image..." sudo mount -o loop $IMAGE /mnt/ echo "** Syncing..." rsync -av /mnt/ $BUILD/ chmod -R u+w $BUILD/ 

After its execution, the entire image content will be in the iso directory. Then you can make the necessary changes and pack the image back. Immediately I will give a packing script:

 #!/bin/bash IMAGE=ubuntu-custom.iso BUILD=iso #   iso/   ubuntu-custom.iso echo ">>> Calculating MD5 sums..." rm $BUILD/md5sum.txt (cd $BUILD/ && find . -type f -print0 | xargs -0 md5sum | grep -v "boot.cat" | grep -v "md5sum.txt" > md5sum.txt) echo ">>> Building iso image..." mkisofs -r -V "Ubuntu OEM install" \ -cache-inodes \ -J -l -b isolinux/isolinux.bin \ -c isolinux/boot.cat -no-emul-boot \ -boot-load-size 4 -boot-info-table \ -o $IMAGE $BUILD/ 

MD5 recalculate the sums of all files necessary for the built-in disk integrity check to work.

Automate the installation process

Now you need to automate the installation process. To start the installer from disk, the isolinux bootloader is used, and this section is dedicated to its configuration. I will tell you about the features of network boot at the very end of the article

In the meantime, let's go in order. First of all, when you start your computer from the Ubuntu CD, you will be prompted to select a language. To prevent this request from appearing, you must create a file in the isolinux / folder with the name lang , the entire contents of which will represent the letter code of the desired language. For example, I have selected the Russian language in the lang file:


All available language options can be viewed in the isolinux / langlist file .

Next, you need the loader to automatically select the desired menu item after some waiting. In our case, this item will be an automatic installation. By default, Ubuntu waits for the user to select and takes no action. To change this behavior, you need to change the value of the timeout parameter in the isolinux / isolinux.cfg file to a non-zero value. The time is measured in tenths of a second; accordingly, in order to set a timeout of two seconds, this file should contain the following entry:

 timeout 20 

It remains only to choose which menu item will be launched by default. All menu items are set in the isolinux / text.cfg file , and we will change it now. For our automatic installation, we will create our own menu item called “OEM Install” in order to keep the usual installation options available. Immediately I must say that the installation process itself is controlled by the so-called preseed files, which lie in the corresponding directory on the disk. About them a little later, in the meantime, you can copy the description of any standard menu item, change its name and the name of the preseed file for it, as well as make it run by default. This is what I ended up with:

 default oem label oem menu label ^OEM install kernel /install/vmlinuz append file=/cdrom/preseed/oem.seed initrd=/install/initrd.gz quiet -- 

At this preparatory stage ends, it is now necessary to deal directly with the technology of preseed .


The preseed technology allows you to pre-specify the answers to questions asked during installation, thus removing the need to answer them manually. This allows you to create fully automatic scripts with all the necessary settings.

If you dig a little deeper, you can find out that the Debian Installer uses the debconf system to manage the installation process, and the preseed technology simply adds the necessary answers to the debconf database in advance. Thus, using preseed, you can configure not only the installer, but also other applications that use debconf , although this feature is unlikely to be useful to you.

Each preseed instruction usually consists of four parts: the owner, the name of the parameter, the type of the parameter, and the value. There must be exactly one space between the parts. The installer is named di , and it is this value that will appear in the first field in most instructions. There are three ways to set preseed instructions:
  1. Through the kernel startup options.
  2. Through the instructions downloadable on the network file with instructions.
  3. Through a local instruction file.
The first two methods are universal and suitable for any boot, the third one only works when installing from disk using isolinux .

There is another significant difference: the instructions passed through the kernel parameters are added to the database before the installer is launched, the instructions from the local file after setting the language and regional options, and the instructions from the network file after setting the network. Therefore, to make a fully automatic installer, in any case, you need to specify parameters for the kernel. Let's start with them.

It is necessary to slightly change the isolinux / text.cfg file , adding several loading options to our OEM Install item. As a result, you should get something like this:

 default oem label oem menu label ^OEM install kernel /install/vmlinuz append file=/cdrom/preseed/oem.seed debian-installer/locale=ru_RU.UTF-8 console-setup/layoutcode=ru localechooser/translation/warn-light=true localechooser/translation/warn-severe=true console-setup/toggle=Alt+Shift initrd=/install/initrd.gz quiet -- 

I think it is generally clear what the parameters are and what can be changed here. Now it only remains to create the main file with instructions for preseed , which, as you may have guessed, is called preseed / oem.seed in my case. Just want to note that the file parameter is used to transfer the file name to the installer. This option will only work when booting from a disk using isolinux , and in it you can use the / cdrom path to refer to the disk contents.

Here is the commented content of my preseed file:

 # Locales di debian-installer/locale string ru_RU.UTF-8 # Keyboard di localechooser/shortlist select RU di console-setup/ask_detect boolean false di console-setup/layoutcode string ru di console-setup/variant select  di console-setup/toggle select Alt+Shift # Network di netcfg/choose_interface select auto di netcfg/get_hostname string ubuntu di netcfg/dhcp_failed note di netcfg/dhcp_options select Do not configure the network at this time # Clock di clock-setup/utc boolean true di time/zone string Europe/Moscow di clock-setup/ntp boolean true # Users di passwd/root-login boolean true di passwd/make-user boolean true di passwd/root-password-crypted password $1$fbh0yv5L$qlugJUXOjNhiakQUYiJ7x0 di passwd/user-fullname string Ubuntu user di passwd/username string ubuntu di passwd/user-password-crypted password $1$fbh0yv5L$qlugJUXOjNhiakQUYiJ7x0 di user-setup/allow-password-weak boolean true di user-setup/encrypt-home boolean false # Partitioning di partman-auto/disk string /dev/sda di partman-auto/method string regular partman-auto partman-auto/init_automatically_partition select Guided - use entire disk partman-auto partman-auto/automatically_partition select di partman-auto/purge_lvm_from_device boolean true di partman/confirm_write_new_label boolean true di partman/choose_partition select finish di partman/confirm boolean true di partman/confirm_nooverwrite boolean true # GRUB di grub-installer/only_debian boolean true di grub-installer/with_other_os boolean true # APT di apt-setup/restricted boolean true di apt-setup/universe boolean true di apt-setup/multiverse boolean true di apt-setup/non-free boolean true di mirror/ftp/proxy string di mirror/http/proxy string # At last di finish-install/reboot_in_progress note tasksel tasksel/first multiselect ubuntu-desktop di preseed/late_command string mkdir /target/install/; cp -R /cdrom/extra/* /target/install/; chroot /target chmod +x /install/postinstall.sh; chroot /target bash /install/postinstall.sh 

In general, by the names of the options you can understand what they are responsible for, but I will comment on some interesting points.

First of all, keep in mind that in order to write scripts for automatic installation, you must clearly imagine the installation in manual mode, in particular, what questions, when and in what cases you have to answer. With preseed, you can set the system exactly the same as in the manual mode. The only limitation is that in the automatic mode it is impossible to install on sections already existing on the computer. In my scenario, I use the simplest approach to allocating space: cleaning and automatic partitioning for the system of the entire first hard disk.

In addition, during the automatic installation, you can use many features that are not available in manual mode. For example, you can set a password for root and create an unprivileged system user, as I have done, or you can use the default behavior and make the first user an administrator, giving him access to system settings via sudo . In the first case, you must set the passwd / root-login parameter to true and specify a password for root, in the second case, simply do not add this parameter to the preseed file. By the way, the password can be specified both explicitly (highly recommended) and in the form of a hash, similar to the hash in the / etc / shadow file. In the second case, you can set the desired password to some user on a running system, and then copy the password hash value for it from the / etc / shadow file to your preseed file. The hashes used in my file correspond to the password Passw0rd .

Most of the useful preseed options can be found in the official Ubuntu documentation . By the way, pay attention: in order to indicate in preseed scenarios answers to questions in which you need to choose one of several points, you just need to write the text of the desired item in English (in fact, you can only start, and you can not even in English, and on any). Therefore, if you know the name of the desired option, then you can put the system in manual mode and write the text of the desired value for this option, and then add its automatic configuration to your preseed file. In my scenario, for example, the value for the netcfg / dhcp_options parameter , which is responsible for actions in case of impossibility to configure the network automatically, is set in this way.

If you did not find the options you need in the documentation, you can install the system manually, and then immediately after the installation, execute the following two commands in the new system:

 sudo apt-get install debconf-utils sudo debconf-get-selections --installer > seedlog.txt 

As a result, you will receive in the seedlog.txt file all the values ​​from the debconf database that were used during the installation process. Among them, it is possible to find the parameters you need.

How to automate the installation process sort of figured out, now a little about how you can configure the installed system itself.

System Setup

First of all, pay attention, to indicate to the installer a set of packages to be installed over the base system, tasksel tasks are used . In the above script, I install the ubuntu-desktop task, i.e. Ubuntu desktop base system. How to change the list of installed packages and manage tasks tasksel , will be devoted to the following article. In the meantime, we will assume that we are quite satisfied with the basic Ubuntu and all we need is to configure it for our needs. By the way, Alternate disks of various Ubuntu variations contain a set of packages for just one specific task tasksel . That is, for example, on the Xubuntu Alternate disk there will be packages only for setting the xubuntu-desktop task, so it’s best to copy the job name for your preseed script from the standard file in the preseed / directory of your CD and not try to change it.

But how to set up the installed system? For these purposes, preseed provides the ability to execute an arbitrary command after the installation is completed. This command is specified in the preseed / late_command parameter and may contain a call to all basic utilities. At that, two special directories are available - / cdrom , which, as you can guess, refers to the contents of the installation disk, and / target , which refers to the root of the system already installed on the hard disk.

In order to change something in the installed system, you can use a simple trick - to enter this system using chroot and execute a previously prepared script. It should be borne in mind that no services will be started when entering through the chroot . Therefore, for example, you should not install packages in this way that require access to the MySQL server during the installation process.

My script contains the following command:

 mkdir /target/install/; cp -R /cdrom/extra/* /target/install/; chroot /target chmod +x /install/postinstall.sh; chroot /target bash /install/postinstall.sh 

As you can see, I create the install / directory in the root of the installed system and copy all the contents of the extra / folder from my disk into it, then run the postinstall.sh script for execution, having previously entered the new system using chroot .

The postinstall.sh script can contain anything, with the limitations described above. For example:

 #!/bin/bash #  APT.         . unset DEBCONF_REDIR unset DEBCONF_FRONTEND unset DEBIAN_HAS_FRONTEND unset DEBIAN_FRONTEND #     dpkg -i /install/debs/*.deb #       ubuntu cp -R /install/home/* /home/ubuntu/ cp -R /install/home/.config /home/ubuntu/ cp -R /install/home/.local /home/ubuntu/ cp -R /install/home/.gconf /home/ubuntu/ chown -R ubuntu:ubuntu /home/ubuntu chmod -R u+w /home/ubuntu 

So we learned how to create unattended installation scripts from disk and configure the installed system. In most cases, this is more than enough to create your own distributions for corporate needs. In the next article I will tell you how to change the standard tasks of a tasksel and install only what you need, as well as correctly add additional packages to the system.

Network installation using pxelinux

All of the above instructions can also be used to organize a network installation using the pxelinux bootloader. However, there will be several important differences:
  1. In addition to the language and keyboard options, preseed network configuration options will also have to be passed as explicit kernel parameters.
  2. You cannot use the file parameter in the kernel options to load a preseed file, you must use the url parameter instead. In addition, you can get the file name via DHCP, more about this in the official documentation.
  3. You cannot use the / cdrom directory in any preseed parameters, in particular, in preseed / late_command . Accordingly, the setup script and all the necessary data for it will also have to be downloaded over the network.
Otherwise, everything will be exactly the same as described above. The benefit of pxelinux is the brother of isolinux , designed for booting over the network, not from disk.

PS Everything was written from memory, maybe I forgot to mention something and explained something clearly. Therefore, any additions and comments are welcome.
PPS There will be a second article dedicated to modifying the repository on the CD and changing tasksel tasks to suit your needs.

Source: https://habr.com/ru/post/104029/

All Articles