Auteur Sujet: Make a bootable USB stick by hand with Grub legacy  (Lu 5951 fois)

0 Membres et 1 Invité sur ce sujet

Hors ligne melodie

  • Administrateur
  • Membre Héroïque
  • *****
  • Messages: 1774
    • Citrotux
Make a bootable USB stick by hand with Grub legacy
« le: 24 février 2013 à 00:16:51 »

The following example is with Ubuntu. You can adapt for other distributions, and it can work if their filesystem tree is in a squashfs archive.

Have a USB stick formatted to Fat32, and inside, create the directories:

cd /path/to/usb/stick 

let's say the USB stick is mounted to /media/ so you will change directory accordingly:
cd /media/USB_stick 

Where "USB_stick" is the label of your USB stick, unless it displays only the UUID (a large number).

Then you create subdirectories:
mkdir -p boot/grub
And from there you change directory to be located inside the grub directory:
cd boot/grub
in the /media/boot/grub, create a menu.lst file with this inside
# general configuration:
timeout   5
default   0
color light-blue/black light-cyan/blue

title OBUbuntu i386
kernel /casper/vmlinuz boot=casper quiet splash --
initrd /casper/initrd.lz

title OBUbuntu i386 Safemode
kernel /casper/vmlinuz boot=casper safemode quiet splash --
initrd /casper/initrd.lz
title OBUbuntu i386 IDE Generic
kernel /casper/vmlinuz boot=casper quiet splash ide.all_generic.ide=1 --
initrd /casper/initrd.lz

have the following files besides it:
fat_stage1_5 stage1 stage2

if you don't have Grub in you system, you should install it (in Ubuntu 12.04 the package having for name just "grub" is the legacy one). Then you can copy the files listed above into /media/boot/grub.

Then comes the part where you install Grub to the USB stick. I generally have the stick not mounted for this part (and I can't remember now what happens if mounted, I think I never tried).

Check which number device it is, with the mount command.

here for now I get : "/dev/sdb1 on /run/media/melodie/VERBATIM type vfat ... " which will help not to make a mistake.

Install Grub. As root in console type:
# grub

after a short text:
Probing devices to guess BIOS drives. This may take a long time.

you will get the Grub prompt:
    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)   

[ Minimal BASH-like line editing is supported.  For the first word, TAB    lists possible command completions. 

Anywhere else TAB lists the possible    completions of a device/filename. ] 

after the Grub prompt, type:
grub> root (hd<tab>

tab means you must press the tab key of the keyboard, which will trigger Grub to display the different possibilities:
 grub> root (hd  Possible disks are:  hd0 hd1

if you have only one hard drive in the machine. if you have more, it will present more, and the USB stick should be represented by the last one.

So your hard drive is the hd0 disk, (if it is connected as master on the first port), you will choose the second option and after:
grub> root (hd

you will add 1:
grub> root (hd1<tab>

And grub will again complete:
grub> root (hd1,0)

Then, hit "enter", and you will get the following information:
grub> root (hd1,0)  Filesystem type is fat, partition type 0xc  grub>

You see "fat", there can't be any mistake.

Then type the following command to install Grub to the MBR of your USB stick:
grub> setup (hd1)

Validate, and you should get the following message:
grub> setup (hd1)  Checking if "/boot/grub/stage1" exists... yes  Checking if "/boot/grub/stage2" exists... yes  Checking if "/boot/grub/fat_stage1_5" exists... yes 

Running "embed /boot/grub/fat_stage1_5 (hd1)"...  15 sectors are embedded. succeeded  Running "install /boot/grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done. 


If you get this success message in your console, it means that Grub is now installed on the MBR of the USB stick.
grub> quit

Now you will need to copy the content of the ISO to the USB key. Once the USB removed and inserted again (I suppose it was unmounted while installing Grub to it), you will be in console and move to the directory where you have your iso:
cd /path/to/iso
As an example, we will say the ISO is in your home directory, so you move there:
cd /home/your_login
and as root:

mount -o loop file.iso /mnt
Where "file.iso" is the full name of your ISO image.

Then you move again there:
cd /mnt
you will copy (cp -R) all the files from the mount point to the USB stick recursively, including a directory which is hidden: the directory ".disk" and it's content. All the directories might not be necessary, (the .disk is necessary, for instance) but this is the fast and sure method. You will get error messages about one or two symbolic links, you can ignore the messages about them and continue.

In the stick, once done, we can see:
$ ls -A
.Trash-1000  casper  install   preseed
.disk  boot  dists   isolinux  pool

these are directories.

If your machine can boot to USB, you are ready to start your Live USB ! If not, try to use the plop boot manager, available for floppy and for CD's from the plop boot manager website:

Good leaders being scarce, following yourself is allowed.