Sunday, April 27, 2008

CD/DVD install with no CD/DVD

Want to install a DVD release of Linux but dont have a DVD drive or recorder? Your CD/DVD drive has died but you still want to install a new or updated version of Linux? You can, and you can do it all from your hard drive without burning a single CD or DVD.

To start we need to make a partition for the image to reside on. Two bits of advice, put the partition at the very end of the drive so you can recover the HD space later on if you wish. It's easy to add more room to the end of a partition but nearly impossible to add more room at the beginning of a partition. The second bit is, if you have no working CD/DVD drive at all you will need another way to resize your drives, for this I recommend going to http://www.pendrivelinux.com. They have a great list of thumb drive installs and how-to's, as well as their own version aptly called pendrivelinux which is great. You'll have to install gparted on it but still, very handy and a must have for your toolkit.

Okay, one way or another we now have a way to resize the drive, my personal preference is gparted. For the next step the size of the .iso we will be working with is needed. The one I will be using in this example is 3.9 Gig so I need 3.9 Gig plus a little bit for a fudge factor. A few hundred meg should be sufficient, however in my case I want to also back up some critical data so I bumped it to 5 Gig. You dont have to, but this is a great way to back up things you want to have readily available after you install. The minimum though is .iso size plus a bit, say 10% of .iso size.

You can use gparted to make this partition ext2 or you can issue the following command to do it. As root:

mkfs -t ext2 /dev/sda4

Where /dev/sda4 is the partition you just created, /dev/sda4 was mine. Make sure to change it to the one you actually made.

Next we need to get ready to start putting things together. All of the commands we will be using for this need to be issued as root so you might as well go there and stay there for awhile.

mkdir /mnt/iso
mkdir /mnt/target
mount -t ext2 /dev/sda4 /mnt/target

(note here, /dev/sda4 needs to changed to the one you made)

mount -o loop -t iso9660 /path/to/image /mnt/iso

(note here, for me this would be /home/jim/dls/Sabayon-Linux-x86-3.5-Loop2-r2.iso . Yours will differ, adjust accordingly)

cp -rvp /mnt/iso/* /mnt/target

Great almost done, but now your going to have to do a little thinking. We have to get what we just did to boot. Since the example I'm using probably wont be the one you will be using I will point out the changes you need to make. Regardless it's fairly straightforward.

We need to figure out the configuration we need to feed to GRUB to actually fire this up. Luckily 99% of this has already been done for us by whoever released the liveCD/DVD.

cd /mnt/target
ls -l


look around here for either isolinux.cfg or syslinux.cfg, if it is not in this directory

cd isolinux
ls -l


and look for it in this directory.

Once you have found it:

cat isolinux.cfg (syslinux.cfg if thats what you have)

You are going to get a lot of stuff here, we are actually only concerned with a little bit. The line LABEL is what we are looking for, the first one usually but read the LABEL to make sure its the one your looking for. In my case:

LABEL sabayon
menu label ^Start SabayonLinux 3.5 Loop2
kernel /boot/sabayon
append root=/dev/ram0 initrd=/boot/sabayon.igz aufs init=/linuxrc cdroot looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 quiet music --

Is the one I want. When you see the next line that says LABEL, that is a seperate boot entry and you wont need it. Now we need to make a few changes to it, to make it bootable from GRUB.

title sabayon
root (hd0,3)
kernel /boot/sabayon root=/dev/ram0 aufs init=/linuxrc cdroot=/dev/sda4 looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 music quiet --
initrd /boot/sabayon.igz

First you'll see I changed it from LABEL to title and removed the menu label line.

Second you'll see I added root(hd0,3). You'll need to adjust this to match where you extracted the .iso image. GRUB counts from 0 so drive 1 = 0 and partition 4 = 3. sda3 would be (hd0,2) sdb3 would be (hd1,2) and so on.

Third you will see that I left the kernel line alone.

Fourth you will see that I removed the word append and then moved the whole thing up so it follows the original kernel line. Then moved initrd=/boot/sabayon.igz to it's own line at the very bottom. Following that a bit further you will also find that where it says cdroot I added the actual partition where we extracted the .iso.

Note that while it looks complex, and the one you will be looking at will probably look significantly different your only actually making a small handful of changes. Just make the small edits as described leaving the rest alone and you'll be golden.

Okay, lets say you now have your entry figured out. Now you simply have to edit /boot/grub/grub.conf and add it to the very end of that file. This file has to be edited as root, and make sure you dont over write anything that is in there already.

Save the file, reboot, and you should see the entry for the LiveCD/DVD as an option in your boot menu.

Once your done you can safely remove the partition you made and reclaim the space using gparted again, or leave it in place and have an emergency boot, although you will have to add the lines back into GRUB if you overwrote your last one if/when you installed.

I wish I could take full credit for this, however I cant. I was working on making a USB variant of this, and was almost there but was having a few problems with it when jvj posted an almost line for line how to in the sabayon wiki. I want to thank him for pointing out that cdroot needed to be pointed to the partition, which is where I was stuck at. Since we both use Sabayon and Loop2 is the most current beta at the time of the writing that is why so much of his wiki entry and my how to look so similar.

Anyway, thanks jvj, and to the rest of you, happy computing.

~Az

*UPDATE* 07July08

I'm happy to say that Sabayon 3.5 has officially been released and that the above how-to has been tested against it and it worked perfectly. Here is the grub.conf entry I used to get it working on my laptop.

title Sabayon 3.5 Install/LiveDVD

root (hd0,3)
kernel /boot/sabayon root=/dev/ram0 aufs init=/linuxrc cdroot=/dev/sda4 looptype=squashfs max_loop=64 loop=/livecd.squashfs splash=silent,theme:sabayon vga=791 CONSOLE=/dev/tty1 quiet --
initrd /boot/sabayon.igz
Remember you will have to adjust root (hd0,3) and cdroot=/dev/sda4 to reflect your actual system as explained in the above article. Due to formatting issues of the blog I should point out that everything from kernel /boot/sabayon to quiet -- is actually one long line.

**UPDATE** 17Oct08
I finally did a write up for how to make a bootable USB from a DVD image. If you have a 4 Gig or larger thumbdrive handy give it a try.
Again, Happy Computing
~Az

5 comments:

Ihar Filipau said...

Good write up.

P.S.

> (note here, /dev/sda4 needs to changed to the one you made)

In materials I prepare for users, I generally do it thru environment variable. e.g.

export TARGET_DEVICE=/dev/sda4

then mention once that it has to be adjusted to whatever device user has and rest of text uses the $TARGET_DEVICE instead of literate device name. Special care needs to be taken for case of su/sudo/reboots/etc.

That makes most command lines "portable" in sense of copy-pasting.

Ben said...

"mount -o loop -t iso9660 /path/to/image /mnt/target"

I think you mean:
mount -o loop -t iso9660 /path/to/image /mnt/iso

Azerthoth said...

Missed that on the proof read(s). Thanks for catching it. Fixed now.

jm said...

Many thanks for your post.

Now I can have a CD/DVD device on my remote server without having a physical one.

In my case I need to change:
/boot/grub/menu.lst

instead of 'grub.conf'

Maybe you should mention this on your article.

Thanks again.

jvj said...

jvj here. Thanks for the mention of the HOWTO. I found it this morning as I was getting ready to follow my own instructions for 3.5 final. Since it's online, I don't have to remember it, so I google for it each time, and you show up as the second hit in google.