Install GNU/Linux without a CD – using a liveUSB or external hard drive
Note: This tutorial’s fraternal twin, Install GNU/Linux without a CD – using your internal hard drive, is here .
Maybe you just don’t like to burn every distribution to a CD and fill the landfills with CD’s they only used once or twice. Maybe you don’t have a CD or DVD drive on your computer (e.g., if you have a netbook), or don’t happen to have any CD-R’s or CD-RW’s on hand. You may like the fact that installing off of a USB key or straight off a hard drive is considerably faster than installing from a CD. The USB key option also offers easier portability – if you happen to run into someone out there who would like GNU + Linux installed, it’s easier to have your USB key with you all the time than a CD. Or you may have multiple computers to install to, and it’s faster to have them all pull the installation files from a central location than to burn a bunch of CD’s every time.
There are a few ways to go about CD-less installations, but I’m going to cover the 2 most common ones. One is by using an external storage device that plugs into a port, such as a USB key or external hard drive (shown on this tutorial). The other is by creating a separate partition for this purpose on your internal hard drive, the one that’s already inside your computer (tutorial coming soon). Here are some quick facts about both to help you decide which will work best for you.
- simpler setup
- you can use it on more than one computer
- won’t work on older computers
- small portable devices are easily lost or stolen
- an external device is one more thing to remember to bring and carry around
internal hard drive:
- works great on older computers
- it’s always with your computer; no worrying about loss, theft, or forgetting to bring it
- usable only on the computer you’ve set it up on
- less straightforward setup – especially if you’re not familiar with hard drive partitioning
- more potential for messing up your existing data if you’re not careful – again, especially if you’re not familiar with hard drive partitioning
- the hard drive partitioning part only needs to be done once, so you don’t have to do it again if you decide to change to a different virtual CD later
For the purpose of this tutorial, I’ll assume you currently have a way to boot into GNU/Linux, either through a currently working install or using an existing LiveCD (almost any distribution will do).
This tutorial works for both USB keys (a.k.a. thumbdrives) and external hard drives with USB or Firewire (IEEE 1394) connections, but for brevity’s sake I’ll refer to all of these as a “USB key”.
I recommend that you have at least 2 GB of free space available on your USB key. The reason behind this is because the files to be copied onto it will take around 700 MB, and the system will need some extra space to work within. You may or may not have enough space if you use a 1 GB key, especially if you also want to store settings and data on it (see LiveUSB_persist_with_hwdetect” in step 9). Operating systems also don’t like it when they don’t have enough space for their temporary files and such.
Some people prefer to go with UNetbootin (wikipedia page) rather than use the process described here, but UNetbootin has its own little idiosyncrasies sometimes. If it hasn’t been tested with and customized for the distribution you want to install, you may get problems no one knows how to solve yet. And it can be hard to troubleshoot if something goes wrong because you don’t know exactly what it’s doing and where it’s putting the files you need. With the method below you have full control over the process.
This tutorial happens to be geared toward PCLinuxOS 2009.1, but many other distributions will work with this process. (Under normal circumstances, it’s not necessary to do this with PCLinux 2009.1 because it already has a special LiveUSB creator utility – but I’m helping my son with a project.) My testing back in January showed it to work with PCLinuxOS 2007. It worked for Linux Mint 6 too, but due to a bug in the installer itself I couldn’t get through the actual install once started. Other distributions may have extra steps specific to them to make them work. OpenSUSE 11.1 failed with an error saying it “couldn’t find the live image configuration file,” and I found out that it required a long additional process I simply wasn’t willing to undertake.
Warning: During my last attempt to do this with Linux Mint, a distribution based on Ubuntu, a bug in the Ubuntu installer (called Ubiquity) set me up for a nightmare in which my father’s system (on the other side of the continent) was rendered unbootable without a liveCD. I don’t know if they’ve fixed the problem in Ubuntu/Kubuntu 9.04 so be especially careful.
Warning: before you do anything past this point, make sure your data is backed up on some other drive or disc – in case anything goes wrong.. Seriously, disaster recovery sucks.
Ready? Here we go…
1. Download the ISO for the distribution in question. Take note of what folder you saved it in as you will need this later.
2. Make sure it downloaded and saved correctly by checking the ISO file’s integrity. If you don’t know how to do this, I have a tutorial on it here. This is an important step that can save you a lot of headaches.
3. Open a terminal and log in as root. Here I’m logged in as g33kgrrl and use the su command to switch user to root. It prompts me for my root password and the prompt changes to show me I’m now logged in as root.
g33kgrrl@home ~ $ su
root@home ~ #
4. Make a special location on the hard drive which will act as your virtual CD. This is called a “mount point.”
root@home ~ # mkdir /mnt/iso
5. Mount the ISO to the new mount point as a loop device (don’t worry if you don’t know what that means). We need to point this command to the ISO file you downloaded. Here, I’ve saved it to /home/g33kgrrl and the ISO file name is pclinuxos-2009.1.iso , so change this to match your setup. The whole command all goes on one line.
root@home ~ # mount -t iso9660 /home/g33kgrrl/pclinuxos-2009.1.iso /mnt/iso -o loop
6. Change directory to the location of your virtual CD.
root@home ~ # cd /mnt/iso
7. You should now be able to list the contents of the virtual CD and see some folders and files. Which ones you see will vary by which distribution you’re using, but as long as you see some there you’re on the right track. Here I see 2 folders and one file.
root@home ~ # ls
boot/ isolinux/ livecd.sqfs
8. Connect your USB key (if you haven’t already), and give the system a few seconds to find it. If it asks you if you’d like to “open in a new window”, click OK.
9. Find out the USB key’s device name and the mount point of the partition on it.
root@home ~ # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.9G 3.3G 4.3G 44% /
/dev/sda3 60G 23G 37G 39% /home
/dev/sdb1 16G 8.0K 16G 1% /media/disk
The partition name is in the “Filesystem” column and should be something like /dev/sdb1 or /dev/hdb1 . Partition names are designated by tacking a number to the end of the device name. Thus, the 1st partition on device /dev/sda is /dev/sda1 , the 2nd partition is /dev/sda2 , and so on. My output above shows 2 partitions mounted on device /dev/sda , my main hard drive, which are numbered 1 and 3. There’s another partition, /dev/sdb1 , on device /dev/sdb . More on this in a moment.
The mount location, called a “mount point”, will be in the “Mounted on” column. USB keys and external drives usually get mounted in some subdirectory under /media or /mnt .
Judging by the size of /dev/sdb1 above and where it’s being mounted (/media/disk) , /dev/sdb is my 16 GB USB key.
Take note of both the device name and mount location (called a “mount point”) as you will need them in the following steps.
If you don’t see anything listed under /media or /mnt , your USB key isn’t mounted. Try removing it and repeating this step from the beginning.
10. Copy the contents of the virtual CD to your USB key. In the last step, I learned that my key is mounted at /media/disk , so I specify that location in my copy command below. You’ll need to change this to match your mount point.
root@home ~ # cp -r . /media/disk
(The “.” tells it to copy everything from the current directory.) This will take a few minutes or so since there is lots to copy. Now’s a great time for a coffee or a sandwich, don’t you think?
When it’s done you’ll get another prompt.
root@home ~ #
11. Find the 2 boot files on the virtual CD. Unfortunately, their names and location vary a bit between distributions. With PCLinuxOS 2009.1, they are named vmlinuz and initrd.gz files and are in the isolinux folder. Your distribution may do things differently. The 2 files may be in a folder other than isolinux, have version numbers in their names (e.g., vmlinuz-2.4.18), or the part after the “.” may be different (e.g., initrd.img). You’ll need to look through the subdirectories on the virtual CD, and modify your commands to match the locations and filenames of these 2 files.The good news is that they will usually be only one folder below where you are now. In other words, you shouldn’t have to go digging through several layers of folders to find them.
Let’s say I don’t know where they are. I list the contents of my virtual CD.
root@home ~ # ls
boot/ isolinux/ livecd.sqfs
I see 2 folders called boot and isolinux and a file named livecd.sqfs . I don’t see the files I need so I dig one level deeper by checking the contents of these 2 folders.
root@home ~ # ls boot
Nope… just another folder, named grub . But I know I shouldn’t have to dig that far, so instead of checking the contents of the grub folder, I check isolinux .
root@home ~ # ls isolinux
back.jpg el.hlp isolinux.bin memtest ru.hlp welcome.jpg
bg.hlp en.hlp isolinux.cfg nb.hlp sl.hlp zh_CN.hlp
boot.cat es.hlp it.hlp nl.hlp star.dat zh_TW.hlp
bootlogo fi.hlp ja.hlp pclinuxos.pcx sv.hlp
cs.hlp fr.hlp lang pl.hlp timer_a.jpg
da.hlp hu.hlp langs pt_BR.hlp uk.hlp
de.hlp initrd.gz mediacheck* pt.hlp vmlinuz
There they are, in isolinux . Take note of which folder you found yours in and what their exact names are. You’ll need this in a bit.
12. Change directory to the mount point of your USB key. Adjust this to match your mount point.
root@home ~ # cd /media/disk
13. Install GRUB. GRUB tells the system where to find the files it needs to boot up, and manages your boot options. Here I’ve used the device name from step 9.
root@home ~ # grub-install --no-floppy --root-directory=. /dev/sdb
14. Open your favourite text editor (as root) and tell it to create a new file. I recommend kwrite or gedit for ease of use.
root@home ~ # kwrite
15. Copy the content below and paste it into the new file.
kernel (hd0,0)/isolinux/vmlinuz livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=on vga=791 keyb=us splash=verbose fstab=rw,auto fromusb changes=/dev/sda1/livecd-rw
kernel (hd0,0)/isolinux/vmlinuz livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=on vga=791 keyb=us splash=verbose fstab=rw,auto fromusb changes=/dev/sda1/livecd-rw hwdetect=yes
color black/cyan yellow/cyan
kernel (hd0,0)/isolinux/vmlinuz livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=on vga=791 keyb=us splash=verbose fstab=rw,auto fromusb
kernel (hd0,0)/isolinux/vmlinuz livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto vesa
kernel (hd0,0)/isolinux/vmlinuz livecd=livecd root=/dev/rd/3 acpi=off vga=normal keyb=us noapic nolapic noscsi nopcmcia
kernel (hd0,0)/isolinux/vmlinuz initrd=initrd.gz root=/dev/rd/3 acpi=on vga=788 keyb=us splash=silent fstab=rw,noauto 3
It’s worth a quick explanation of the menu options above, so that you know what your choices mean. Each section starts with a line where the first word is “title”, and represents one option in the menu.
LiveUSB – like a LiveCD; you can boot to it and play around with settings but it won’t save any of your changes.
LiveUSB_persist – saves changes; the next time you boot to it any changes you made to settings will still be there. LiveUSB_persist_with_hwdetect – can detect and save your hardware configuration; useful if you only boot this USB key on one computer
VideoSafeModeVesa – useful if you’re having video issues when using the above options
Safeboot – useful if you’re having other hardware issues
Console – skip the graphical user interface (GUI) and just boot straight to a command line
Memtest – test the computer’s RAM to make sure it’s functioning properly
16. Edit the text as necessary to point to the 2 boot files. Make sure the boot options in the new file point to the correct location and names of the 2 files. I have vmlinuz and initrd.gz in the /isolinux folder, so for each boot option I ensure that the line that starts with kernel points to /isolinux/vmlinuz and the line that starts with initrd points to /isolinux/initrd.gz . If you look at the output from the previous step, you can see they’re already pointing to the correct locations – so I don’t need to do anything extra here.
17. Save your new GRUB configuration file. On your USB key, among the files you copied from the virtual CD, should be a subdirectory boot/grub (notice no / in front of boot/grub ) Recall that my USB key’s mount point is /media/disk . That means I will need to save the file to /media/disk/boot/grub . Adjust your save location according to your mount point.
You are creating a boot menu for GRUB to prompt you with at boot time. Unfortunately, the required file name can be one of two options depending on your distribution. Many distributions use the newer name of menu.lst (that’s an “L” not a number “1”). A shrinking number still use grub.conf . If menu.lst doesn’t work, you can always go back and rename this file to grub.conf .
In this example I have saved the text file in /media/disk/boot/grub as menu.lst .
18. Reboot and set your computer to boot to the USB key or external drive. This process varies depending on the manufacturer of your computer’s motherboard. Consult your user manual for details if you need help.
Happy cd-less booting!