Recently I was playing around with kickstart files. Kickstart files contains specification on how a CentOS (or RHEL) OS should be installed. For example, it may be used to specify the keyboard layout, the system language, the time zone, the disk partition, the network, etc. Basically it can set anything that you could set with the graphical installation interface. Feb 02, 2012 I changed out using the LiveCD for using DVD1 as the install image on the USB stick in hopes that Kickstart would be happy. My USB key partitions look like this: /dev/sdb1 on /media/CENTOS62 type vfat (rw,nosuid,nodev,uhelper=udisks,uid=500,gid=500,shortname=mixed,dmask=0077,utf8=1,flush).
None of what is written below is particularly original, however, I was unable to find a method documented on the internet at the time of writing that successfully created a kickstart driven CentOS 7 USB installer.
My interest was in doing this manually as I require this USB (image) to be created from a script. Therefore, I did not look into using ISO to USB applications - in addition, these typically do not allow custom kickstart files to be used.
References
Much of the process described below was found on the CentOS Wiki page on Installing from USB key, and from the Softpanorama page on the same subject. I thoroughly recommend reading all of the latter as it highlights the shortcomings/dangers associated with the steps below.
USB key preparation
Partition USB
This can probably be done as a disk image too, though I haven't tried this yet. Below I will use /dev/sdX for the USB device.
- Create two partitions, one of type W95 FAT32 (LBA) (assigned code 'c' in fdisk) of ~250MB, make this partition bootable. Create an ext3 partition from the remaining space.
- Format partitons
- Write MBR data to device
- Install syslinux to first parition
Copy files to USB
- Mount the partitions
- Copy DVD isolinux contents to
BOOT
- rename
isolinux.cfg
tosyslinux.cfg
- I also deleted a few bits from
BOOT
I didn't think were required, e.g.isolinux.bin
,TRANS.TBL
,upgrade.img
,grub.conf
. - I then copied my kickstart file to the
BOOT
directory and the CentOS 7 ISO to theDATA
partition.
The final file structure looked something like this:
Edit the syslinux.cfg
So that it points to the ISO and the kickstart
Here is the install CentOS 7 entry from the Minimal ISO
isolinux.cfg
(which we renamed syslinux.cfg
):The
append
line is changed to read the following:I suspect LABEL could be used here, rather than the enumerated device, which would make it safer, but I haven't tried this yet. Assuming the system you are installing on only has a single HD the USB key will be enumerated as sdb more information about this can be found in the Softpanorama article.
When you boot from the USB and select Install CentOS 7, it now installs the system as described by your kickstart.
I'm posting because, although there are some instructions on the wiki, I found a lot of misinformation/incorrect information while searching for a solution.Background:
I have a complicated kickstart file that gets generated through the jinja templating language and a build script. The system would completely build a dvd from the CentOS 6 or RHEL 6 DVD image. It would also auto populate the isolinux.cfg/grub files with all of the proper options I needed, including the kickstart lines.
The problem:
DVD's are slow to burn, and not editable. I wanted to be able, at a minimum, to modify the ks.cfg file(s) on the drive without rebuilding/copying everytime. I strugled with finding the right way to partition the USB drive, use the proper boot lines in the .cfg file, and not overwrite the USB drive itself. I found many 'solutions', none of which covered everything, and many which just were wrong or old.
The Solution:
There are a number of things that go into play here. I'm going to post up a snippet of the kickstart that includes the relevant bits. I'm not going to detail how you copy the iso files, modify repos, etc.. That's for a much longer thread!
This assumes you have done SOME research and probably done a DVD based kickstart before.
1. build your iso:
Build your iso however you want. However, you MUST run 'isohybrid' on the image after creation. I guess there are a few utilities that have that as an option now. using mkisofs does not. You may also wish to implant an md5sum into the image before proceeding.
2. Script to setup/format the USB drive
This function I have searches for any connected USB drives and prompts the user to select one. You could automated, etc... but the important parts are all here.
The most important part is the use of livecd-iso-to-disk from the livecd-tools package. I use it to format the drive and it then copies almost all the necessary files to the usb drive. note, it does NOT copy the kickstart files over. I believe that is due to the version of livecd-tools that I have from EPEL. I think newer ones support a ks option. However, for my situation, I have to copy over a complete directory of kickstart files, and my image can do multiple things.
![Kickstart Kickstart](http://2.bp.blogspot.com/-hH5thx1ZHxw/Tb6WMk4Lx-I/AAAAAAAAAAs/_beDcPXmgd4/s1600/create_bootable_centos_redhat_usb_drive.png)
Notes:
* livecd-iso-to-disk puts the syslinux/isolinux files in a directory called syslinux at the root of the primary partition.
* the boot images are also extracted from the iso and copied to a directory called 'images' at the root of the primary partition.
Tree for /dev/sdX
/dev/sdX
-/dev/sdX1
--yourcustom.iso
--syslinux
--images
3. Proper syntax for the isolinux.cfg lines:
wherever you have your dvd image mounted to, edit ~/path/to/isofiles/isolinux/isolinux.cfg by adding a line in as follows:
Code: Select all
The above is the basic way of telling anaconda where to look for the kickstart file(s) and where the install repo is to be found. Understand that using the hd: method requires an iso to be on the disc. not exploded file tree. /dev/sdX1 will be different on every single machine and could be different depending on how you partition the drive if you don't use my recommended method. i.e. you could have /dev/sdc as the location, or maybe /dev/sda2, etc....
For a truly automated install, your system cannot 'guess' and the drive name. Instead, use either the LABEL or UUID of the hd device:
note: you can use e2label or mlabel (depending on format of the drive) to relabel.
I have seen people reference the device in these lines in different ways. the above was the ONLY way I was able to get anaconda to find everything properly.
4. the kickstart pre section.
This is obviously very important. I'm only including the pre section for reference. Perhaps if I get crazy I'll come back and add a full file.
this file does a few things:
1. finds applicable boot drives and data drives
2. finds any removable usb drives in the system
3. sets up the clearpart and ignoredisk options
4. prevents overwrite of the usb drive
5. points to additional repos that are added to the disk (used createrepo to generate/regenerate repodata files)
6. appends the proper install 'option' to the system: cdrom or harddrive and uses the right install device.
note: the harddrive option is necessary, and the ks file should note have a 'cdrom' option listed.
The important functions listed in the ks file below are:
find_removable_drives_by_device
find_best_block_device_by_names
find_block_device_by_name
get_ks_device
find_usable_drives_for_clearpart
![Usb Usb](http://4.bp.blogspot.com/-X7KNYUfURxw/U6AxSspOg2I/AAAAAAAAEKM/uuN08iQDaZY/s1600/Screenshot+from+2014-06-17+08:13:49.png)
mykickstart.cfg
Code: Select all
7. Questions/issues/Etc:
* dd should still work, but you would have to change the ks= and hd= lines to get the partition name proper.
* what would another way to properly format a drive for this effort? using scriptable commands? fdisk?
* I had a problem with livecd-iso-to-disk after first formatting the drive with the '--format' command and then trying to use the same command 'without' formatting. The tool gave me a partition format error, that may have been fixed in current versions. I'd like to modify the build script so that I can pass in some options to the livecd tool to more dynamically determine when to format, when to not format, when to copy iso, when not to copy iso, etc...
* Security of the directories and the device should be set, which I'm not doing right now.
* need to convert this method to support using it as a Live USB device too.
* What needs to change for RHEL.7/CentOS 7? I haven't started testing yet, but need to.
Hope this helps someone!
-Drew