Skip to content

Instantly share code, notes, and snippets.

@szurcher
Last active September 12, 2021 09:56
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save szurcher/12a1546eb610e1e7ebb65b6feca468ac to your computer and use it in GitHub Desktop.
Save szurcher/12a1546eb610e1e7ebb65b6feca468ac to your computer and use it in GitHub Desktop.
CentOS 7 Minimal kickstart file and Packer config.json for building a vagrant virtualbox base box with guest additions installed. Based off of https://www.centosblog.com/centos-7-minimal-kickstart-file/
{
"builders": [{
"type": "virtualbox-iso",
"guest_os_type": "RedHat_64",
"iso_url": "[YOUR ISO PATH HERE]",
"iso_checksum": "[YOUR ISO CHECKSUM HERE]",
"iso_checksum_type": "sha256",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_wait_timeout": "1500s",
"boot_command": [
"<esc>",
"<wait>linux inst.ks=hd:/dev/fd0:ks.cfg<enter>"
],
"boot_wait": "5s",
"disk_size": 100000,
"floppy_files": [
"ks.cfg"
],
"hard_drive_interface": "sata",
"shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now",
"vboxmanage": [
["modifyvm", "{{.Name}}", "--memory", "1024"]
]
}],
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"sudo mkdir /media/VBoxGuestAdditions",
"sudo mount -o loop,ro /home/vagrant/VBoxGuestAdditions.iso /media/VBoxGuestAdditions",
"sudo /bin/sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run",
"sudo umount /media/VBoxGuestAdditions",
"sudo rmdir /media/VBoxGuestAdditions"
]
}],
"post-processors": [{
"type": "vagrant",
"keep_input_artifact": true,
"output": "centos_7_with_guestadditions.box"
}]
}
install
cdrom
cmdline
lang en_US.UTF-8
keyboard us
timezone Pacific/Honolulu
auth --useshadow --enablemd5
firewall --enabled --ssh --http
services --enabled=NetworkManager,sshd
eula --agreed
ignoredisk --only-use=sda
reboot
network --bootproto=dhcp --device=enp0s3 --onboot=on --hostname=[YOUR HOSTNAME HERE]
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part swap --asprimary --fstype="swap" --size=1024
part /boot --fstype xfs --size=200
part pv.01 --size=1 --grow
volgroup rootvg01 pv.01
logvol / --fstype xfs --name=lv01 --vgname=rootvg01 --size=1 --grow
rootpw --iscrypted [PUT PASSWORD CRYPT HASH HERE]
user --name=vagrant --iscrypted --password=[PUT PASSWORD CRYPT HASH HERE]
repo --name=base --baseurl=http://mirror.cogentco.com/pub/linux/centos/7/os/x86_64/
%packages --nobase --ignoremissing
@core
epel-release
dkms
kernel-devel
kernel-headers
make
automake
gcc
gcc-c++
bzip2
%end
%post
SUDOERS_FILE=sudoers
SSHD_CONFIG=sshd_config
cp /etc/${SUDOERS_FILE}{,.bak}
(
SUDOERS_FILE=sudoers
sed 's/^Defaults[[:space:]]\+requiretty/Defaults !requiretty/' /etc/${SUDOERS_FILE} > /tmp/${SUDOERS_FILE}
mv /tmp/${SUDOERS_FILE} /etc/${SUDOERS_FILE}
sed 's/^Defaults[[:space:]]\+!visiblepw/Defaults visiblepw/' /etc/${SUDOERS_FILE} > /tmp/${SUDOERS_FILE}
mv /tmp/${SUDOERS_FILE} /etc/${SUDOERS_FILE}
)
chown root:root /etc/${SUDOERS_FILE}
chmod 0660 /etc/${SUDOERS_FILE}
echo "vagrant ALL = (ALL) NOPASSWD: ALL" >> /etc/${SUDOERS_FILE}
(
mkdir /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
cd /home/vagrant/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > authorized_keys
chmod 0600 authorized_keys
chown vagrant:vagrant authorized_keys
cd /home/vagrant
chown vagrant:vagrant /home/vagrant/.ssh
)
(
SSHD_CONFIG=sshd_config
sed 's/^[[:space:]]*#*UseDNS[[:space:]]\+yes/UseDNS no/' /etc/ssh/${SSHD_CONFIG} > /tmp/${SSHD_CONFIG}
mv /tmp${SSHD_CONFIG} /etc/ssh/${SSHD_CONFIG}
)
chown root:root /etc/ssh/${SSHD_CONFIG}
chmod 0600 /etc/ssh/${SSHD_CONFIG}
%end
@joshuanutt
Copy link

Hey dude, I'm having an issue with the boot command portion of this.

"linux inst.ks=hd:/dev/fd0:ks.cfg"

Watching the VM I see it type those commands and starts running, but I still wind up on the Centos GUI installation screen.

I think the issue is something to do with the path, but I can't figure it out. I've tried:
inst.ks=hd:/dev/fd0:ks.cfg
inst.ks=hd:fd0:ks.cfg
inst.ks=hd:fd0:/ks.cfg

Any idea how to figure out what's going on??

@enuguris
Copy link

enuguris commented Mar 4, 2021

Hey dude, I'm having an issue with the boot command portion of this.

"linux inst.ks=hd:/dev/fd0:ks.cfg"

Watching the VM I see it type those commands and starts running, but I still wind up on the Centos GUI installation screen.

I think the issue is something to do with the path, but I can't figure it out. I've tried:
inst.ks=hd:/dev/fd0:ks.cfg
inst.ks=hd:fd0:ks.cfg
inst.ks=hd:fd0:/ks.cfg

Any idea how to figure out what's going on??

Add the line "text" in the kickstart config file that should solve the problem. If you want to avoid X then add skipx

@joshuanutt
Copy link

I switched it from .cfg to .ks for centos7

inst.ks=hd:fd0:/kickstart.ks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment