2009-04-29

Debian Installation from a USB Flash Drive

Before we can move on to upgrading the SSD on the Mini 9, I figured we should perpare our installation media. Since the Mini 9 does not have a CD/DVD drive on it, and I don't have an external CD/DVD drive laying around, I decided that I would install Debian onto the Mini 9 via a USB flash drive.
Things you will need:
  • A computer running Linux (a Mini 9 with Ubuntu Remix on it should do fine)
  • A USB flash drive:
    • At least 64 MB for the business card .iso
    • At least 256 MB for the network install .iso
    • At least 1GB for the standard CD .iso
  • A Debian installation .iso (you only need one of the following):
    *Using either of these, you will need a wired internet connection during the installation process to download packages.
  • The following addional files:

I did this using the standard CD .iso because I already had it downloaded, but either of the other two should work just fine. Just a heads up for when you actually install with this, I recommend a wired internet connection during the installation as this will autmatically configure networking during the installation process and it will download any package updates when installing.
I think we're ready to get started.
  1. Let's start by making sure we have all everything we need installed on our computers. We will need the dosfstools package if our flash drive is not a single FAT16 partition, the syslinux and mtools packages to install the syslinux boot loader on the flash drive, and the mbr package in case we need to fix a corrupted MBR on the flash drive:

    # apt-get update
    # apt-get install dosfstools syslinux mtools mbr

  2. Check the file system on your flash drive and get the device name for the flash drive (if you're working on a Mini 9, this is probably /dev/sda). For the purposes of this guide, I will use /dev/sdX for the device name of the flash drive, be sure to replace the "X" with the appropriate letter. You will want to make sure you have the correct drive name for you flash drive; you don't want to accidentally format your hard drive because you used the wrong drive name. Most flash drives come with a single FAT16 partition, which is what we want since we will be using syslinux as the boot loader which uses a FAT16 partition. We can use fdisk to check the partitions on the flash drive and to get the device name:

    # fdisk -l

  3. Skip this step if your flash drive is already a single FAT16 partition. If your flash drive is not a single FAT16 partition, we will make changes to the partition table with fdisk and format the filesystem with mkdosfs. First we want to make sure none of the partitions on the drive are mounted:

    # umount /dev/sdX1
    # umount /dev/sdX2

    Repeat the above for each partion number shown when you listed your partitions with fdisk before. Now that the drive is not mounted, we can write a new partition table with fdisk:

    # fdisk /dev/sdX
    Command (m for help):

    • Typing "m" will give you a list of commands
    • If you need to see a list of partitions again (this will help make sure you're messing with the right drive), type "p"
    • Type "d" and then a partition number to delete a partion
    • Repeat above step until typing "p" returns no partions
    • Create a new partition with "n"
    • Type "p" to make it a primary partiton, and then "1" to make it the first partiton
    • Hit the 'Enter' key twice to make this partition take up the whole drive
    • You should now be back at the 'Command (m for help):' prompt, type "a" and then "1" to set the boot flag on the first partition
    • Type "t" then "1" and then "6" to set the file system on the partion to FAT16
    • Type "w" to write the partition table, and then you should be back at the standard bash prompt

    Now we want to format the file system with mkdosfs:

    # mkdosfs /dev/sdX1

  4. At this point, the flash drive is probably mounted on your system (even if you just formatted it), so we need to unmount it before we can install syslinux on it:

    # umount /dev/sdX1
    # syslinux /dev/sdX1

  5. Now we need to mount the flash drive; the easiest way to do that is to unplug it and plug it back in. By default, my flash drive was mounted to /media/disk. If you have already downloaded the vmlinuz and initrd.gz files, copy them onto the flash drive now. Alternatively, we can download them directly to the flash drive:

    # cd /media/disk
    /media/disk # wget http://ftp.nl.debian.org/debian/dists/lenny/main/installer-i386/current/images/cdrom/initrd.gz
    /media/disk # wget http://ftp.nl.debian.org/debian/dists/lenny/main/installer-i386/current/images/cdrom/vmlinuz

  6. Now we need to create a file called 'syslinux.cfg'. This is a configuration file for syslinux that tells it what to do. The file needs to contain the following information two lines:

    default vmlinuz
    append initrd=initrd.gz ramdisk_size=12000 root=/dev/ram rw

    Depending on the image you are booting with this, you may need to increase the ramdisk_size parameter. I used the above settings with the standard CD iso image and did not have any problems. Also, if you run into issues with booting from the flash drive, it may help to add devfs=mount,dall to the second line. You can create this file with your favourite text editor:

    # vim syslinux.cfg

    # gedit syslinux.cfg

    # nano syslinux.cfg

    Or you can create the file directly from the command line with the 'echo' command:

    # echo "default vmlinuz" > syslinux.cfg
    # echo "append initrd=initrd.gz ramdisk_size=12000 root=/dev/ram rw" >> syslinux.cfg

  7. Now you can copy your iso to the flash drive:

    # cp /`path to iso`/`iso file name`.iso /media/disk/

    Or you can drag and drop the file in nautilus or whatever your file manager of choice is.

  8. At this stage you should be done, but I always have to do an extra step. For some reason, during the above processes, I always corrupt the MBR on the flash drive. Not to worry, though, because it is easy to repair. First we need to unmount the flash drive again and then we can use install-mbr:

    # umount /dev/sdX1
    # install-mbr /dev/sdX

Well, there you have it! You should now have a flash drive that you can boot up into the debian installation with. You should be able to boot up into the installation on any computer that will allow you to boot from USB (you may need to turn this on in the BIOS). We are all ready to swap out the SSD in the Mini 9 with a bigger and faster one in my next post.

2 comments:

  1. Thanks man. It helped to install debian on 1u server. Btw, what is the most common approach to install os onto 1U servers without cd-rom drive?

    ReplyDelete
  2. To be honest, I don't have a whole lot of experience here. Most of my experience is in working with Linux from a workstation perspective rather than from a server perspective.

    That said, if I were going to be doing a lot of Linux deployments, I would go for doing a base installation using whatever method is most convenient (standard CD installation, USB isntallation, or network boot installation). Then I would clone the hard drive for that installation for the machines that I would need to deploy to.

    If you Google "clone linux server installation" or something similar, you can find a lot of different resources to help. I found this one that appears to be pretty thorough: http://www.faqs.org/docs/Linux-HOWTO/Clone-HOWTO.html

    ReplyDelete