Re: Custom ISO with Kickstart and Local Repos

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



so all you're trying to do is add some packages and a kickstart file?

I don't use any external tools.  I add in the new packages into a directory at the top level of the disc image and modify the Packages directory if I need to.  then I run createrepo on each "package" directory

createrepo --update -d -g comps.xml ${repo}  trying to remember this, so verify it's correct.  if you want to use the comps/groups file, use the -g option, otherwise ignore it.

In my kickstart, I add in the additional package directories as new repos for yum to find the packages.  after adding ANY rpms, you will need to re-run createrepo on each folder and add them as repos in the ks file IF you want anaconda to be able to install them.  otherwise, you can mount in the post and run rpm commands directly on each command.

to get additional data off of the disc, you will also need to ensure you "mount" the disc/source somewhere the kickstart can access the data and your anaconda/isolinux options must be set correctly, so you have to get inst.ks and inst.stage2 setup properly.

inst.stage2=hd:LABEL=${DRIVELABEL} inst.loglevel=debug lang=en_US.UTF-8 keymap=us inst.ks=cdrom:/dev/cdrom:/ks/${ksname}.ks  

NOTE:  inst.stage2 uses a label designation.  this LABEL value MUST be exact.  When you generate your iso, usb drive, whatever, it MUST have the label exactly matching the DRIVELABEL value or it won't install.  Also, you can use inst.upgrade to point to an upgraded anaconda Product.img file which can contain rebrading/anaconda customizations.



Here's a kickstart snippet that covers a lot of ground:

"""""""
#PRE Section
  ksDeviceSource=$(sed 's/ /\n/g' /proc/cmdline | grep '^inst.ks='|cut -f1 -d:|cut -f2 -d'=')
  if (grep -q "ks=hd:LABEL" /proc/cmdline)
  then
    ksDeviceName=$(sed 's/ /\n/g' /proc/cmdline | grep '^inst.ks='|cut -f2 -d":" | cut -f2 -d"=")
    ksDeviceBaseName=`blkid -L $ksDeviceName`
    ksDeviceBaseName=`basename $ksDeviceBaseName`
  else
    #using a normal dev name, not a LABEL 
    ksDeviceName=$(sed 's/ /\n/g' /proc/cmdline | grep '^inst.ks='|cut -f2 -d":")
    ksDeviceBaseName=`basename $ksDeviceName`
  fi

  if [[ -z "${repo}" ]]; then
    #Are we using a usb drive?
    if [[ "${ksDeviceName}" == "hd" ]]; then
       repo="hd"
    else
      # If no repo was specified, then we must be installing from disc
      repo="cdrom"
    fi
  fi

  # Variable for the repo line:
  srcLoc="/tmp"
  # Mount the source repo
  mkdir -p /tmp/source
  repotype=$(echo "${repo}" | cut -d: -f1)
  if [[ "${repotype}" == "nfs" ]]; then
    source=$(echo "${repo}" | cut -d: -f2-)
    mount -t nfs -o nolock "${source}" /tmp/source
  elif [[ "${repotype}" == "cdrom" ]]; then
    echo "cdrom" >> /tmp/pre.ks
    # Re-bind the existing mount otherwise we'll get errors with some devices
    ### WARNING:  RHEL 7 anaconda now mounts to /run/install/repo.  /mnt/stage2 is gone.
    ###  it's possible that we no longer need to do this mount, but hey, then we'd have to change A LOT!
    mount --bind /run/install/repo /tmp/source
  elif [[ "${repotype}" == "hd" ]]; then
   echo "harddrive --partition=$ksDeviceBaseName --dir=/" >> /tmp/pre.ks
    # Re-bind the existing mount otherwise we'll get errors with some devices
    # I am not sure if we need to do the next mount with USB/HD.
    # NOTE:  the next line will not work if we expand to multiple iso(s).
    tmpDIR=$(mktemp -d)
    mount -L $ksDeviceName $tmpDIR
    mount -o loop $tmpDIR/imagename*.iso /tmp/source
    srcLoc="/tmp"
    #mount --bind /tmp/source /mnt/source
  fi


  #set the repos here.
cat << EOF > /tmp/repos.ks
repo --name="ELRepo" --baseurl=file://$srcLoc/source/ELRepo --cost=410000
repo --name="EPEL" --baseurl=file://$srcLoc/source/EPEL --cost=400000
repo --name="Extras" --baseurl=file://$srcLoc/source/Extras  --cost=500000
repo --name="Custom" --baseurl=file://$srcLoc/source/Custom --cost=500000

