HOWTO: Install Debian Linux on a USB Key

I’m currently typing this on a MacBookPro Debian “Lenny” installation running off a USB key!

Kernel: Linux debian 2.6.26-2-686 #1 SMP

Questions? E-mail me at http://fieldeffect.info/wp-content/uploads/2014/08/FrontPageactionAttachFileampdogetamptargetsignature.gif

Installation Steps

In a nutshell, the process is this: you create a bootable HFS+ (Apple format) partition on your USB key that will run the Grub bootloader, which you can then use to boot into Linux on your USB drive.

Here are the steps I used for a MacBookPro2,2; I assume the steps are similar for other MacBookPros.

  1. Get a Debian installation CD-Rom or DVD
  2. Get a USB key
  3. Partition USB key into 3 partitions (you can do this using Linux cfdisk – see notes below):
    1. sdb1, primary Linux partition, ext3
    2. sdb2, MacOS filesystem (Type AF, not listed in cfdisk partition types)
    3. sdb3, Windows 95 LBA (Optional – for dual-booting on Windows systems)
  4. Boot the debian installation CD
  5. Choose to manually partition /dev/sdb (should be device name of USB key)
  6. Choose /dev/sdb1 as root filesystem (“/”), no swap space. Don’t make any other changes to /dev/sdb.
  7. When asked to choose software uncheck everything (provides most basic Debian install)

  8. Finish install
  9. Boot into MacOS X
  10. Go into Disk Utility and format the HFS+ partition you created with cfDisk
  11. Download GRUB2 image link

  12. Put GRUB.EFI file in /Volumes/something/efi/grub/grub.efi on the Apple partition of the USB key you created

    1. The something in that path above is the name of the Apple partition on the USB key that you created.

  13. Put grub.cfg (My Grub.cfg File) into the same efi folder.

  14. Boot into MacOS and run the following command in a terminal:
    1. sudo bless --folder=/Volumes/something --file=/Volumes/something/efi/grub/grub.efi --setBoot

      Again, replace something with the volume name of the HFS+ partition of your USB key

    2. Reboot your system, holding down the Alt key; you should see an orange disk with a USB symbol on it. Click that to boot into GRUB.

Post-installation Tasks

  1. Wireless

    1. iwconfig – needed for all wireless installations

      apt-get install wireless-tools

       

    2. madwifi – needed for Atheros pci drivers
      1. Add ‘contrib’ and ‘non-free’ to your main Debian repository (My Sources.list file) then update your packages list with

        aptitude update

         

      2. Install the madwifi kernel module source and the ability to compile it

        aptitude install module-assistant
        aptitude install madwifi-source madwifi-tools madwifi-doc

         

      3. Compile it

        m-a prepare
        m-a a-i madwifi
        modprobe ath_pci

         

    3. wpa-supplicant (for logging into wpa-protected WIFI)

      apt-get install wpasupplicant

       

  2. Video
    1. Xorg
  3. Sound
    1. alsamixer

Notes

  • This process is probably not for beginners. If you haven’t installed Linux before, you might want to try installing Linux into a VirtualBox installation first. You can do this non-destructively in an already existing Windows or Mac installation.

  • I have read that it’s not a good idea to run a Linux installation directly off of a USB key because flash memory is not meant for the tons of write operations that occur on a normal Linux system. By googling, you can find some decent solutions that only write data at various intervals. From my own memory on Unix systems (from a college class), there are write buffers that cause data only to get physically written to the disk periodically, or when you issue the “sync” command from a terminal. To me, this would mean that data aren’t written to disk very frequently anyway, but I have no real idea if this is the case; it’s only my educated guess. That said, you probably don’t want your swap space on a flash disk, because swap is written to more frequently. I’m not sure how big a deal any of this is, but in any case I figured I should mention it.
  • I have rEFIt installed, but I’m pretty sure you don’t need it for this process! It does seem to help when troubleshooting, but I don’t think it’s necessary.

  • The cfdisk utility can be found on your Debian installation disk by booting into a rescue shell. This is one of the boot options when you boot from the installation disk.
  • /dev/sdb is the name of the drive on my computer… you may get a different name on your system. You’ll be able to tell when you go into cfdisk and see the different drives installed on your system.
  • Grub can provide you with helpful information. If you can get into Grub, you can type “c” to get a command line, and then type “ls”. This gives you a listing of drives on your system. For the most part, I believe on a Mac (hd0) in Grub would translate to /dev/sda in Linux and (hd1) is /dev/sdb.
  • I have recently read that you should set the “noatime” option when mounting flash filesystems. This option prevents inodes from being updated with the last access time, preventing a lot of writes from occurring. This is used to help improve the life span of the flash device.

Scratchpad for notes on compiling/installing GRUB2

./grub-mkimage -d . -o grub.efi appleldr boot cat cmp chain configfile crc date echo ext2 fixvideo fat fs_uuid part_gpt part_apple gptsync halt help hexdump hfs  hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pci reboot reiserfs read scsi sleep search sh video videotest xfs
 ./grub-mkimage -d . -o grub.efi appleldr boot cat cmp chain configfile crc date echo ext2 fixvideo fat fs_uuid part_gpt part_apple gptsync halt help hexdump hfs  hfsplus iso9660 linux loopback loadbios lspci ls minicmd memrw ntfs pci reboot reiserfs read scsi sleep search sh video videotest xfs blocklist elf extcmd jfs lvm mmap msdospart normal parttool scsi sfs xfs

ubuntu post on making grub.efi image

bean123 github repository for grub2

Christopher Smart describes how to compile GRUB2 for Xserve

My wpa.conf

Contents of my /etc/wpa_supplicant/wpa.conf file:

# WPA-PSK/TKIP

ctrl_interface=/var/run/wpa_supplicant

network={
        ssid="Access_Point_Name"
        key_mgmt=WPA-PSK
        proto=WPA
        pairwise=TKIP
        group=TKIP
        psk="MyPreSharedPassPhrase"
}

My interfaces file

Contents of my /etc/network/interfaces file:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

auto ath0
iface ath0 inet dhcp
        pre-up wpa_supplicant -B -Dwext -iath0 -c/etc/wpa_supplicant/wpa.conf
        pre-up iwconfig ath0 essid "Access_Point_Name"
        post-down killall wpa_supplicant

Installing Debian directly onto a hard drive

Installing directly onto a hard drive is much easier. Just install rEFIt, install Debian into an empty partition, the run Partition Tool in rEFIt and let it sync. You may have to re-install GRUB once the partition tables are synced. I booted into my system using the USB key, then used grub-install /dev/sda3.

TODO

  • add info on booting the same USB key on Windows system
  • add more detail
  • configuring Xorg My Xorg.conf file

  • madwifi
  • swap space in a flat file
    • mount -o rw /dev/hdX /mnt/<mount-point>
      dd if=/dev/zero of=/mnt/<mount-point>/swap bs=1G count=2
      mkswap /mnt/<mount-point>/swap
      swapon /mnt/<mount-point>/swap

       

  • CPU Frequency Scaling

    echo speedstep_centrino >> /etc/modules
    echo acpi_cpufreq >> /etc/modules
    echo cpufreq_ondemand >> /etc/modules