Search This Blog

Showing posts with label kickstart. Show all posts
Showing posts with label kickstart. Show all posts

2015-02-17

Kickstart Drive Mapping

Ordering of Storage Devices Messing up install

A problem that occurs commonly in kickstart is that kickstart will detect storage devices in a different order that which you intend the OS to install in.

This most commonly happens with Dell devices and virtual disks.

The Dell device will name its first virtual device /dev/sda which will cause installation problems when you try to specify that you want your kickstart installation to install on /dev/sda which is likely going to be one of Dell's virtual media devices.

A way to get around this is to create a kickstart script that looks at some criteria of physical devices first and then determines which drive to install to.

Finding Drive Mapping

http://www.redhat.com/archives/kickstart-list/2012-October/msg00014.html
https://access.redhat.com/solutions/273843
https://access.redhat.com/solutions/188463
https://access.redhat.com/solutions/58467
https://access.redhat.com/solutions/58561

Interactive Pre-Install to Test

https://stuffivelearned.org/doku.php?id=os:linux:centos:kspostscript
http://hintshop.ludvig.co.nz/show/interactive-pre-post-install-scripts-redhat-kickstart/

Example of My Partitioning Script


# Couldnt figure out how to make piping with while loop output work properly
# So I wrote to a temp file which seems to be the most compatible method of
# Performing while loop redirection in multiple shells
list-harddrives > /tmp/list-harddrives

# Loop to filter through attached HDDs and their sizes in MiB
# Will find the smallest disk larger than 15GB and set it as /
while read DISK DSIZE
do
DSIZE=$(echo "$DSIZE" | awk -F '.' '{print$1}')
if [ -z $rootDisk ]; then
rootDisk=$DISK
rootSize=$DSIZE
echo "Root Disk was unset and is now: $rootDisk"
fi

if [ $DSIZE -gt 143305 ]; then
if [ $DSIZE -lt $rootSize ]; then
rootDisk=$DISK
rootSize=$DSIZE
echo "Root Disk overriden due to smaller disk that meets requirements: $rootDisk"
fi
fi
done < /tmp/list-harddrives # Echo result out to console for debug echo "Root Disk: $rootDisk" # Create another temp file to feed into the kickstart later # It will choose the root disk that was previously figured out as the primary disk cat << EOF >> /tmp/partitioning
# Specify the bootloader as required for RedHat automated installation (--location=mbr is default)
bootloader --driveorder=${rootDisk}
# Without the 'zerombr' option specified, uninitiated disks will require manual intervention
zerombr
# To clear the existing partitions, use the clearpart option and include the --all parameter
clearpart --all --initlabel

# Create /boot partition (100MB is not large enough anymore so 500MB is used)
part /boot --size=500 --ondisk=${rootDisk}
# Create a pv to be used with LVM, start with 100MB partition and grow to the remaining size that is left on disk
# This will also ensure that we use the root disk we determined earlier specifically
part pv.01 --size=100 --grow --ondisk=${rootDisk}

# Add the previous pv to the volume group
volgroup VolGrp pv.01

# Carve out space in the volume group for /, swap, and /d2 (data)

# Root partition will always be 10GB
logvol / --vgname=VolGrp --size=10000 --name=Vol1
# Swap will be what is recommended by RedHat for each Distro (no guarantees on which disk)
logvol swap --vgname=VolGrp --recommended --name=Vol2 --fstype=swap
# d2 is the a data partition which will use any remaining space (no guarantees on which disk)
logvol /d2 --vgname=VolGrp --size=100 --name=Vol3 --grow
EOF


Reference for include scripts and multi-drive kickstart partitioning:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-preinstallconfig.html

2015-02-02

ESXi 5.1 PXE Install

ESXi PXE Install is very similar to any other kind of automated PXE deployment.

There are a few finicky components you'll have to deal with but overall it's fairly straight forward.

