Skip to content

Instantly share code, notes, and snippets.

@tfherbert
Created April 16, 2020 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tfherbert/1586fe4d33c3e475f9a41ba184bacd04 to your computer and use it in GitHub Desktop.
Save tfherbert/1586fe4d33c3e475f9a41ba184bacd04 to your computer and use it in GitHub Desktop.
create-bootable-CentOS-USB.sh
#/bin/bash
# build a small bootable USB from CentOS ISO.
#
# Run on Fedora or CentOS
#
#
# Build a bootable USB image to automatically install CentOS8 on
# a small X86_74 box such as a nuc variant.
# Uses a custom kickstart derived from installed system which can be
# customized further.
# Uses a custom isolinux which replaces the one in the original DVD which
# turns on serial console port, puts it in text mode install and uses a
# vnc.
#
MOUNT_PNT=/mnt/iso
CENTOS_DVD=/home/images/isos/CentOS-8.1.1911-x86_64-dvd1.iso
BOOTISO=/tmp/boot.iso
# Raw block device for USB stick.
DEVICE=/dev/sdx
sudo mount -o loop $CENTOS_DVD $MOUNT_PNT
ISO_TMPDIR=/tmp/isocopy
sudo rsync -av ${MOUNT_PNT}/ ${BOOT_DIR}
sudo rm -rf ${BOOT_DIR}/AppStream
udo cp -f kickstart/ks.cfg ${BOOT_DIR}
sudo cp -f isolinux/isolinux.cfg ${BOOT_DIR}/isolinux
sudo cp -f .treeinfo ${BOOT_DIR}
cd ${ISO_TMPDIR} && sudo mkisofs -o ${BOOTISO} -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -V "CentOS-8-1-1911-x86_64-dvd" -R -J -v -T isolinux/. .
sudo isohybrid ${BOOTISO}
sudo implantisomd5 ${BOOTISO}
sudo dd if=${BOOTISO} of=${DEVICE} bs=512 status=progress
--------------------------------kickstart file-----------------
kickstart:
cat kickstart/ks.cfg
#version=RHEL8
ignoredisk --only-use=sda
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Use text mode install
text
# Use CDROM installation media
cdrom
# Keyboard layouts
keyboard --vckeymap=us --xlayouts=''
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=enp1s0 --onboot=on --ipv6=auto
network --bootproto=dhcp --device=enp2s0 --onboot=on --ipv6=auto
network --bootproto=dhcp --device=enp3s0 --onboot=on --ipv6=auto
network --bootproto=dhcp --device=enp6s0 --onboot=on --ipv6=auto
network --bootproto=dhcp --device=enp8s0 --onboot=on --ipv6=auto
network --bootproto=dhcp --device=enp9s0 --onboot=on --ipv6=auto
network --bootproto=dhcp --device=enp3s0f0 --onboot=on --ipv6=auto
network --bootproto=dhcp --device=enp3s0f1 --onboot=on --ipv6=auto
network --hostname=vbg-Centos
# Root password
rootpw --iscrypted $6$RgZ/C1gpbknd3hFn$0QagR8s/bCKywhKLq.0tdm.wzc/P07wRHuCQ5Ez44gzvkcB53Wfu0vmNUoPTiKJyaXPUYUAhyyG.Bg8PObMr8.
# Run the Setup Agent on first boot
firstboot --enable
# Do not configure the X Window System
skipx
# System services
services --enabled="chronyd"
# System timezone
timezone America/New_York --isUtc
%packages
@^minimal-environment
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
---------------------------------------isolinux file-------------------
isolinux:
cat isolinux/isolinux.cfg
default vesamenu.c32
timeout 15
display boot.msg
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS Linux 8
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected item
menu color sel 0 #ffffffff #00000000 none
# Title bar
menu color title 0 #ff7ba3d0 #00000000 none
# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none
# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none
# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none
# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none
# Help text
menu color help 0 #ffffffff #00000000 none
# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none
# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux
menu label ^Install CentOS Linux 8
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-1-1911-x86_64-dvd inst.text vnc inst.ks=hd:LABEL=CentOS-8-1-1911-x86_64-dvd:/ks.cfg console=ttyS2,119200 console=tty0
label check
menu label Test this ^media & install CentOS Linux 8
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-1-1911-x86_64-dvd rd.live.check inst.text vnc inst.ks=hd:LABEL=CentOS-8-1-1911-x86_64-dvd:/ks.cfg console=ttyS2,119200 console=tty0
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshooting
menu title Troubleshooting
label vesa
menu indent count 5
menu label Install CentOS Linux 8 in ^basic graphics mode
text help
Try this option out if you're having trouble installing
CentOS Linux 8.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-1-1911-x86_64-dvd nomodeset inst.text vnc inst.ks=hd:LABEL=CentOS-8-1-1911-x86_64-dvd:/ks.cfg console=ttyS2,119200 console=tty0
label rescue
menu indent count 5
menu label ^Rescue a CentOS Linux system
text help
If the system will not boot, this lets you access files
and edit config files to try to get it booting again.
endtext
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS-8-1-1911-x86_64-dvd rescue inst.text vnc vnc inst.ks=hd:LABEL=CentOS-8-1-1911-x86_64-dvd:/ks.cfg console=ttyS2,119200 console=tty0
label memtest
menu label Run a ^memory test
text help
If your system is having issues, a problem with your
system's memory may be the cause. Use this utility to
see if the memory is working correctly.
endtext
kernel memtest
menu separator # insert an empty line
label local
menu label Boot from ^local drive
localboot 0xffff
menu separator # insert an empty line
menu separator # insert an empty line
label returntomain
menu label Return to ^main menu
menu exit
menu end
#.treeinfor file to replace the one on the release install DVD.
#
[checksums]
images/efiboot.img = sha256:c7f58721abc6447fdfa2eeba5659135d007c97cd4639b8a598a2ac6cc146784c
images/install.img = sha256:d6f8b80efe2b922f2708d60e1b3efd208b5e2e435e84b255f0e1e5c62ffe9ff2
images/pxeboot/initrd.img = sha256:2813def028c5bb62a08c45027dc055d0c082b5232ffe026046b56ce0f2941d35
images/pxeboot/vmlinuz = sha256:91e58e93a9bf4d05c7b189dca10e791f414a114154714f9b0ee8630aa8776653
[general]
; WARNING.0 = This section provides compatibility with pre-productmd treeinfos.
; WARNING.1 = Read productmd documentation for details about new format.
arch = x86_64
family = CentOS Linux
name = CentOS Linux 8
packagedir = BaseOS/Packages
platforms = x86_64,xen
repository = BaseOS
timestamp = 1578087691
variant = BaseOS
variants = BaseOS
version = 8
[header]
type = productmd.treeinfo
version = 1.2
[images-x86_64]
efiboot.img = images/efiboot.img
initrd = images/pxeboot/initrd.img
kernel = images/pxeboot/vmlinuz
[images-xen]
initrd = images/pxeboot/initrd.img
kernel = images/pxeboot/vmlinuz
[media]
discnum = 1
totaldiscs = 1
[release]
name = CentOS Linux
short = CentOS
version = 8
[stage2]
mainimage = images/install.img
[tree]
arch = x86_64
build_timestamp = 1578087691
platforms = x86_64,xen
variants = BaseOS
[variant-BaseOS]
id = BaseOS
name = BaseOS
packages = BaseOS/Packages
repository = BaseOS
type = variant
uid = BaseOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment