Install GNU/Linux without a CD – using your internal hard drive

Note: This tutorial’s fraternal twin, Install GNU/Linux without a CD – using a liveUSB or external 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 another 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 (shown on this tutorial). Here are some quick facts about both to help you decide which will work best for you.

external storage:

  • 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 assume that you already have GNU/Linux installed on this computer and are using GRUB as your bootloader.  (Translation: Using this method to wipe your Windows partition and switch to GNU/Linux is another tutorial for another day.)  GRUB tells the system where to find the files it needs to boot up, and manages your boot options. If you’ve already been running GNU/Linux on this computer, and didn’t go out of your way to install LILO instead, it’s pretty safe to assume you’re already using GRUB.

I’ll also assume that you currently have a way to boot into GNU/Linux, other than the target hard drive.  Usually this means booting to an existing liveCD or liveUSB (almost any distribution will do).  But if you have a second hard drive inside your computer that you can boot to, or know how to temporarily connect one, that would work too.  This assumption is for two reasons: (1) you can’t modify the partitions of a hard drive that is in use, and (2) if you make a mistake and render your hard drive temporarily unbootable, it’s not a big deal – but you will need to boot to something else in order to fix it.

I recommend at least 3 or 4 GB of free space available on your hard drive, even though only about 2 GB of that goes to the new partition.  To simulate a liveCD you need space for a 700 MB ISO file, 700 MB of files to be extracted from that file, and extra space for the system to work within.  Shrinking a partition that’s almost full takes a really long time, and runs a significantly higher risk of data corruption while being resized.  That risk is still relatively low, but it does happen.  Operating systems also don’t like it when they don’t have enough space for their temporary files and such.  (If you want the option of booting to virtual liveDVD’s as well, I suggest at least 12 GB space; 4.7 GB ISO + 4.7 GB files + working space).

Some people prefer to go with UNetbootin (wikipedia page) rather than use the process described here.  But UNetbootin doesn’t do the hard drive partitioning part, so you’d still have to do that.  It also 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 which can also write to hard drives – but I’m helping my son with a project.)  My testing back in January showed this process 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. Boot to something other than the target hard drive. You cannot modify the partitions on a hard drive that is currently in use. As I mentioned above, many people use a LiveCD (almost any GNU/Linux distribution will do) or temporarily boot to a different hard drive.  As long as your target hard drive is still connected, and you have booted to an alternate device, you can make the changes you need.

2. 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 ~ g33kgrrl$ su
root@home ~ g33kgrrl#

3. Find out the name(s) of your existing partition(s), if you don’t already know.

root@home ~ g33kgrrl# fdisk -l
Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device     Boot  Start   End      Blocks   Id  System
/dev/sda1   *        1  1044     8385898+  83  Linux
/dev/sda2         1045  1566     4192965   82  Linux swap / Solaris
/dev/sda3         1567  9729    65569297+  83  Linux

Here I have a list of the partitions on my hard disk.  The partition names are in the “Device” column.  Partition names are designated by tacking a number to the end of the storage device’s name.  Thus, the 1st partition on device /dev/sda is /dev/sda1 , the 2nd partition is /dev/sda2 , and so on.  Here you can see I have 3 partitions on disk /dev/sda , my main hard drive, which are numbered 1, 2, and 3.  In this case, /dev/sda1 is my working GNU/Linux installation, /dev/sda2 is a special system area called a swap partition, and /dev/sda3 is where I keep all my data (I use a separate partition for /home – to be covered in a future tutorial).  Your list will likely be different from this one; for example, you might have only one partition called /dev/hda1 .  Take note of the name(s) of the partition(s) because you’ll need this later.

4. Shrink at least one partition to make space. You’ll need to use a partitioning utility such as Gparted, which comes with most GNU/Linux distributions and you can also run it from their LiveCDs. Resize at least one existing partition so that you end up with unallocated space at the end of your hard drive.  I recommend making at least 2 GB of space.  You may be able to squeak by with as little as 1 GB, but it’s really best to give it more working room than that.  There’s a good Gparted tutorial on how to shrink a partition here, which includes screenshots.  (I may well expand this tutorial with full step-by-step screenshots in the future, but in the interest of getting this tutorial off the ground, I’ve skipped that step for now.)

I will shrink my 3rd partition, /dev/sda3, to make 2 GB of unallocated space at the end of my drive.

5. Create a new ext3 partition in the new space. You can do this using the same partitioning utility as in step 2. There’s another Gparted tutorial with screenshots that covers the basic process here, but make sure you choose file system type “ext3” when you create the new partition.

6. Double-check the changes you’ve requested and apply them. No changes are made to your partitions until you tell the utility to apply them.  This is your last chance to make sure everything is correct.  When you’re sure, click Apply.

This will take some time depending on your setup.  You deserve a break after all this hard work.  How about a nice cold lemonade, or a nice hot coffee?

7. Reboot. Once the changes are done, your computer needs to reboot in order to recognize them properly.  You don’t need to boot to an alternate drive any more if you have a working GNU/Linux installation on your target hard drive – the partitioning part is done.

8. If you haven’t already, download the ISO for the distribution in question. Take note of what folder you saved it in as you will need this later.

9. 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.

10. Open a terminal and log in as root. This is just like step 2.

g33kgrrl@home ~ g33kgrrl$ su
root@home ~ g33kgrrl#

11. Find out the name of the new partition. This is much like step 3.

root@home ~ g33kgrrl# fdisk -l
Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device     Boot  Start   End      Blocks   Id  System
/dev/sda1   *        1  1044     8385898+  83  Linux
/dev/sda2         1045  1566     4192965   82  Linux swap / Solaris
/dev/sda3         1567  9437    63223807+  83  Linux
/dev/sda4         9438  9729     2345490   83  Linux

Now you can compare your list of partitions from step 3, both to ensure that your changes worked and also to find out the name of the new partition since you’ll need it in the next step.  Before, I had 3 partitions numbered 1, 2, and 3 on disk /dev/sda .  They are still there, but now /dev/sda3 is smaller (you can tell because the number in the “Blocks” column is smaller) and there is now a 4th partition called /dev/sda4 .

12. Make a special directory on the hard drive which you will use to access your new partition. This special directory is called a “mount point.”

root@home ~ g33kgrrl# mkdir /mnt/livecd

13. Mount the new partition to this new mount point (don’t worry if you don’t know what that means).  In this step, you tell the computer to give you access to the new partition through the special location you created in the last step.  You’ll need the name of your new partition, which you took note of earlier.  Recall that mine is /dev/sda4 .  As always, change this as needed to match your setup.

root@home ~ g33kgrrl# mount -t ext3 /dev/sda4 /mnt/livecd

14. Make a  mount point on the hard drive which will act as your virtual CD.

root@home ~ g33kgrrl# mkdir /mnt/iso

15. Mount the ISO to this new mount point as a loop device (don’t worry if you don’t know what that means either). 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 ~ g33kgrrl# mount -t iso9660 /home/g33kgrrl/pclinuxos-2009.1.iso /mnt/iso -o loop

16. Change directory to the location of your virtual CD.

root@home ~ g33kgrrl# cd /mnt/iso
root@home ~ iso#

17. 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 ~ iso# ls
boot/     isolinux/ livecd.sqfs

18. Copy the contents of the virtual CD to your new partition.

root@home ~ iso# cp -r . /mnt/livecd