This is assuming you already have PXELINUX fully installed and configured along with DHCP and TFTP Server

  1. Download the ISO
  2. Mount the iso (I'm mounting in BSD)
  3. mdconfig -a -t vnode -f isoimage.iso -u 1 mount -t cd9660 /dev/md1 /mnt/iso/
  4. Create a directory to store the raw iso files
  5. mkdir -p /images/esxi/5.1/1065491/dell-a03/ I like to organize my images via. MajorVersion-Build-SpecialInfo
  6. Rsync the iso contents over
  7. rsync -av /mnt/iso/ /images/esxi/5.1/1065491/dell-a03/
  8. unmount the iso
  9. umount /mnt/iso mdconfig -d -u 1
  10. Create an "isolinux.cfg" file which basically is just used to point to the files required to boot up and run the kernel/kickstart files. This file will exist typically under the pxelinux.cfg directory either as the file called "default" or will match the mac-address of the machine you would like to image
  11. /images/kickstart/ESXI-5.1-1065491-dell-a03.ks DEFAULT install LABEL install KERNEL images/esxi/5.1/1065491/dell-a03/mboot.c32 APPEND -c images/esxi/5.1/1065491/dell-a03/boot.cfg MENU LABEL Dell ESXi-5.1-Update 1-1065491(A03) ^Installer As you can see mine is fairly simple with no menu.c32 as this file I dont want to have any options. I just want to copy this file over and have it boot up the correct references files ex. KERNEL $path to mboot.c32
  12. Modify the boot.cfg file so that it does not reference the tftp root directory thanks to http://brain.serenity-networks.com/networking-computers/vmware/esxi-5-5-5-pxe-installation-via-syslinux
  13. sed -e "s#/##g" -e "3s#^#prefix=/`basename $PWD`/\n#" -i.bak boot.cfg The above line will not only remove preceeding / it will also add a prefix= parameter where we can specify the path to our files.
  14. Then you will modify the prefix parameter with the path to your files on tftp. In my case it would be "/images/esxi/5.1/1065491/dell-a03/"
  15. bootstate=0 title=Loading ESXi installer prefix=images/esxi/5.1/1065491/dell-a03/ kernel=tboot.b00 kernelopt=ks=ftp://ftp/images/kickstart/scripts/ESXI-5.1-1065491-dell-a03.ks modules=b.b00 --- useropts.gz --- k.b00 --- chardevs.b00 --- a.b00 --- user.b00 --- s.v00 --- misc_cni.v00 --- net_bnx2.v00 --- net_bnx2.v01 --- net_cnic.v00 --- net_tg3.v00 --- scsi_bnx.v00 --- scsi_bnx.v01 --- net_bna.v00 --- scsi_bfa.v00 --- ima_be2i.v00 --- scsi_be2.v00 --- scsi_lpf.v00 --- net_igb.v00 --- net_ixgb.v00 --- scsi_mpt.v00 --- scsi_mti.v00 --- ima_qla4.v00 --- net_qlcn.v00 --- scsi_qla.v00 --- scsi_qla.v01 --- ata_pata.v00 --- ata_pata.v01 --- ata_pata.v02 --- ata_pata.v03 --- ata_pata.v04 --- ata_pata.v05 --- ata_pata.v06 --- ata_pata.v07 --- block_cc.v00 --- ehci_ehc.v00 --- weaselin.t00 --- esx_dvfi.v00 --- xlibs.v00 --- ipmi_ipm.v00 --- ipmi_ipm.v01 --- ipmi_ipm.v02 --- misc_dri.v00 --- net_be2n.v00 --- net_e100.v00 --- net_e100.v01 --- net_enic.v00 --- net_forc.v00 --- net_nx_n.v00 --- net_qlge.v00 --- net_r816.v00 --- net_r816.v01 --- net_s2io.v00 --- net_sky2.v00 --- net_vmxn.v00 --- ohci_usb.v00 --- sata_ahc.v00 --- sata_ata.v00 --- sata_sat.v00 --- sata_sat.v01 --- sata_sat.v02 --- sata_sat.v03 --- sata_sat.v04 --- scsi_aac.v00 --- scsi_adp.v00 --- scsi_aic.v00 --- scsi_fni.v00 --- scsi_hps.v00 --- scsi_ips.v00 --- scsi_meg.v00 --- scsi_meg.v01 --- scsi_meg.v02 --- scsi_mpt.v01 --- scsi_mpt.v02 --- scsi_rst.v00 --- uhci_usb.v00 --- tools.t00 --- dell_con.v00 --- xorg.v00 --- imgdb.tgz --- imgpayld.tgz build= updated=0

References:
Example kickstart config from yellow-bricks: http://www.yellow-bricks.com/2011/07/19/esxi-5-0-and-scripted-installs/
Kickstart valid parameters: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004582
Example kickstart from william lam: http://www.virtuallyghetto.com/2011/07/automating-esxi-5x-kickstart-tips.html
Blog to show how to structure boot.cfg: http://brain.serenity-networks.com/networking-computers/vmware/esxi-5-5-5-pxe-installation-via-syslinux/
Vmware documentation on PXE Install: https://pubs.vmware.com/vsphere-50/index.jsp#com.vmware.vsphere.install.doc_50/GUID-B9DB94CA-4857-458B-B6F1-6A688726AED0.html

2014-11-11

Network Ubuntu Install via PXE Using Preseed - Kickstart Alternative

Ubuntu has a method of automatic network installation similar to redhat's kickstart install.

It's called "debian-installer" and it is the recommended method of installing ubuntu automatically.

Similar to kickstart you have a preconfiguration file called "preseed" in which you answer questions asked by the installer.

You can either:
  1. Install ubuntu manually and export answers to questions
  2. Create answers to questions manually

#1 you can perform using:

# Generate a sample preseed.cfg with some default values you selected during manual install
apt-get install debconf-utils
debconf-get-selections --installer > preseed.cfg
debconf-get-selections >> preseed.cfg


Then you make this file available in the kickstart menu.

I've included a sample menu file (which points to the preseed) as well as the contents of a basic preseed file.
Menu File:

default linux

SERIAL 0 115200

label linux
kernel images/ubuntu/14.04/install/netboot/ubuntu-installer/amd64/linux
append initrd=images/ubuntu/14.04/install/netboot/ubuntu-installer/amd64/initrd.gz auto=true priority=critical interface=auto url=ftp://fbsd-ftp/images/ubuntu/14.04/preseed/sandvine.seed -- console=ttyS0,115200n8
IPAPPEND 2


Preseed File:

# Primary network interface:
d-i netcfg/choose_interface select auto

# Locale Configuration
d-i debian-installer/locale string en_US

# Set Keyboard to American English
d-i console-keymaps-at/keymap select American English
d-i debian-installer/keymap string us

# Set timezone
d-i time/zone string American/Toronto

# Do not make a user account
d-i passwd/make-user boolean false

# Assign the password for root
d-i passwd/root-password password sandvine
d-i passwd/root-password-again password sandvine

# Allow root login
user-setup-udeb passwd/root-login boolean true

# Partitioning
# Partition using LVM on the first and only detected disk
d-i partman-auto/method string lvm
# If one of the disks that are going to be automatically partitioned
# contains an old LVM configuration, the user will normally receive a
# warning. This can be preseeded away...
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean false
partman-lvm partman-lvm/device_remove_lvm boolean true
partman-lvm partman-lvm/confirm_nochanges boolean true
partman-lvm partman-lvm/confirm boolean true
unknown partman-lvm/confirm boolean true
partman-lvm partman-lvm/vgdelete_confirm boolean true

# Choose automatic partitioning recipes where automatic puts
# All configuration on the same partition
d-i partman-auto/choose_recipe select automic
# Complete partitioning without further confirmation
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

#Choose some additional packages to instal
d-i pkgsel/include string openssh-server


### Finishing up the installation
# During installations from serial console, the regular virtual consoles
# (VT1-VT6) are normally disabled in /etc/inittab. Uncomment the next
# line to prevent this.
d-i finish-install/keep-consoles boolean true

# Send command to pxeboot server to tell it to boot from HDD after imaging is successful
d-i preseed/late_command string /bin/echo "$(hostname -s)" | nc -w 3 lab-nfsbootlinux 2509

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note


Ubuntu does have support for kickstart but there are some important features that may not be fully featured in kickstart that are available in debian installer. Ubuntu even has system-config-kickstart utility to build kickstart files but because of the lack of full functionality it does not end up being as useful as the more fully funcitoning debian installer.

References:
Serial Console - http://blather.michaelwlucas.com/archives/638
Package Install (openssh) - http://www.stratuslab.eu/fp7/doku.php/tutoral:examplepreseed.html
Remove LVM Parts - http://ubuntuforums.org/showthread.php?t=1505174
Debian Example Preseed - http://d-i.debian.org/manual/example-preseed.txt
Ubutntu Example Preseed - https://help.ubuntu.com/lts/installation-guide/example-preseed.txt
Ubuntu 12.04 Preseed Explained - https://help.ubuntu.com/12.04/installation-guide/i386/preseed-contents.html
Ubuntu 10.04 Preseed example - https://help.ubuntu.com/10.04/installation-guide/example-preseed.txt
Generate a preseed - http://searchitchannel.techtarget.com/feature/Performing-an-automated-Ubuntu-install-using-preseeding
Puppet and Preseed - http://ghantoos.org/2012/10/21/cocktail-of-pxe-debian-preseed-ipmi-puppet/
Add Console and debug to menu - http://christian.hofstaedtler.name/blog/2008/09/debian-installer-preseeding-autostart-from-pxe.html
Ubuntu 14.04 install bug - http://www.michaelm.info/blog/?p=1378
What you need to append to menu - https://saz.sh/2011/07/30/preseed-debian-squeeze-using-pxe/
Create User Accounts - https://help.ubuntu.com/community/Cobbler/Preseed
Debian links:
https://www.debian-administration.org/article/394/Automating_new_Debian_installations_with_preseeding
https://www.debian.org/releases/wheezy/i386/apbs04.html.en
https://www.debian.org/releases/wheezy/i386/apbs03.html.en

Official Documentation:
http://www.debian.org/releases/stable/i386/apb.html.en
https://wiki.debian.org/DebianInstaller/Preseed
http://searchitchannel.techtarget.com/feature/Performing-an-automated-Ubuntu-install-using-preseeding
http://www.debuntu.org/how-to-unattended-ubuntu-deployment-over-network-page-5-preseed-file/

New Docs:
http://web.theurbanpenguin.com/auto-installing-ubuntu-16-04/
https://www.debian.org/releases/stable/example-preseed.txt
http://hands.com/d-i/

How to get a post-install command working:
http://www.50ply.com/blog/2012/07/16/automating-debian-installs-with-preseed-and-puppet/
https://ubuntuforums.org/showthread.php?t=1977570


2014-08-14

Boot Directly into New Kernel After Kickstart Install

It is useful to be able to boot directly into your freshly installed linux box immediately after installation.

However there are multiple different methods to going about doing this, both depending on which version of GRUB you are running, because the information you will require to make the next kernel load will depend on what you plan on booting next.

Both instructions will require the use of post-install scripts to pull data from the filesystem about next boot parameters.

First off, it's a good idea to get some debug going on your console screen, which can be done via the following:
%post
exec < /dev/console > /dev/console
echo "# Running Post Configuration #"
#....Do stuff....
echo "End of post-install steps"
References: http://blog.mozilla.org/jv/2011/01/31/redirecting-kickstart-prepost-over-serial-console/

GRUB 0.97

In GRUB 0.97 its fairly easy, you just grab the cmdline options (arguments) from the /boot/grub/grub.conf
cmdline=$(awk /kernel.*console/'{$1=$2=""; print$0}' /boot/grub/grub.conf)                       
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initramfs-$(uname -r).img --append="${cmdline}"
sleep 2                                                                                          
kexec -e                                                                                         

GRUB 2

In GRUB 2 its a bit more challenging as each GRUB menu is dynamically generated from /etc/grub2.cfg which points to /etc/grub.d/* files which have scripts that parse the underlying filesystem to locate kernels to dynamically build the grub menu
ls -lah /etc/grub.d/
total 80K
drwx------.  2 root root 4.0K Aug 12 13:16 .
drwxr-xr-x. 99 root root 8.0K Aug 12 20:09 ..
-rwxr-xr-x.  1 root root 8.5K Jun 30 12:16 00_header
-rwxr-xr-x.  1 root root 9.3K Jun 30 12:16 10_linux
-rwxr-xr-x.  1 root root  11K Jun 30 12:16 20_linux_xen
-rwxr-xr-x.  1 root root 2.5K Jun 30 12:16 20_ppc_terminfo
-rwxr-xr-x.  1 root root  11K Jun 30 12:16 30_os-prober
-rwxr-xr-x.  1 root root  214 Jun 30 12:16 40_custom
-rwxr-xr-x.  1 root root  216 Jun 30 12:16 41_custom
-rw-r--r--.  1 root root  483 Jun 30 12:16 README

By default linux grub menus are generated via /etc/grub.d/10_linux and take the defaults for cmdline options from /etc/defaults/grub

Grabbing the cmdline

cmdline=$(awk -F '"' '/GRUB_CMDLINE_LINUX/{print$2}' /etc/default/grub)

Grabbing the root Volume

I haven't figured out a dynamic way of grabbing the root volume yet so I just manually stuff in /dev/mapper/(volume-group-lv) in

Putting GRUB2 all together to kexec the kernel

%post                                    
exec < /dev/console > /dev/console       
echo "# Running Post Configuration #"                                                                                    
cmdline=$(awk -F '"' '/GRUB_CMDLINE_LINUX/{print$2}' /etc/default/grub)                                               
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initramfs-$(uname -r).img --append="root=/dev/mapper/VolGrp-Vol1 ro {cmdline}"                                                                                                               
sleep 2                                                                                                               
echo "Loading new Kernel"                                                                                             
kexec -e 
%end

2013-12-10

Change TTYs In Linux To Debug

I have found this useful while doing a kickstart install. Being able to change your terminal when an irrecoverable error shows up is very useful.

The way to get to other terminal types is to use a combination of: Ctrl+Alt+F-key

Here's the functions of some of them:
Ctrl+Alt-F1 - The installation dialog when using text or cmdline 
Ctrl+Alt-F2 - A shell prompt
Ctrl+Alt-F3 - The install log displaying messages from install program
Ctrl+Alt-F4 - The system log displaying messages from kernel, etc.
Ctrl+Alt-F5 - All other messages 
Ctrl+Alt-F7 - The installation dialog when using the graphical installer