Slackware universal install USB

Last Sunday, after upgrading my old netbook (ASUS Eee PC 900) from Debian Wheezy to Jessie, I decided to try Debian Jessie Live on my laptop. Unfortunately, the provided image couldn’t boot in UEFI environment, so I had to switch booting mode from UEFI to legacy. After playing with the distro for a while (it had problems with my wireless card’s drivers), I changed the booting mode back to UEFI and rebooted. To my surprise, there wasn’t Slackware option in the boot menu anymore. It looks like changing the booting mode changes something in UEFI settings. Anyway, I needed my Slackware, so I booted my rescue USB with Parted Magic. It was a bit dated (version from June, 2014), maybe that’s why efibootmgr (v0.5.3) refused to work with my laptop’s UEFI firmware. At least I confirmed that my ELILO files were intact in EFI partition, so all I needed was efibootmgr to add an option to the boot menu. Somehow I didn’t think about booting into Windows 8.1, which I also have on my laptop, to add a boot option to UEFI, but if I did that it wouldn’t be so interesting, would it?

So I decided to use what I thought was the next best thing to Parted Magic: Slackware installation image. Unfortunately, I didn’t have one on my USB stick, neither I had any blank DVDs, so I had to download an entire Slackware tree and then use alienBob’s usbimg2disk.sh script. I could just download the script and mini ISO, but I also wanted to have a stick that I could use to install Slackware without Internet connection. What I noticed was that alienBob’s script didn’t make the stick bootable in UEFI, although the EFI directory was there, just not in the root of the stick. I moved it, fixed paths to the kernel and ramdisk in elilo.conf and was finally able to boot from it and bring back Slackware option to the laptop’s boot menu.

Then I thought about submitting a patch for usbimg2disk.sh script that would also make the USB stick bootable in UEFI environment, but then it stroke me that wasn’t necessary, because Slackware tree already had EFI directory, so I could’ve just copied the whole tree to the stick and be able to boot from it. While thinking all of that, and after inspecting alienBob’s script itself I had an idea: I should make two partitions on my USB stick: the first partition for any data I want to carry, the second one will be bootable with Slackware installer and packages on it. And so I did. The result was a USB stick that would be usable in Windows and be able to install OS. I tested booting on my laptop and netbook. It worked on them both. Then I realised, that while I used syslinux from Slackware64, I was still able to boot the installer on 32 bit netbook.

And the day after (today, actually), while I was at work (it’s slow days, so I don’t have much, if anything, to do) I thought: I should make both 32 and 64 bit Slackware available from one USB stick! When I came home, I did just that: I copied the package tree for the 32 bit system to the second partition of my stick, I copied the necessary kernels, renamed kernels for the 64 bit installer, edited /syslinux/syslinux.cfg to include all kernels, removed syslinux’s EFI directory, from the stick’s filesystem’s root, copied EFI directory from the Slackware64’s tree, edited grub.cfg in the same manner as syslinux.cfg, and that was it! Now I have a USB stick that can boot anywhere (as long as the machine supports booting from USB, which means the majority of PCs made at least in the last seven years).

The story aside, that’s how I did it:

  1. Get a USB stick with at least 8 Gb of space (both versions of Slackware’s packages will take about 4.3 Gb).

  2. Make two partitions (optional, you can make just one) using fdisk, parted or whatever. You don’t have to make the stick a GPT disk, regular MBR will do just fine, as UEFI doesn’t care about the partition table on the removable media. Don’t forget to format them in FAT32. Or FAT16, it doesn’t really matter if you don’t plan to have big files on the stick. Make the second partition bootable/active (boot flag).

  3. Get the Slackware tree for both 32 and 64 bit versions. I used rsync mirror for that, you can use FTP or HTTP mirrors. The command I used was rsync -aPSH --delete rsync://mirror.yandex.ru/slackware/slackware64-14.1 ./ (for Slackware64, obviously). You can choose the mirror you like here.

  4. Copy slackware and slackware64 directories from the trees you just downloaded to the root of the second partition on your stick.

  5. Issue mount -o loop,ro /path/to/slackware64-14.1/usb-and-pxe-installers/usbboot.img /mnt/tmp. Then make directory called syslinux on the second partition on your stick. Copy everything from /mnt/tmp (or wherever you mounted the image) to that syslinux directory. Rename huge.s to huge64.s and initrd.img to initrd64.img. Unmount the image: umount /mnt/tmp. Mount the same image from 32 bit tree, copy only huge.s, hugesmp.s and initrd.img from it to syslinux directory on your stick. You don’t need to rename them, but, you know, whatever.

    Come to think of it, you don’t need to mount these USB images, you can just grab kernels and ramdisks from the kernels and isolinux directories respectively in the Slackware tree. Just don’t forget to rename the kernels from bzImage to something else, like names mentioned above.

    …Actually, no, you need to mount at least one of the images, because it contains all the necessary configuration for syslinux. Of course, you could just copy the stuff from isolinux directory (isolinux and syslinux are basically the same) in the Slackware tree, but that would require a bit more editing.

  6. Remove ldlinux.sys from the syslinux directory. Issue syslinux -s -d /syslinux /dev/sdb2. This won’t do anything but create ldlinux.sys file, which is syslinux itself, and write bootloader in the beginning of the partition.

  7. Issue dd if=/usr/share/syslinux/mbr.bin of=/dev/sdb MAKE SURE /dev/sdb CORRESPONDS TO YOUR USB STICK!!! It won’t actually touch your partition table, only bootloader info, but better safe than sorry. What this does is it records instruction to search for the bootloader in the active partition on the disk. Remember the partition we made bootable in step 2? This is why.

  8. Copy EFI directory from the top of the slackware64-14.1 tree to the top of the second partition on your stick. Or you can use the EFI directory from syslinux directory, but I would prefer to have a menu, because ELILO is a bit obscure when it comes to choosing a boot option.

  9. Edit /EFI/BOOT/grub.cfg and /syslinux/syslinux.cfg to include all the necessary kernels there. I’ll post my configs later in the post.

