Install Slackware using a bootable USB stick Introduction Recently I have been exploring the Slackware installer, and especially looking for ways to use the installer other than running it from a CDROM/DVD. In a previous wiki article I detailed my experiences with creating a PXE installer that you can use if your computer is able to do a network boot. This is also fondly called PXE boot. This was fun, and it was the end of using CDROMs for my Slackware installations - as long as I had a PXE server configured in the local network. Of course, when you visit other places, such a server is not always available :-) So, I went on, and turned to USB sticks, also known as pen drives or thumb drives. These devices are small,lightweight, easy to carry around and modern PCs are usually able to boot from a suitable USB medium (such as the pendrive). The result of my experiments is documented in this Wiki page. I will show you how to use a bootable USB stick to install Slackware. This method - creating the USB equivalent of a boot/root floppy pair - is relatively easy to implement. Note: I am taking the convoluted path of first creating an image file and then copying that to a USB stick. It is easier to directly write to a USB stick and forget about the intermediate stage of creating the image file, and particularly much easier in the case of the multi-partition USB stick... but USB Flash devices are not meant to be written an infinite amount of times, they have a limited lifetime regarding write operations. I wanted to keep my USB sticks out of harms way, and also I should mention that writing to a file on hard disk is much faster than writing to the USB device. This sped up the development process considerably. Finally, it was a great learning experience in working with loop devices and image files. Boot disk on a mini USB image I had no idea how bootable USB sticks were configured, but by looking at the Slackware CDs isolinux bootloader, it turned out that its sibling syslinux was the ideal candidate for creation of such a bootable USB image. I started small, by creating an image containing a single partition to which I copied the contents of the Slackware boot disk (i.e. large parts of the /isolinux directory of the Slackware package tree and then some more). This worked great! The result is a 37 MB small USB boot image that you can use to boot into the Slackware setup program (and then use a NFS server or another Slackware package source like a prepared local harddisk partition). The small image works great, especially when you don't have or don't want to use CDROM media as the carrier for the Slackware packages. I myself install Slackware from my own NFS server because my network is blazing fast compared to the much slower CDROM data transfer speeds. The USB image is small enough to make it available for download on a web server, and is transfered to a USB stick in a matter of seconds. Even the oldest and tiniest of USB drives is well suited for this purpose. So, how does one create this small image file, and how is it used? We will need access to a local mirror of the Slackware directory tree, or at least the isolinux and kernels directories thereof. In the examples below, I am assuming the Slackware tree is located at /mirror/Slackware/slackware-11.0. You will have to adapt the example commands so that they are correct for your own situation. The mini image will not contain any installable Slackware package. Instead, we are relying on a nearby NFS server from which we can retrieve the packages. The usual way of installing Slackware from a NFS server repository, is to boot the Slackware CDROM, and run (pcmcia and) network to load all the drivers for your network card before starting setup to commence the installation procedure. When you type pcmcia and/or network, the Slackware installer will look for the appropriate driver files on an available CDROM, and if no CDROM is found it prompts you to insert floppy disks. Now, with a boot from our USB stick we are assuming there is no CDROM and no floppy drive available to us. So, we need to add all the drivers we need to the root filesystem where the setup program and related stuff is stored (this is what is in the initrd.img file - initrd stands for initial ramdisk). If you want the easy way out, you can either download the ready-made image file or download the script I wrote and which implements all the steps I'm about to describe. Otherwise, read on. Creating a new initrd.img file Let us do our work in a temporary directory I call the staging directory: mkdir -p /tmp/slackboot The fun thing is, a lot of the work looks exactly like the steps I described in my PXE installer article. Instead of duplicating my efforts, I am sending you over to that section of the article to read exactly how you build a modified initrd.img. Assembling the USB image Now that we have a initrd.img file with all the functionality we need, it is time to create the larger USB image file. First, we calculate the sizes of the files we are going to copy into the USB image (the initrd.img and the boot kernels are the bulk). That target file must be larger than the sum of the sizes of those source files: let USBIMG=$( du -sk /tmp/slackboot/initrd.img | cut -f1 ) for KERN in /mirror/Slackware/slackware-11.0/kernels/*.?/*zImage ; do let USBIMG=USBIMG+$(du -sk $KERN | cut -f1 ) done let USBIMG=USBIMG+512 # Add just that little extra.. This leaves us with a variable ${USBIMG} whose value is the estimated size in kB of the file we are about to create. You could of course also calculate this value by using your eyes and brain and looking at the ls -l output :-) But the exercise is meant to enable you to copy/paste the example commands, and to create your own script from it. Create a DOS formatted image file: mkfs.msdos -n USBSLACK -F 16 -C /tmp/slackboot/usbboot.img ${USBIMG) You will notice that we use the switch -C and the variable ${USBIMG} that we calculated in the previous step. With the mkfs.msdos command line like that, we can omit the step where we would use the dd command to create the file prior to formatting it - mkfs.msdos will do that for us at no cost. The command also labels the new FAT filesystem with the name USBSLACK (the -n USBSLACK option) but this is not required. The important piece of information that is contained in the command is the fact that this FAT filesystem must be a FAT16 filesystem (-F 16). It is tempting to use FAT32 but the syslinux bootloader will fail to make the USB stick bootable if the filesystem is not FAT16. The file /tmp/slackboot/usbboot.img will eventually be the file to copy to the USB stick. Loop-mount the image so that we have a mount point to where we can start copying files: mkdir -p /tmp/slackboot/usb mount -o loop,rw /tmp/slackboot/usbboot.img /tmp/slackboot/usb Now, we copy the files that syslinux needs: cp /mirror/Slackware/slackware-11.0/isolinux/isolinux.bin /tmp/slackboot/usb cp /mirror/Slackware/slackware-11.0/isolinux/setpkg /tmp/slackboot/usb/ cp /mirror/Slackware/slackware-11.0/isolinux/{f*.txt,message.txt} /tmp/slackboot/usb/ cp /tmp/slackboot/initrd.img /tmp/slackboot/usb/ cat /tmp/slackboot/pxelinux.cfg_default | sed -e 's# /kernels/# #g' -e 's#/.zImage##' > /tmp/slackboot/usb/syslinux.cfg Note: The file /tmp/slackboot/pxelinux.cfg_default was created together with our modified initrd.img file. The difference with the file /mirror/Slackware/slackware-11.0/isolinux/isolinux.cfg which you perhaps expected me to use, it that we need a much bigger ramdisk than the Slackware bootable CDROM, because we added all the network and pcmcia stuff to the initial ramdisk. This of course means that this is not a suitable method to boot old PCs that are low on memory! The ramdisk will be more than 16 MB in size, and you will need RAM for your kernel as well. Syslinux can not cope with subdirectories, that is the reason we need to place all the files that syslinux uses in the root of the loop mounted FAT filesystem - including the bootkernels: cd /mirror/Slackware/slackware-11.0/kernels/ for dir in `find -type d -name "*.?" -maxdepth 1` ; do cp $dir/*zImage /tmp/slackboot/usb/$dir done Finally, we stamp the file with the syslinux bootloader: umount /tmp/slackboot/usb syslinux -s /tmp/slackboot/usbboot.img Note: Open the file ~/.mtoolsrc in an editor and add the line mtools_skip_check=1 in case the syslinux command gives an error. This concludes the steps needed to create our image file! All thats left is to copy the file to a USB stick: dd if=/tmp/slackboot/usbboot.img of=/dev/sda bs=512 Be careful about the device name for your USB stick! The above dd command will wipe out any existing data on the device, so you had better be sure that it is not the SATA hard disk you're targeting! Booting from the stick Your computer BIOS must support booting from USB HDD. Plug the stick into your computers USB slot, and boot it up. Make sure you select boot from USB-HDD - how you do this is very dependent on the type of computer you have. Many computers will display a message during the initial stages of the booting that says something like Press [F12] for a boot device list. The Slackware installer will start just like when you had booted from a CDROM Log in as root. Start the install by partitioning your hard drive as usual, and running setup. If you want to install from a NFS server, you should run the commands pcmcia (if your network card is PCMCIA) and/or network prior to running setup in order to load a driver for your network card. If you want to install Slackware using a local hard disk partition in case you copied the Slackware tree there in advance, that is also an option. It would not make much sense to opt for the third install method use a CDROM since we just abandoned the use of a CDROM medium :-) After writing the usbboot.img to the USB stick, if you run fdisk -l you will see alarming output like this: This doesn't look like a partition table Probably you selected the wrong device. Device Boot Start End Blocks Id System /dev/sda1 ? 8563200 8326647 2088818490 1 FAT12 Partition 1 has different physical/logical beginnings (non-Linux?): phys=(124, 38, 11) logical=(8563199, 1, 16) Partition 1 has different physical/logical endings: phys=(344, 195, 26) logical=(8326646, 0, 49) Partition 1 does not end on cylinder boundary. ... and so on, for partitions 2, 3 and 4 as well. This is actually harmless. The usbboot.img uses the raw device, it did not create partitions at all. Fdisk reads the information in the first sector and incorrectly interprets that. Restoring a USB stick to its original state When you have used the small 40 MB image to create a USB installer, your USB stick is no longer useful for anything else. Any remaining space on the stick (supposing you used a larger-than 40 MB stick for it) is inaccessible. Fortunately, it is easy to re-create a FAT partition on the stick (thereby removing the Slackware installer of course) so that the USB stick again becomes available for carrying around your data. Take care about which device actually is your USB stick !!! The next command will render all data on /dev/sda inaccessible !!! First, wipe the bootsector of the USB stick: dd if=/dev/zero of=/dev/sda bs=512 count=1 Then, create a new FAT32 partition on the stick and write a FAT32 filesystem on it (vfat or type b in fdisk terminology): fdisk /dev/sda <