(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 ~ iso#

19. 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 ~ iso# 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 ~ iso# 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 ~ iso# 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     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.

21. Open your favourite text editor (as root) and edit your GRUB configuration file. I recommend kwrite or gedit for ease of use.  Unfortunately, this file’s name can be one of two things 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 .  Either way, it should be in the /boot/grub folder.  Mine is menu.lst so this is how I do it:

root@home ~ iso# kwrite /boot/grub/menu.lst

This saves me a step by launching kwrite and immediately opening the file I want to edit.

Note that menu.lst should have some text in it already.  If it’s completely blank, your distribution uses grub.conf – so open that instead.

24. Add a boot menu option to the end of this file. There are 4 lines you need to add here, and they will need some explaining.  When you boot up to GNU/Linux, you are normally greeted with a menu that gives you different boot options.  This is the GRUB menu.  After a few seconds it times out and sends you on your way to whatever menu option is set as your default.  By editing GRUB’s configuration file, you will be adding another menu option which will appear at the bottom of that menu.

Line 1 starts with the word title .  This is followed by a space and then whatever description you want for this option.  I’ve chosen PCLinuxOS 2009.1 virtual liveCD .

title PCLinuxOS virtual liveCD

Line 2 starts with kernel , and tells GRUB what hard drive and partition it should look on to find your vmlinuz file.  It uses a special notation to do this.  Remember your partition name from earlier?  You’re going to need to translate it.  But never fear, it’s not too terribly hard.

You may remember that my new partition’s name was /dev/sda4 .  Take a look at how I tell GRUB to go to /dev/sda4 and then I’ll explain.

kernel (hd0,3)

The first hard drive on your computer is usually referred to with a device name of either /dev/sda or /dev/hda , depending on your configuration.  Here, sda stands for (S)CSI (D)rive (A) and hda stands for (H)ard (D)rive (A).  The second hard drive gets called either sdb or hdb .  The third gets sdc or hdc , and so on.

In GRUB’s notation, they just get hd for (H)ard (D)rive plus a number tacked on.  But just to be confusing, it starts counting at 0 not 1.  So the first hard drive is hd0 , the second is hd1, the third is hd2, and so on.

By knowing the device name above, one can figure out what to call it in GRUB’s notation.  My main hard drive is being called /dev/sda , so I know GRUB is going to call it hd0 .

Then after that is a comma and another number.  Recall that my partition names listed earlier were /dev/sda1 , /dev/sda2 , /dev/sda3 , and /dev/sda4 .  The number tacked onto the end of the device name /dev/sda represented the number of the partition.  GRUB counts partitions, too.  But again, there’s a “gotcha” because just like when it’s counting hard drives, it starts with 0 not 1.  So the first partition is 0, the second is 1, the third is 2, and so on.

Since my new partition is on the 1st hard drive and it’s the 4th partition, I use hd0, 3 .  I plug that in to the line with the format kernel (hdhard-drive-number,partition-number  boot-options).  That’s why my second line to add is

kernel (hd0,3)/isolinux/vmlinuz livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=on vga=791 splash=verbose fstab=rw,auto

You will need to change this to point to your new partition, in the correct folder and with the correct filename.

Line 3 tells GRUB the location and name of your initrd file.  Figuring out line 3 is going to be very similar to line 2.  Recall that my initrd file was initrd.gz .  Again, adjust this for your partition, folder and file name.

initrd (hd0,3)/isolinux/initrd.gz

That’s it. Here are the 3 lines I added to my menu.lst .  Here I’ve inserted spaces between the lines for clarity, but you won’t need to do that.

title PCLinuxOS virtual liveCD

kernel (hd0,3)/isolinux/vmlinuz livecd=livecd initrd=initrd.gz root=/dev/rd/3 acpi=on vga=791 splash=verbose fstab=rw,auto

initrd (hd0,3)/isolinux/initrd.gz

15. Save your new GRUB configuration file. On your key or drive, 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. In this example I have saved the text file in /media/disk/boot/grub as menu.lst .

You have now created a boot menu option for GRUB to prompt you with at boot time.

16. Reboot and choose the boot menu option you created. When your system boots, you will now have a new boot option with the name (title) you chose earlier.  I now have an option called “PCLinuxOS virtual liveCD”.  Use the arrow keys to go down the list and select it, and hit Enter.

Congratulations! You should now have a virtual liveCD that works almost exactly like a real one. You can use it to boot from any time you have trouble booting from your existing GNU/Linux installation, and you can even use it to format your other partitions and do a fresh install. The only real difference is that you can’t repartition your hard drive, since you can’t do that on a hard drive that is in use.

Happy CD-less booting!



10 thoughts on “Install GNU/Linux without a CD – using your internal hard drive

  1. Pingback: Install GNU/Linux without a CD, using a liveUSB or external hard drive « g33kgrrl’s garage

  2. Pingback: Verify the integrity of an ISO or burned CD « g33kgrrl’s garage

  3. informative post! 2 underscores in the email address

    “For the purpose of this tutorial, I’ll assume you assume that you already have GNU/Linux installed on this computer and are using GRUB as your bootloader.”

    running grub4dos & SliTaz iso, similar to frugal install. how can i use your method to get pclinuxos running on my laptop?

  4. I have read this article with great interest, as I have a number of older PC’s (Compac EVO), that have problems reading CD’s.
    You have explained almost everything in detailes, exept one thing:
    In your menu.lst, the kernel string, you write: ‘root=/dev/rd/3’.
    You have not explained, what /dev/rd/3 is. Is it essential, and is it always the same or is it different for different situations (different partitions)?

    Kaj Rasmussen

  5. I wrote a comment to this article yesterday, and I recieved notifications on my gmail account, but I Can’t see any comments, even though I follow the link in the mail.
    Beneath the artocle it says 2 Responses, but that text are not a hyperlink.

    If I click on the link to comments underneath the headlines on the frontpage of the site, I am brought to the comment on some articles, but this one and not on the related ones.

    Kaj Rasmussen

  6. Does this work at normal computer speeds, or does it run at the speed you experience when operating from a live CD? Or perhaps somewhere inbetween? Thanks for the clearly explained tutorial; very refreshing. Noob here.

  7. Cool tutorial. But point 15 is somewhat confusing. You suddenly start talking about a USB key you never mentioned before. My tries suggest you should actually save the menu.lst to the place you opened it from in the first place. But since I’m not into Linux that much I don’t know if that’s the right guess.

  8. Hi, I have read(& followed) your article regarding installing Linux using Internal Hard drive, in which upto the 3/4 of the article,the explained procedure can be done from any Linux distro live cd,and the later part you expect the user to have a Linux distro installed in his/her computer in order to complete the procedure explained in the article. But what if the user doesn’t have any linux distro installed in his/her computer, how can we install a Linux distro, without any cd/dvd or usb, by just using internal hard drive,with no other Linux installation installed in the computer previously.
    I have tried your method in my windows 7 machine(note:windows 7 machines use a 100 MB system partition as active partition to boot the windows 7 OS), in which I don’t have any Linux distro installed. I could not complete the method because of the reason I said earlier. Can u kindly suggest a solution or a method to install a Linux distro using internal hard drive without having any Linux distro installed in the system already or previously.

  9. I’m using linux mint 10, I want to install another OS on it. What seems to be a problem that the grub file is now different then what it is used in your post . I want to know, do I need to append the grub file differently?

  10. Pingback: openSUSE installation without CD/USB | Imperturbable Capitulation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s