CentOS 7 kickstart file

The minimal CentOS 7 kickstart file I could come up with for my requirements. Enjoy.

install
lang en_GB.UTF-8
keyboard uk
poweroff
timezone UTC
auth  --useshadow  --passalgo=sha512
selinux --disabled
firewall --disabled
services --enabled=NetworkManager,sshd
eula --agreed
rootpw --plaintext password
ignoredisk --only-use=sda
bootloader --location=mbr --timeout=0
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

repo --name=base --baseurl=http://mirror.centos.org/centos/7/os/x86_64
repo --name=updates --baseurl=http://mirror.centos.org/centos/7/updates/x86_64
url --url="http://mirror.centos.org/centos/7/os/x86_64"

%packages --nobase --ignoremissing
@core
augeas
%end


%post --log=/root/postinstall.log

# Do the bare minimum so that I can ssh to the box and run a shell script to execute whatever provisioning needs happening

mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6hE75Ox6wDfXVJzXeKdyUBO4o19TtGxboJTI2vR3CE9ZJbODIxSr+tfMZcwmuSF892PiahhVzAA2wJ6LdMtFH6FUIGvjU0i7jIo/x+TmvheH46N9qllo2C2ZlxL/HbpRYIyqEntUYcBQzYBvUwnzoDFgS1GhG4LalYp0U9zlHGOA/Wk7qBjH8Ca1mtPSnxudsb/NwERIjfLbvdX9Fc+vkx6fs3ykJv+p8lPEZkw3kcVAfuyhnXzE7kprSHDuOuQo0FDvCTjy9ISxZPvExKT7bD7vQRlrx9PLzYSWI7/evonWHR8c/jPS8U56ii8YH/rtC/iqo4LiwKFxoxaDdS2wD joaocosta@zonalivre.org" > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys


augtool -s <<EOF
#root login needs to be enabled during initial setup so the project specific scripts can be executed
set /files/etc/ssh/sshd_config/PermitRootLogin yes

#This saves time during vm startup
set /files/etc/grub.conf/timeout 0

#Removed because otherwise user install scripts can't use sudo
rm /files/etc/sudoers/Defaults[requiretty]
EOF

%end
CentOS 7 kickstart file

qemu disk format autodetection

Lets say you use qemu like this:

sudo qemu-system-x86_64 \
    -hda system.raw	\
    -hda data.raw

In recent versions of qemu, you might see this error message:

WARNING: Image format was not specified for 'system.raw' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.

To avoid the warning and remove the restriction on block 0 write operations, do what the error message suggests and explicitly set the disk file format to raw, ie:

sudo qemu-system-x86_64 \
    -drive file=system.raw,format=raw,index=0,media=disk \
    -drive file=data.raw,format=raw,index=1,media=disk

Happy qemuing!

qemu disk format autodetection

Choosing a domain registrar

For a long time I’ve registered my domains with godaddy. They were recommended by a friend back in the early 00’s, and they worked well enough, but there have always been a few gotchas that made using the service unpleasant:

  • Heavy UI, required more work than needed to get things done. To be fair, they have improved this over the time.
  • Constant up selling of things I don’t need.
  • Bait tactic of charging for a cheap one year domain, only to be hit with a high renewal fee the year after.

Still, for a relatively light domain registrar user like myself, those kinks weren’t really enough to justify the trouble of moving.

Until recently a couple of my domains came up for renewal, and I finally decided it was time to try something different. My first port of call was reddit.com, and as usual, they didn’t disappoint. The site is packed full of threads discussing domain registrars. Out of these, a gem came out.

https://domcomp.com/ is a service that allows you to compare different domain registrars. It’s pretty cool, if you are shopping for a domain registrar, you should definitely check it out.

I like the ability to compare prices for different .TLDs and purchase options (New, Renew, Transfer), while the discussions on reddit gave me a general idea of what kinds of features/service levels to expect.

After some research, I’ve narrowed it down to either namecheap or namesilo and will transfer a domain or two to try them out.

Choosing a domain registrar

Redirect STDOUT/STDERR

Sometimes you want to redirect your shell script’s STDOUT/STDERR to a log file. This is pretty simple to do, ie:

./myscript.sh &> output.log

But sometimes you want to do the redirect inside the script itself ( ie, maybe redirecting is conditional, or maybe the file name is conditional on something only the script knows about)


#!/bin/bash

exec >> output.log
exec 2>&1

>&2 echo "This was printed to stderr"
echo "This was printed to stdout"

Or if you want to write to both a file and the terminal:

#!/bin/bash

exec 1> >(tee -a output.log)
exec 2>&1

>&2 echo "This was printed to stderr"
echo "This was printed to stdout"

Stackoverflow has other ways to do it:

Redirect STDOUT/STDERR

How to rotate pdf pages permanently

You scan a document, only to find out it’s upside down. You could head to the scanner again and get some movement into your body, but you’re not sure which way to orient the page. Here’s how to do it from your computer instead.

  1. Open the file in Adobe Reader
  2. Choose the menu option View->Rotate View->Clockwise
  3. Choose the menu option File->Print
  4. Choose to print to a PDF driver.  This is native in Windows 10.
  5. If you don’t have a PDF printer driver, try this one: http://www.cutepdf.com/products/cutepdf/writer.asp
How to rotate pdf pages permanently

Wait for a file in bash

Sometimes your bash script needs to wait for a file to exist before proceeding. Here is one way to do it.

function wait_till_exists {
    file=$1
    timeout=${2:-60}
    counter=1
    until ls -l $file &amp;&gt; /dev/null
    do
        if [ $counter -gt $timeout ]; then
            return 1
        fi
        sleep 1
        ((counter++))
    done
    return 0
}

wait_for_file="/tmp/myfile"
if ! wait_till_exists "$wait_for_file" 5; then
    echo Timed out waiting for $wait_for_file to exist
exit 1
fi

echo "$wait_for_file found"
Wait for a file in bash