Fedora + Docker
I needed a way to create a custom fedora linux distribution that ran on USB flash drive in a single command that was easy to do. I knew there were ways to create installers, but I needed to automate the actual installation as well.
Live CDs
I looked into Live CD creation an I accepted this as a possible solution. I had created custom distributions before, but I did not want to have to relive my youth or reinvent the wheel. Surely, this is something that system administrators battle with all the time. Surely even AWS engineers have to automate image creation somehow. It would be a huge pain if not.
Anaconda/kickstart
First, I found this documentation on creating live images. I found that kickstart is the tool I needed to use. There is a lot of kickstart documentation out there, but none of it was really useful. What really helped me was that there are a lot of examples included in the spin-kickstarts
and fedora-kickstart
packages.
What I did was I just created a docker image FROM fedora:27
and I exported the kickstart examples. Here is what I ended up with.
Customization
I started with a number of images just trying to get one to build and then boot. Just ran docker to build my image:
docker run --rm -v $PWD/conf:/kickstarts --privileged=true r351574nc3/docker-kickstart:latest livecd-tools.ks
It would dump an image in my $PWD/conf
path. I could then use qemu
to see if it even started:
qemu-system-x86_64 -cdrom <isoimage>
Many times, it would not even start until I found a good base image that worked. I ended up using
%include fedora-disk-base.ks
Then, I defined my basics
part / --size 6144 --fstype ext4
services --enabled=sshd,NetworkManager,chronyd
network --bootproto=dhcp --device=link --activate --onboot=on
bootloader --timeout=1
rootpw --iscrypted --lock $1$1PAq/71w$cJGAbLaOx2dVXMtsK39mO1
I wanted a specific partition size and I wanted to make sure sshd
was installed at startup. It was important to me also that the operating system selfboot and run headless.
Packages
Next, I wanted to minimize the size of my build as much as possible. I was going to run on a USB flash drive, so I did not need a lot of bloat. I also wanted a base X11 system.
%packages
@base-x
-@guest-desktop-agents
-@fonts
-@input-methods
-@dial-up
-@multimedia
-@printing
# install tools needed to manage and boot arm systems
-@arm-tools
-uboot-images-armv7
# save some space
-mpage
-sox
-hplip
-numactl
-isdn4k-utils
-autofs
# smartcards won't really work on the livecd.
-coolkey
# scanning takes quite a bit of space :/
-xsane
-xsane-gimp
-sane-backends
I also made sure I had all the system administration tools I expected. Some of the tools are actually needed for building kernel modules. I had need to build custom DKMS for GPU mining, so I include that as part of the build.
# install the default groups for the server evironment since installing the environment is not working
@server-product
@standard
@headless-management
-initial-setup-gui
-generic-release*
@development-tools
@admin-tools
@system-tools
@text-internet
@python-web
# Explicitly specified here:
# <notting> walters: because otherwise dependency loops cause yum issues.
kernel
kernel-devel
kernel-modules
kernel-modules-extra
Then, I added tools I would need to build the live cd including anaconda which is the automated installer and syslinux for the bootloader.
# The point of a live image is to install
anaconda
@anaconda-tools
# Without this, initramfs generation during live image creation fails: #1242586
dracut-live
grub2-efi
syslinux
Finally, I had some additional customization for the OpenCL requirements:
# Libraries for ethminer
ocl-icd-devel
clinfo
-beignet
-pocl
-mesa-libOpenCL
%end
was used to wrap up the %packages
section.
Custom Scripts
I created a %post
section which I won't really talk about because what I did was specific to GPU mining; however, I will say that in this section, this is the real meat. You can configure things you can't do through package installation. You can setup systemd
services to run automatically. You can setup first-time boot parameters. You can also create users here. There are a lot of things you can configure here. This is what sets your distribution apart from others.
Next Steps
The .ks
file is the main parameter to the docker image, so you can change it as you see fit. My next steps are to generate a .ks
file. I would like to create a template file that I can process through a tool like jinja and have tokens in the file replaced like usernames, etc... This way, I do not need to rely on users making modifications to the file to construct their image. Instead, I can automate it and just offer a few basic (wizard) questions to the user.