Booting on a PC

Booting your PC in eLua

That's right: after following this tutorial, your PC will boot directly into Lua! No OS there (this explains why the boot process is so fast), just you and Lua. You'll be able to use the regular Lua interpreter to write your programs and even use "dofile" to execute Lua code.

Details

Booting eLua involves using the well known GRUB that will be used to load a multiboot compliant ELF file that contains our eLua code. The code runs in protected mode, so you have access to your whole memory. The code does not access any kind of storage device (HDD, CDROM, floppy), so if you're worried that it might brick your system, you can relax now :) I'm only using some very basic keyboard and VGA textmode "drivers", so all you're risking is a system freeze (even this is highly unlikely), nothing a good old RESET can't handle (be sure to use the hardware reset though, CTRL+ALT+DEL is not handled by the code). But just in case, see also the next section.

Disclaimer

As already mentioned, 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.

Prerequisites

To boot your computer in Lua you'll need:

  • a 386 or better computer running Linux. I actually tested this only on Pentium class computers, but it should run on a 386 without problems.
  • GRUB. Since you're running Linux, chances are you're already using GRUB as your bootloader. If not, you must install it. You don't need to install it on your HDD; a floppy, an USB stick or even a CDROM will work as well. I won't cover the GRUB installation procedure here, just google for "install grub on floppy/usb/cdrom" and you'll sure find what you're looking for. You can try for example here, here or here.
  • The eLua i386 ELF file, see here for instructions on how to obtain it. OR download the eLua source distribution and compile it for the i386 architecture using a toolchain that you can build by following this tutorial.
  • a text editor to edit your GRUB configuration file.

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.

Let's do this

First, copy the eLua ELF file to your "/boot" directory:

$ sudo cp surprise /boot

Next you need to add another entry to your GRUB menu file (/boot/grub/menu.lst). Edit it and add this entry:

  title eLua
  root (hd0,0)
  kernel /boot/elua_lua_i386.elf (change this if the eLua file name is different)
  boot

You may need to modify the root (hd0,0) line above to match your boot device. The best way to do this is to look in the menu.lst file for the entry that boots your Linux kernel. It should look similar to this:

  title           Ubuntu, kernel 2.6.20-16-generic
  root            (hd0,2)
  kernel          /boot/vmlinuz-2.6.20-16-generic
  initrd          /boot/initrd.img-2.6.20-16-generic
  savedefault

After you find it, simply use the root (hdx,y) line from that entry (root (hd0,2) in the example above) in your newly created entry instead of root (hd0,0).
That's it! Now reboot your computer, and when the GRUB boot menu appears, choose "eLua" from it. See using eLua for instructions on how to use your newly installed self-booting programming language :)

As usual, if you need more details, you can contact us. Also, if you want to go one step ahead and have you own USB stick that boots eLua, check this tutorial.