And you are done! EFI loader is set up (EFI directory is there with correct grub.cfg), MBR loader is set up (syslinux with correct syslinux.cfg), the first partition is untouched and can be used to store files from both Linux and Windows, the second partition is invisible in Windows and can be used to boot and install both 32 and 64 bit versions of Slackware.

It’s not much for such wall of text, it can be figured out easily, but I still wanted to share my findnings.


/syslinux/syslinux.cfg:

default hugesmp.s
prompt 1
timeout 1200
display message.txt
F1 message.txt
F2 f2.txt
label huge.s
  kernel huge.s
  append initrd=initrd.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 nomodeset SLACK_KERNEL=huge.s
label hugesmp.s
  kernel hugesmp.s
  append initrd=initrd.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 nomodeset SLACK_KERNEL=hugesmp.s
label kms.s
  kernel huge.s
  append initrd=initrd.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 SLACK_KERNEL=huge.s
label kmssmp.s
  kernel hugesmp.s
  append initrd=initrd.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 SLACK_KERNEL=hugesmp.s
label huge64.s
  kernel huge64.s
  append initrd=initrd64.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 nomodeset SLACK_KERNEL=huge.s
label kms64.s
  kernel huge64.s
  append initrd=initrd64.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 SLACK_KERNEL=huge.s
label memtest
  kernel memtest

/syslinux/message.txt:

Welcome to "Slackware" version 14.1 (Linux kernel 3.10.17)!

If you need to pass extra parameters to the kernel, enter them at the prompt
below after the name of the kernel to boot (huge.s etc).

In a pinch, you can boot your system from here with a command like:

boot: hugesmp.s root=/dev/sda1 rdinit= ro

In the example above, /dev/sda1 is the / Linux partition.

To test your memory with memtest86+, enter memtest on the boot line below.

This prompt is just for entering extra parameters.  If you don't need to enter
any parameters, hit ENTER to boot the default kernel "hugesmp.s" or press [F2]
for a listing of more kernel choices.  Default kernel will boot in 2 minutes.

/syslinux/f2.txt:

                 -+  Kernel Selection Help +-

You'll need one kernel to get Linux started on your system so that you can
install it.  The default kernel is hugesmp.s, which requires at least a
Pentium III processor. If this kernel doesn't work for you, you may try
the regular "huge.s" kernel, which supports i486 and better single CPU
machines. If you have a 64bit CPU (at least Athlon64), you can use
huge64.s to install Slackware64.

To boot the chosen kernel put the name of the kernel and press enter.

boot: hugesmp.s   "For example, boot the 'huge.s' kernel!"
boot: kmssmp.s    "To boot with kernel mode setting for graphics -- needed
                   with some machines."
boot: huge64.s    "Same as hugesmp.s, but for x86_64 arch."
boot: kms64.s     "Same as kmssmp.s, but for x86_64 arch."

To check your system memory with memtest86+, use 'memtest':

boot: memtest

/EFI/BOOT/grub.cfg:

set default="0"
set timeout="30"
set hidden_timeout_quiet=false

#if loadfont /EFI/boot/unicode.pf2; then
#  set gfxmode=800x600
#  load_video
#fi

#terminal_output gfxterm

menuentry "Slackware 14.1 hugesmp.s kernel"{
  echo "Loading hugesmp.s kernel and installer initrd.  Please wait..."
  linux /syslinux/hugesmp.s vga=normal load_ramdisk=1 prompt_ramdisk=0 ro printk.time=0 nomodeset SLACK_KERNEL=huge.s
  initrd /syslinux/initrd.img
}

menuentry "Slackware 14.1 hugesmp.s kernel (use KMS console)"{
  echo "Loading huge.s kernel (with KMS) and installer initrd.  Please wait..."
  linux /syslinux/huge.s vga=normal load_ramdisk=1 prompt_ramdisk=0 ro printk.time=0 SLACK_KERNEL=huge.s
  initrd /syslinux/initrd.img
}

menuentry "Slackware64 14.1 huge.s kernel"{
  echo "Loading huge.s kernel and installer initrd.  Please wait..."
  linux /syslinux/huge64.s vga=normal load_ramdisk=1 prompt_ramdisk=0 ro printk.time=0 nomodeset SLACK_KERNEL=huge.s
  initrd /syslinux/initrd64.img
}

menuentry "Slackware64 14.1 huge.s kernel (use KMS console)"{
  echo "Loading huge.s kernel (with KMS) and installer initrd.  Please wait..."
  linux /syslinux/huge64.s vga=normal load_ramdisk=1 prompt_ramdisk=0 ro printk.time=0 SLACK_KERNEL=huge.s
  initrd /syslinux/initrd64.img
}

# Detect installed operating system and allow booting them from GRUB:
menuentry "Detect/boot any installed operating system" {
  configfile "/EFI/BOOT/osdetect.cfg"
}

message.txt and f2.txt aren’t actually config files, their purpose is to tell you a bit of information about what kernel to load, so you can include there whatever.

fsLeg

It turned out, that I need a full featured website much less than a simple blog. I don’t want to have a blog on Tumblr, but I do like their implementation of it, so I went with Chyrp, which is pretty close. But then Chyrp died, so I moved to Hugo. The blog is NSFW, as I might occasionally post some pr0n and other disturbing stuff.

Tags
Archives