Booting eLua from an USB stick

This is follow up of this tutorial. After completing it you'll be able to boot eLua directly from your USB stick (provided, of course, that your computer can boot from an USB stick, which is true for most computers nowadays). You might want to check the boot your PC in eLua tutorial first for more details. If you have an old USB stick that you don't use anymore, and/or the shear geekness of this idea makes you feel curious, this tutorial is definitely for you :)

Disclaimer

As mentioned here, the code won't try to access any kind of storage (HDD, CDROM, floppy), not even for reading, so you don't need to worry about that. Also it doesn't try to reprogram your video card registers, so it can't harm it or your monitor. It only implements a "protected mode keyboard driver" that can't physically damage anything in your system. In short, I made every effort to make the code as harmless as possible. I tested it on 5 different computers and in 2 VirtualBox emulators, and nothing bad happened. That said, there are no warranties of any kind. In the very unlikely event that something bad does happen to your system, you have my sincere sympathy, but I can't be held responsible for that. Also, I can't be held responsible if you mess up your HDD by failing the GRUB installation procedure (even though, once again, this shouldn't be possible unless you really insist on messing it up). If you're new to computers or Linux, this tutorial might not be for you. Your call.

Prerequisites

To have your own bootable eLua USB stick you'll need:

The rest of this tutorial assumes that you're using Linux with GRUB, and that GRUB is located in /boot/grub, which is true for many Linux distributions.

Backup your stick

Since the stick is going to be formatted, make sure to backup the data from your stick first (you can copy it back after finishing the tutorial).

Partition and format your stick

Depending on your stick, this step might not be required, but chances are you'll need to re-partition and re-format your stick before installing GRUB on it. The problem is that many sticks have a very creative, non-standard partition table, and GRUB doesn't like that. I looked at the original partition table of my eLua USB stick and it scared me to death, so I had to follow this procedure. In short, you'll need to delete all the partitions from your stick, create a new partition, and then format it. For a step by step tutorial check here.

Install GRUB on your stick

First, mount your freshly formatted stick (I'm going to assume that the mount directory is /mnt):

$ sudo mount /dev/sda1 /mnt

(of course, you'll need to change /dev/sda1 to reflect the physical location of your USB stick. You should know the physical location from the previous step). Then copy the required GRUB files to your stick:

$ cd /mnt
$ mkdir boot
$ mkdir boot/grub
$ cd /boot/grub
$ cp stage1 fat_stage1_5 stage2 /mnt/boot/grub

Copy the eLua ELF file (elua_lua_i386.elf in this example, change the name if needed) to the GRUB directory as well:

$ cp elua_lua_i386.elf /mnt/boot/grub

Create a menu.lst file for GRUB with you favorite text editori (I'm using vim):

$ cd /mnt/boot/grub
$ vim menu.lst
  title eLua
  root (hd0,0)
  kernel /boot/grub/elua_lua_i386.elf 
  boot

Now it's time to actually install GRUB on the stick.

$ sudo -s -H
# grub

Now we need to find the GRUB name of our USB stick. We'll use the "find" command from
GRUB and our eLua ELF file to accomplish this:  

grub> find /boot/grub/elua_lua_i386.elf
(hd2,0)

GRUB should respond with a single line (like (hd2,0) above). If it gives you more
than one line, something is wrong. Maybe you also installed eLua on your HDD? If so,
delete the /boot/grub/elua_lua_i386.elf file from your HDD and try again. 
You might get a different (hdx,y) line. If so, just use it instead of (hd2,0) in the 
rest of this tutorial.

grub> root (hd2,0)
grub> setup (hd2)
  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 (hd2)"...  15 sectors are embedded.
  succeeded 
  Running "install /boot/grub/stage1 (hd2) (hd2)1+15 p (hd2,0)/boot/grub/stage2
  /boot/grub/menu.lst"... succeeded
  Done.
grub> quit

That's it! Now reboot your computer, make sure that your BIOS is set to boot from USB, and enjoy! See using eLua for instructions on how to use your new toy :).

As usual, if you need more details, you can contact us.