This page was vreated because I failed to find full manual of kickstart driven CentOS 7 USB installer.
The simplest way to create a customize Kickstart file that you can use it further for multiple installations is to manually perform an installation of RHEL/CentOS 7 and copy, after installation process finishes, the file named anaconda-ks.cfg, that resides in /root path, to an accessible network location, and specify the initrd boot parameter.
My intention was in putting all commands into script. Other manual for example tell you to use gparted of fdisk in order to fomrat USB drive. You can't use gparted in bash script.
Can we just dd CentOS image to USB stick and put kickstart file to USB?
- No, we can't. Kickstart failed to start.
References
Most of the instructions described below was found on the CentOS Wiki page on Installing from USB key.
USB key preparation
Partition USB
This can't be done as a disk image. As I described earlier kickstart failed to start. Below I will use /dev/sdX for the USB device.
- Create two partitions, one of type W95 FAT32 (LBA) of ~250MB, make this partition bootable. Create an ext4 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 to BOOT
- rename isolinux.cfg to syslinux.cfg
- I also deleted a several files from BOOT I didn't think were required, e.g. isolinux.bin, TRANS.TBL, upgrade.img, grub.conf.
- Copy kickstart file to the BOOT/isolinux directory and the CentOS 7 ISO to the DATA partition.
The final file structure looked something like this:
Edit the syslinux.cfg
Here is the install CentOS 7 entry from the Minimal ISO isolinux.cfg (which we renamed syslinux.cfg):
The append line should contain path to iso image and kickstart file.
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.
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
![Centos kickstart from usb Centos kickstart from usb](http://2.bp.blogspot.com/-hH5thx1ZHxw/Tb6WMk4Lx-I/AAAAAAAAAAs/_beDcPXmgd4/s1600/create_bootable_centos_redhat_usb_drive.png)
Sorry, this is a large file snippet that actually does include a post section. I recommend not trying to use as is. This is cut down from my full kickstart file, which is 10 times longer .
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