Custom Slax Bootable OS

From TheBeard Science Project Wiki
Revision as of 13:26, 9 October 2019 by Beard (talk | contribs) (Customization Script)

Jump to: navigation, search

Slax is an amazing Linux distro! This is the first time I've found a tolerable workflow for generating custom bootable Linux images, on the fly, for different purposes. Slax has all the features that I want as a base system for custom images, and it comes with scripts that make it easy to roll your changes into modules, which you can then incorporate into a new disk image. It's super fast and super easy.

Everything that I wanted:

  • Debian based
  • Minimal lightweight base OS
  • Simple bootloader
  • Fast and easy build process

Purpose of this example build:

  • Lightweight utility OS for general IT work (including Windows systems)

Customizations I've made:

  • Added Memtest86+ to the boot menu
  • Made the OS boot to text mode by default
  • Installed several recovery, diagnostic, and security packages
  • Replaced the desktop wallpaper with a flat color
  • Removed the startup/shutdown sound

File Downloads

Filename Description Size Modified Link

gen-slax-custom.sh

My own script for generating a custom Slax image. 4K 9/30/2019

Download

Procedure

First, download Slax from the website: https://slax.org

In this tutorial, I am using version 9.11.0 (64 bit).

I used VirtualBox to set up a VM for generating the custom Slax image: https://www.virtualbox.org/

Be sure to have hardware virtualization enabled in your BIOS (Intel VT-x or AMD-V). Even when I tried to build a 32 bit version of Slax, the build process froze without hardware virtualization enabled.

I created a new VM with these properties:

  • 2G of RAM
  • 8G virtual disk (dynamic expanding)
  • Network connection "Bridged"

Boot it up and select the "slax-64bit-9.11.0.iso" image. It will now boot into a graphical desktop.

You can right-click anywhere on the desktop and select "Terminal".

One way or another, you will need to get the custom script gen-slax-custom.sh onto the guest OS. I'll assume you have the script located in your home folder on another machine that has SSH enabled (where the IP address is 10.1.2.2).

scp user@10.1.2.2:/home/user/gen-slax-custom.sh $HOME/

Now just run the script:

bash gen-slax-custom.sh

There will be several prompts after the script runs:

  • Select a timezone
  • Confirm packages to be installed
  • Choose whether non-superusers can capture packets (Wireshark)
  • Choose whether Macchange should automatically change the MAC Address on boot
  • Confirm overwriting disk partition (only prompts if your virtual disk already had a partition)

This will take several minutes to run. When it's done, your final disk image should be located in: /mnt/slax-custom64-build<DATE>.iso

Copy the image file off of the guest OS any way you want. You can copy it to you SSH server like before:

scp /mnt/slax-custom64-build<DATE>.iso user@10.1.2.2:/home/user/

When you boot up the custom image, you will be no longer be dropped into a graphical desktop. You now get a text terminal with a login prompt.

As it says on the screen, the login name is root and the password is toor.

If you want to go into the graphical desktop, you can run the command startx. To exit the desktop, open a terminal and run killall Xorg.

You can now burn the image to a CD or DVD. If you want to create a bootable USB flash drive, follow the instructions here: https://www.slax.org/starting.php

Customization Script

Custom script gen-slax-custom.sh (download here):

# ================================================================
#
# GENERATE CUSTOM SLAX BOOTABLE ISO
#
# This was created with Slax 9.11.0 (64 bit)
# Source: http://ftp.sh.cvut.cz/slax/Slax-9.x/slax-64bit-9.11.0.iso
#
# Boot up the live Slax image in a virtual environment, create a
# virtual disk that is at least 3G attached to the VM, copy this
# script onto that VM, then run this script (needs network
# connection).
#
# The /mnt directory is used for temporary build files.
#
# The final image will be located in:
# /mnt/slax-custom64-build<DATE>.iso
#
# When you boot the custom image, you can hit Tab at the
# bootloader, and there is several boot options. There is now an
# Entry for Memtest86+.
#
# When you boot into the OS, you will get a text terminal. Login
# as Username: root, Password: toor
#
# If you want a graphical desktop, run the command "startx".
#
# ================================================================
#

#
# Set the time zone
# ================================================================
dpkg-reconfigure tzdata

#
# Enable SSH Server
# ================================================================
systemctl enable ssh

#
# Install packages
# ================================================================
apt-get update
apt-get -y install binutils chntpw cifs-utils clamav curl dnsutils etherwake ffmpeg gddrescue gparted iftop john macchanger memtest86+ nmap ntfs-3g parted rar recordmydesktop rsync smbclient ssh sshfs stress sudo tcpdump telnet testdisk tmux traceroute unrar vim wireshark

#
# Replace the desktop wallpaper with flat color
# ================================================================
apt-get -y install imagemagick
convert -size 1x1 xc:gray /usr/share/wallpapers/slax_wallpaper.jpg
apt-get -y purge imagemagick
apt-get autoremove
apt-get autoclean

#
# Remove startup/shutdown sound files
# ================================================================
rm /usr/share/sounds/*.wav

#
# Partition the disk and create a file system
# ================================================================
echo -e "n\np\n1\n\n\n\nw\n" | fdisk /dev/sda
mkfs -t ext4 /dev/sda1
tune2fs -m 0 /dev/sda1

#
# Mount the disk
# ================================================================
umount /dev/sda1
mount /dev/sda1 /mnt

#
# Delete the shell history
# ================================================================
echo > ~/.bash_history
history -c

#
# Save the custom module
# ================================================================
savechanges /mnt/custom.sb

#
# Generate the temp ISO
# ================================================================
genslaxiso /mnt/slax-temp.iso /mnt/custom.sb

#
# Create the temp folders for working with the ISO file
# ================================================================
mkdir /mnt/isomount
mkdir /mnt/isotemp

#
# Mount the ISO file and copy into the temp folder
# ================================================================
mount -t iso9660 -o loop /mnt/slax-temp.iso /mnt/isomount
cp -R /mnt/isomount/* /mnt/isotemp/
umount /mnt/slax-temp.iso
rm /mnt/slax-temp.iso

#
# Move memtest86+ to the boot folder and rename it (required)
# ================================================================
mv /boot/memtest86+.bin /mnt/isotemp/slax/boot/memtest86
rm /boot/memtest86+_multiboot.bin

#
# Set the text mode as the default boot option
# ================================================================
sed -i 's/perch,automount/&\ text/g' /mnt/isotemp/slax/boot/syslinux.cfg

#
# Add Memtest86+ to the boot menu
# ================================================================
echo -e "\nLABEL memtest86\nMENU LABEL Memtest86+ (Test RAM)\nKERNEL /slax/boot/memtest86" >>/mnt/isotemp/slax/boot/syslinux.cfg

#
# Generate the final ISO file
# ================================================================
cd /mnt/isotemp/
dt=$(date +%y%m%d%H%M%S)
genisoimage -o /mnt/slax-custom64-build$dt.iso -b slax/boot/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V Slax .

Links