repo --name="Optional" --baseurl=file://$srcLoc/source/Optional --cost=350000
repo --name="Supplementary" --baseurl=file://$srcLoc/source/Supplementary --cost=360000
repo --name="Workstation" --baseurl=file://$srcLoc/source/Workstation --cost=330000
repo --name="Packages" --baseurl=file://$srcLoc/source/Packages --cost=300000
EOF

########## End Pre Section ############
####Post section######

# This is the First Post script,
  # copy things that are needed in chrooted Posts to where they can be found.
  source /tmp/cmdline  #you won't use these three lines probably
  cp -p /tmp/cmdline /mnt/sysimage/tmp/cmdline
  cp -p /tmp/cmdline /mnt/sysimage/root/cmdline


  # Re-mount the source for the post-scripting
  {{ m.export_cmdline() }}  #This is a JINJA operator, you would need to add in the mount command here if not using JINJA

  ksDeviceSource=$(sed 's/ /\n/g' /proc/cmdline | grep '^ks='|cut -f1 -d:|cut -f2 -d'=')

  if (grep -q "ks=hd:LABEL" /proc/cmdline)
  then
    ksDeviceName=$(sed 's/ /\n/g' /proc/cmdline | grep '^ks='|cut -f2 -d":" | cut -f2 -d"=")
    ksDeviceBaseName=`blkid -L $ksDeviceName`
    ksDeviceBaseName=`basename $ksDeviceBaseName`
  else
    #using a normal dev name, not a LABEL
    ksDeviceName=$(sed 's/ /\n/g' /proc/cmdline | grep '^ks='|cut -f2 -d":")
    ksDeviceBaseName=`basename $ksDeviceName`
  fi

  if [[ -z "${repo}" ]]; then
    #Are we using a usb drive?
    if [[ "${ksDeviceName}" == "hd" ]]; then
       repo="hd"
    else
      # If no repo was specified, then we must be installing from disc
      repo="cdrom"
    fi
  fi


  # Mount the source repo
  mkdir -p /tmp/source
  repotype=$(echo "${repo}" | cut -d: -f1)
  if [[ "${repotype}" == "nfs" ]]; then
    source=$(echo "${repo}" | cut -d: -f2-)
    mount -t nfs -o nolock "${source}" /tmp/source
  elif [[ "${repotype}" == "cdrom" ]]; then
    echo ""
    #TODO: this is a legacy item that needs removed.... later
    #mount $(cat /tmp/source) /tmp/source
  elif [[ "${repotype}" == "hd" ]]; then
    tmpDIR=$(mktemp -d)
    mount -L $ksDeviceName $tmpDIR
    #at this point, /tmp/isodir is the device that is mounted.  useit!
    mount -o loop $tmpDIR/imagename*.iso /tmp/source
  fi



  # Make the source repo available in the chroot
  mkdir -p /mnt/sysimage/tmp/source
  mount --bind /tmp/source /mnt/sysimage/tmp/source
"""""""""""""##### End Post Section ##########


here's the genisoimage command:
genisoimage -r -v \
     -V "LABELNAME.x86_64" -A "${label}" -cache-inodes -J -l \
     -b isolinux/isolinux.bin -c isolinux/boot.cat \
     -no-emul-boot -boot-load-size 4 -boot-info-table \
     -o "${isoLocation}${filename}" disc


  pushd ${isoLocation} >> /dev/null
  # if you want to use a usb drive, then next part is mandatory:
  #make sure the iso is bootable on USB devices
  isohybrid ${filename}
  implantisomd5 ${filename}


Apparently, you can use xorriso, which contains an argument for running isohybrid.

hope that helps.  All of this stuff for building your own respun disc is available online.  
Such as:
https://devopsmates.com/make-custom-centos-7-rhel-7-cd-kicktart-file/
http://www.smorgasbork.com/2014/07/16/building-a-custom-centos-7-kickstart-disc-part-1/

use livecd tools or dd to make a custom bootable disc/usb drive.


Andrew Simpson

On Thu, Feb 22, 2018 at 11:07 PM, Vinícius Ferrão <ferrao@xxxxxxxxxxxxxxxxxx> wrote:
Firas, thank you.

That’s appears to be exactly what I need.

I’ll be doing some test tomorrow and report back.

V.

