Tuesday, September 19, 2017

Part 2 Ubuntu Auto Installer

I forgot were I found this online, but here is how to use the ks.cfg file with an auto install...

1. Create Preseed file

Pressed commands work when they are directly written inside the Kickstart file, but I wanted to separate the two files. Create new file on you desktop named ubuntu-auto.seed with the following contents:
# 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
For additional Preseed configuration options, refer to official Ubuntu installation guide.

2. Extract original ISO image

Download Ubuntu Server 16.04 x64 from official Ubuntu website and put it on your desktop. It is necessary to use server version, because desktop version doesn't support unattended installations. Desktop functionality will work after ubuntu-desktop package in %packages section of kb.cfg file is installed.
Mount the .iso file to Ubuntu filesystem. The commands below will mount .iso file to the folder named ubuntu_iso:
cd ~/Desktop
mkdir ubuntu_iso
sudo mount -r -o loop ubuntu-16.04.1-server-amd64.iso ubuntu_iso
Copy .iso contents to another folder on your desktop so we can edit the files. Don't forget to set the right permissions to be able to make changes.
mkdir ubuntu_files
rsync -a ubuntu_iso/ ubuntu_files/
sudo chown ernestas:ernestas ubuntu_files
sudo chmod 755 ubuntu_files
sudo umount ubuntu_iso
rm -rf ubuntu_iso

3. Edit contents of ISO image

Copy ks.cfg, ubuntu-auto.seed and post.sh files to newly created ubuntu_files folder
cp {ks.cfg,ubuntu-auto.seed,post.sh} ubuntu_files
chmod 644 ubuntu_files/ks.cfg ubuntu_files/ubuntu-auto.seed
chmod 744 ubuntu_files/post.sh
Change isolinux folder and isolinux/txt.cfg permissions for editing:

chmod 755 ubuntu_files/isolinux ubuntu_files/isolinux/txt.cfg ubuntu_files/isolinux/isolinux.cfg

Now we need to make the installer read Kickstart and Preseed files by including new menu selection for automatic Ubuntu installation. To do this edit txt.cfg in isolinux folder:
nano ubuntu_files/isolinux/txt.cfg
Paste the following content right after the line containing default install:
label autoinstall
  menu label ^Automatically install Ubuntu
  kernel /install/vmlinuz

append file=/cdrom/preseed/ubuntu-server.seed vga=788 initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/ubuntu-auto.seed quiet --

Set timeout to start the installation automatically:
sed -i -r 's/timeout\s+[0-9]+/timeout 3/g' ubuntu_files/isolinux/isolinux.cfg
Warning! This command will start installation proccess immediately and format the hard drive as defined in ks.cfg. Skip it if you want to manually start the process after booting into ISO.
Change the permissions back:
chmod 555 ubuntu_files/isolinux
chmod 444 ubuntu_files/isolinux/txt.cfg ubuntu_files/isolinux/isolinux.cfg

4. Recreate ISO image

Create new .iso:

sudo mkisofs -D -r -V "ubuntu-auto" -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -input-charset utf-8 -cache-inodes -quiet -o ubuntu-auto.iso ubuntu_files/

Remove files:
sudo rm -rf ubuntu_files

5. Optional – Create bootable USB media

Make the .iso file bootable from external USB devices:
sudo apt-get install syslinux-utils
sudo isohybrid ubuntu-auto.iso
Plug in USB device and determine the path to it:
lsblk
My USB device was identified as /dev/sdb. Unmount the media:
sudo umount /dev/sdb
Copy ISO to USB device. Make sure to copy directly to the drive, not the first partition (/dev/sdb
1)

Be-careful that you only DD the USB Stick (that is blank) and not your HD or a different USB stick with data on it! As dd is a powerful low level system tool, use with extreme care.

sudo dd if=ubuntu-auto.iso of=/dev/sdb bs=4M && sync

6. Known Issues

8.1. USB doesn't mount as CD-ROM
Error message:
"Your installation CD-ROM couldn't be mounted. This probably means that the CD-ROM was not in the drive. If so you can insert it and try again."
Fix: Use dd to create bootable USB. Previuosly this error was caused by Ubuntu Startup Disk Creator.

No comments:

Post a Comment