Monday, July 21, 2014

Customizing Redhat/Oracle Linux CDROMs, ISOs and USBs - Part 1

Redhat/Oracle Linux custom CDROMs, ISOs and USBs can be very useful... They speed up server installation with predefined kickstart files; they reduce distributions to the few hundreds of MB you really need; they provide easy customization for configurations that are not supported by anaconda's initial setup program or your distribution (e.g. here) and they might be enhanced with additional RPMs and custom scripts. This few posts demonstrate how to modify Oracle Linux ISOs and how to use them.

Obviously if you are dealing with a large number of servers and VMs, using RPM repositories with PXE, xenpvnetboot or templates is the way to go. But if you are dealing with only a few VMs on your laptop or with manual server installation, custom ISOs are simple and very fast. You can literally create one in less than 10 minutes. This first part will be presenting how to customize an ISO with a simple kickstart file. It will be using the Oracle Linux 7 Early Adopter ISO but other Redhat Based distributions and other releases are not much different...

Extracting the distribution

In order to customize the distribution, you must download it and extract its content to a directory; we will use a directory named OL7 below:
mkdir /tmp/iso

sudo mount -o loop \
     linux/OracleLinux-R7-U0-Server-x86_64-dvd.iso \
     /tmp/iso
[sudo] password for gregory: 
mount: /dev/loop0 is write-protected, mounting read-only

mkdir OL7
sudo cp -Rp /tmp/iso/* OL7
sudo umount /tmp/iso

Adding a kickstart file

To customize the ISO, add a kickstart file to the root of the distribution. You should be able to manage most aspects of the installation from that file and the various kickstart directives. If you don't, you should even be able to deploy and execute custom scripts. Below is an example of a configuration file that:
  • perform the installation from the CDROM
  • configure the first available network link with DHCP
  • change the keyboard to french
  • define the root password as manager
  • disable SELinux
  • set the timezone
  • erase the content of /dev/sda and install Linux on it with the default layout
  • avoid running the initial setup program
  • shutdown the server once the installation done
cd OL7
sudo cat ks.cfg 
install
cdrom
lang en_US.UTF-8
keyboard fr
network --onboot yes --device link --bootproto dhcp --noipv6
rootpw manager
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Europe/Paris --isUtc --nontp
bootloader --location=mbr --boot-drive=sda
text
skipx
zerombr
clearpart --all --initlabel
autopart
firstboot --disabled
poweroff
 
%packages
@base
@core
%end

Customizing the boot menu

You can add a menu in the isolinux/isolinux.cfg file so that you can boot with the kickstart file as a parameter. Add the section below to the file:
label auto
  menu label Oracle Linux 7.0 ^Kickstart install
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.ks=cdrom:/ks.cfg inst.stage2=hd:LABEL=OL-7.0\x20Server.x86_64 
Note 1:
Don't forget to remove the menu default directive from the menu it is attached to; If you want to speed up the installation, you can also change timeout 600 to timeout 100
Note 2:
It's important you reference the disk label in the inst.stage2 as you will name it when creating the ISO file.

Rebuilding the ISO

To end with the process, create the ISO from the directory you've been working with, i.e. OL7:
sudo  mkisofs -r -T -J -V "OL-7.0 Server.x86_64" \
    -b isolinux/isolinux.bin -c isolinux/boot.cat \
    -no-emul-boot -boot-load-size 4 -boot-info-table \
    -o /tmp/OracleLinux7.iso OL7/

sudo implantisomd5 /tmp/OracleLinux7.iso
checkisomd5 /tmp/OracleLinux7.iso
Note:
If you don't have access to the command above, make sure the genisoimage and isomd5sum RPMs have been installed on your system.

Testing your ISO

Last but not least, you can test your new installation as well as the associated options:

Bibliography
Redhat Enterprise Linux 7
Installation Guide
Chapter 23. Kickstart Installations

1 comment:

  1. We found that using 'inst.ks=cdrom:/ks.cfg' doesn't always work when for example the iso is on a usb or there are multiple cdroms. Instead we used something like this ''inst.ks=hd:LABEL=OL-7.0\x20Server.x86_64:/ks.cfg' which works in those cases too.

    ReplyDelete