> On 22 Feb 2018, at 22:40, Firas Alshafei <Firas.Alshafei@xxxxxxxxxx> wrote:
>
> V,
>
> If you're adding rpms then you'll need to update the repo to actually include them. I'm not familiar with Lorax so I can't really help there, but if your end goal is  a standard RHEL dvd with extra packages that you want to define in your kickstart configuration then it should just require createrepo and genisoimage.
>
> My use case is fairly vanilla kickstart you might have to modify to suit your workflow.
> - isolinux and efi use the inst.ks and inst.stage2 to point to kickstart file and installation source respectively.
> - kickstart file and pre/post/conf scripts in DVD/kickstart directory structure
> - Packages in the default DVD/Packages and additional packages in /DVD/Packages-Extra
> - I delete all uneeded packages to reduce DVD size, just feed the rpm -qa output on an installed system to yumdownloader
>
> Here's a script stub - I do something similar in-house to get our DVDs created for air-gapped environments (it's a pain).
> Hope this helps 😊
>
> #!/bin/bash
> #===================================================================================
> # Title        : create-iso
> #
> # Description  : Generate kickstart dvd
> #
> # Author       : Firas AlShafei
> #
> # Last Revised : 11/04/2015
> #
> #===================================================================================
>
> # Assume following path structure
> #
> # working-directory
> # |
> # ---> creat-iso.sh
> # |
> # ---> media (DVD media + kickstart + additional packages)
>
> # Path variables
> scriptPath=$(dirname "$(readlink -f "$0")")
> isoPath=${scriptPath}
> releaseName="my-awesome-dvd.iso"
>
> # Move repo group info
> mv ${scriptPath}/media/repodata/*-comps-Server.x86_64.xml ${scriptPath}/media/repodata/comps-Server.x86_64.xml
>
> # Create repo
> cd ${scriptPath}/media
> createrepo --quiet --pretty --update --groupfile repodata/comps-Server.x86_64.xml .
>
> # Make ISO file
> echo "== Generate DVD Image"
> echo "= ${isoPath}/${releaseName}.iso"
> genisoimage -r -T -J -V ${releaseName} \
> -quiet                                \
> -o ${isoPath}/${releaseName}.iso      \
> -no-emul-boot                         \
> -boot-load-size 4                     \
> -boot-info-table                      \
> -b isolinux/isolinux.bin              \
> -c isolinux/boot.cat                  \
> -eltorito-alt-boot                    \
> -no-emul-boot                         \
> -b images/efiboot.img                 \
> ${scriptPath}/media/
>
>
>
>
> Firas AlShafei
> Senior Lead Engineer
> Enterprise Software
> ABB
>
> -----Original Message-----
> From: kickstart-list-bounces@redhat.com [mailto:kickstart-list-bounces@xxxxxxxxxx] On Behalf Of Vinícius Ferrão
> Sent: Thursday, February 22, 2018 3:47 PM
> To: kickstart-list@xxxxxxxxxx
> Subject: Custom ISO with Kickstart and Local Repos
>
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
>
> Hello,
>
> I’m trying to create a custom ISO with a Kickstart file to achieve a complete offline installation.
>
> I was able to create the Kickstart file as usual, since I use it for PXE installs for at least 10 years, but the major problem now is building the ISO with the necessary files.
>
> I’ve came across a tool named Lorax, but I was not able to create a custom ISO from DVD’s. It only works when point to mirrors, and this is a time consuming task. Another problem is that Lorax does not seems to care about the /usr/share/lorax/product folder to create a custom Anaconda with the embedded kickstart file on /usr/share/anaconda/interactive-defaults.ks.
>
> The small ISO generated by Lorax lacks local repositories and I was unable to find the appropriate documentation on how to build this scenario. So it generates a boot only install that must be done over the Internet.
>
> At this moment I’m running Lorax on a CentOS install, I’ve got RHEL licenses too, but to keep it simple I just went with CentOS. I think this is irrelevant information but it’s just for the sake of completion.
>
> With genisoimage I was able to add the custom product.img file, that I’ve generated by hand with cpio, on the ISO but I was not able to solve the local repos problem. There are packages that I would like to add to the install media, like Ansible, but they are available only on the Extras repository and I’m unsure on how to do this. Just wondering if createrepo and yumdownloader are necessary...
>
> Any help is greatly appreciated.
>
> Thanks,
> V.
>
>
> _______________________________________________
> Kickstart-list mailing list
> Kickstart-list@xxxxxxxxxx
> https://emea01.safelinks.protection.outlook.com/?url="">https%3A%2F%2Fwww.redhat.com%2Fmailman%2Flistinfo%2Fkickstart-list&data="">7Cfiras.alshafei%40us.abb.com%7C61f459f9ce2a4501b84d08d57a3dede1%7C372ee9e09ce04033a64ac07073a91ecd%7C0%7C0%7C636549328763319165&sdata=ryv0YW%2FzOdUplRFSLABdNkRZN%2BZKBJwKVw5CaSDJfRk%3D&reserved=0
>
> _______________________________________________
> Kickstart-list mailing list
> Kickstart-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/kickstart-list


_______________________________________________
Kickstart-list mailing list
Kickstart-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/kickstart-list

_______________________________________________
Kickstart-list mailing list
Kickstart-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/kickstart-list

[Index of Archives]     [Red Hat General]     [CentOS Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux