SqueakNOS: Building, changing, booting and installing.

2006-08-04 22:54:00 - gera

To roll your own version of SqueakNOS, either changing the native side or the .image side, you need to know how to rebuild and boot it. This process should be as easy and fast as possible.

This article will explain the building process and the boot process, describing how to rebuild everything from scratch, how to create a new .iso image, and how to use GRUB to boot SqueakNOS from a fat/vfat, NTFS, ext2/3 or other file system, from either a harddisk or USB disk.

Quickly rebuilding and trying

We work on Linux, so it will be a lot easier to do everything from Linux. However, the same should work on other Unixes, and quite probably in Windows too, after finding the right versions of the tools.

Every distribution of SqueakNOS (.iso images) contains everything necessary to rebuild it from scratch.

Extract from the .iso image the directory "trunk", this contains part of the subversion tree of the standard Squeak build tree, and an added SqueakNOS target platform. To build SqueakNOS everything is done from within trunk/platforms/SqueakNOS, where the main Makefile is located.

$ mount -o loop SqueakNOS.iso /cdrom
$ cp -R /cdrom/trunk .
$ cd trunk/platforms/SqueakNOS

Copy, from the root of the CD the two files SqueakNOS.image and SqueakNOS.changes:

$ cp /cdrom/SqueakNOS.image Squeak3.8-6665full.image
$ cp /cdrom/SqueakNOS.changes Squeak3.8-6665full.changes

Note how the Makefile expects the .image file to be named Squeak3.8-6665full.image, and copies it as SqueakNOS.image for building the CD.

Now you are ready to roll your own SqueakNOS.iso:

$ # To simply build the kernel, obviously:
$ make
$ # To build release/SqueakNOS.iso and release/SqueakNOS.vmx:
$ make iso
$ # To build and try it with vmplayer:
$ make try
$ # To try with qemu
$ make iso && qemu -std-vga -cdrom release/SqueakNOS.iso
$ # To build a new distro (release/SqueakNOS-30-Jul-2006.zip and tar.bz2):
$ make distro    # The date in the filename is automatic

Of course, you can always open the .image in a standard squeak, modify it, save it, and try it. The .image and .changes are copied to boot/iso.template during the building of the .iso image, so you can continue working inside squeak while building and trying. This is great to make changes while you are debugging in a live SqueakNOS. It's currently also possible to have access to .changes and .sources from within SqueakNOS itself using a RemoteObjectChannel over a serial line, if you are interested in doing this, take a look at the code and comments included in the Workspace in SqueakNOS.image.

Booting from other than a CD

We are using GRUB Legacy as bootloader, so it is possible to boot SqueakNOS from anything where GRUB works, but to do it, you need to install GRUB in the media. If you are using any modern operating system there are good chances that you can just chain SqueakNOS' version of GRUB Legacy from your existing bootloader. Otherwise, or if you prefer, you can install SqueakNOS' version of GRUB in your mast boot record as main bootloeader.

The first thing you should know and remember is that a standard GRUB will not work for SqueakNOS. We have added a new command to GRUB to change the video mode (setvbe command). You will not need to recompile GRUB unless you have your own customized version. In the distribution CD you'll find a bunch of precompiled GRUB binaries, including GRUB for DOS and GRUB for Windows, as well as the standard "GRUB as master boot record" used by Linux and other OSes. SqueakNOS' version is an enhanced version including all GRUB standard features and a few more, so you can quite likely replace your GRUB with this one.

General GRUB instructions

To boot SqueakNOS with GRUB you'll need to copy a few files from the CD. On the one hand you need to copy GRUB's files from CDROM/boot/grub. If you are going to chain GRUB with other bootloader as explained latter, on most cases you only need to copy a single file to a specific location, however, if you are going to install GRUB as main bootloader you need to copy all this files to /boot/grub on your main partition. On the other hand you need to copy SqueakNOS' files CDROM/SqueakNOS.* to anywhere on the same partition.

After copying, you need to modify the text file /boot/grub/menu.lst to reflect the location of your SqueakNOS.* files. The GRUB commands kernel and module need the full path to the files, for example:

title SqueakNOS
kernel /boot/SqueakNOS/SqueakNOS.kernel
module /boot/SqueakNOS/SqueakNOS.image
setvbe 1024x768x32

As you can see, in this configuration file you can also choose SqueakNOS' screen resolution. If you are not sure what resolutions your card supports, just choose one, and if it's not supported you'll see a list of the available options.

After copying the files and configuring GRUB by changing menu.lst you need to setup GRUB as bootloader.

The first options will show you how to chain GRUB with Windows' bootloader, LILO, SYSLINUX or another version of GRUB. The following option will show you how to install GRUB as bootloader on your harddisk, and then we'll see how to install GRUB on a USB disk to boot SqueakNOS from it.

Chaining GRUB with Windows 2000/XP/2003 bootloader

For this option you need to copy the file grldr from boot/grub to C:\. Apparently this is the only way to do it. After copying it, edit c:\boot.ini with any text editor (notepad is good), and add the following line at the end:

C:\grldr="SqueakNOS / GRUB"

Note that you may need to change boot.ini's read-only attributes. In grub4dos' wiki you can find more information on using GRUB and GRUB for Windows and DOS.

This should be it! If you reboot your box, you'll see a new option in Windows' boot menu: "SqueakNOS / GRUB". Select it, after a few seconds you'll see a second menu (GRUB's) showing the options configured in boot/grub/menu.lst. Select your preferred one, and enjoy a real SqueakNOS!

Chaining GRUB with LILO

Copy grub.exe to anywhere on your main partition, for example to /boot/grub. Then add the following lines to your lilo.conf:


After rebooting, you'll have the option to boot grub (either from a menu or by writing 'grub' at the boot prompt).

Chaining GRUB with SYSLINUX

Copy grub.exe from /boot/grub to the root directory, and add the following lines to syslinux.cfg

    kernel grub.exe

After rebooting you can choose to boot into GRUB by typing 'grub' at the boot prompt.

Chaining GRUB with another GRUB

Copy grub.exe to /boot/grub of your main partition. If grub.exe already exists there, you can choose a new name, or just overwrite the old version. Then add the following lines to /boot/grub/menu.lst together with SqueakNOS' specific lines as explained before:

title GRUB for SqueakNOS
kernel (hd0,0)/boot/grub/grub.exe

When you reboot you should get a first GRUB menu served by your old version of GRUB. If you choose the option 'GRUB for SqueakNOS' you'll get a second GRUB menu from where you you'll be able to launch SqueakNOS. Note that even when the option to start SqueakNOS will be available in the first menu, it will not work as you original GRUB will lack support for the new command 'setvbe'.

Chaining GRUB with DOS or Windows 9x/ME

Copy grub.exe to /boot/grub and add the following lines to CONFIG.SYS:


Of course this could be part of a menu configuration in CONFIG.SYS.

Installing SqueakNOS' GRUB as bootloader

If you like extreme sports, you can install SqueakNOS' version of GRUB as your main bootloader. We are using it, and it should be as fine as any other GRUB, and probably better; but you must understand that, as with any other extreme sport, you are doing it at your own risk. Please read the hole section before doing anything.

Here I will describe one way of doing it, there are better and worst ways, more automatic and even more manual ways, take it or leave it. This one works for me, I really hope it works for you and it doesn't destroy your hard drive.

The first you'll need is to get to GRUB's command-line interface. There are at least two options to do this, one is to have the grub command on your unix, either because you already use GRUB, or because you download it with 'apt-get grub' or the RPM equivalent, or because you downloaded sources and compile it: just try typing 'grub' (Enter) on a terminal: if it works you can safely exit it with 'quit'. The other option is to boot from another GRUB device, like any of the previously described chaining methods or, for example, from a SqueakNOS bootable CD... I've successfully tried this latter method booting SqueakNOS.iso in a VMWare configured to have access to the Physical HardDisk (/dev/hda for example).

As with the other methods we first need to copy GRUB's files to the harddisk:

# mount -o loop SqueakNOS.iso /cdrom
# mkdir -p /boot/grub
# cp /boot/grub/menu.lst /tmp
# cp /cdrom/boot/grub/* /boot/grub
# mv /tmp/menu.lst /boot/grub

As you can see we are backing up (if it exists) the file /boot/grub/menu.lst. Now get into GRUB's shell. To do this, as explained before, you may do it rebooting your box using any of the chaining methods, booting from SqueakNOS.iso, or simply executing the command grub:

If you rebooted, once you are in GRUB's menu, press 'c' to get into command-line mode.

>From the command-line interface you have to setup grub as master boot record:

grub> root (hd0,0)
grub> setup (hd0)
grub> quit

Please note that (hd0,0) means the first partition of the first drive. If your /boot/grub is in a different partition you'll need to change that to, for example, (hd0,1), (hd0,2), etc. A good way to find out the partition number is to use Tab for autocompletion, and reading the answer for the command 'root', which should print out the file system for the partition (for example NTFS or ext3).

If you have changed menu.lst this should be enough to boot SqueakNOS, but you'll probably want to boot your previous OS too. If you had a menu.lst before you should be fine, otherwise the procedure is a little bit more complicated, and we will not explain it here. In this latter case, probably your best option is to first install any GRUB on your system using the method provided by your OS (apt-get, RPM, emerge, etc), and then, after trying it, go ahead upgrading to SqueakNOS' version of GRUB.

Booting SqueakNOS from a USB disk

If your USB disk is already bootable by any other means try using the appropriate chaining option above. If your USB disk is not bootable yet, you'll either need to install any other bootloader (DOS, SYSLINUX, etc), and then chain GRUB to it, or use the grub command if it exists on your system already, or, as a last option, download GRUB's sources, compile the grub command, and use it.

The procedure is quite similar to installing GRUB as main bootloader, except that we will trick grub to think that (hd0) is the USB disk instead of the main hard drive. So, again, first copy all needed files to the USB disk:

# mount -o loop SqueakNOS.iso /cdrom
# mount /dev/sda1 /mnt        # this line mounts the USB to /mnt
# mkdir -p /mnt/boot/grub
# cp /cdrom/boot/grub/* /mnt/boot/grub
# cp /cdrom/SqueakNOS.kernel /mnt/
# gzip -9 -c /cdrom/SqueakNOS.image >/mnt/SqueakNOS.image

Here we are copying all files from /boot/grub to the USB disk. This is not strictly necessary. If you are short on disk space you can try reducing the set of copied files. The minimum you'll need are stage1, fat_stage1_5 or the appropriate for your USB disk, stage2 and menu.lst. Also note that we are compressing the .image file to reduce the required space, but this is optional.

Now we need to install GRUB as bootloader on the USB disk. First, create a device map file, and then run grub. This time, root privileges are not required if you have the right permissions on the device file:

$ umount /dev/sda1    # better to unmount it
$ echo "(hd0) /dev/sda" >usb-device-map
$ grub --device-map=usb-device-map
grub> root (hd0,0)    # use Tab and see the answer to be sure this is USB
grub> setup (hd0)
grub> quit

In this example we are assuming the USB disk is at /dev/sda. When the device is mounted, you can run mount to see what device the USB disk is connected to. Remember that /dev/sda1 is the first partition of the device at /dev/sda.

Last notes on using GRUB

If for some reason you get to GRUB's menu, but you can't make it load SqueakNOS, it's a lot easier to try things on the command-line, and just change menu.lst when you are sure how to do it.

>From the menu, press 'c' to get into command-line mode, and there, use commands like help, kernel, module, setvbe, boot, etc. to boot SqueakNOS. Remember that using Tab for autocompletion is a very good tool to find where the files are, and what disk drivers and partitions are available.

SqueakNOS components

A working SqueakNOS is composed of the following components:

  • GRUB Legacy: The bootloader takes control after BIOS, sets up a few things, loads the kernel and .image into memory, and passes control to the kernel. In our case, we needed to modify GRUB because we wanted it to take care of changing the video mode prior to passing the control to SqueakNOS.
  • Multiboot implementation: 80% platform specific. Multiboot is a specification for a binary interface between bootloaders and operating systems. SqueakNOS implements Multiboot, so it can be loaded by GRUB, and probably other bootloaders. Part of this code is in boot/loader.s and part is in nos/nos.c and nos/multiboot.h
  • Kernel: We call kernel everything that runs natively (vs. interpreted) and that is exclusive of SqueakNOS. The Squeak interpreter and SqueakNOS plugin (basic I/O primitives and IRQ support) are part of the kernel, as well as the implementation of the display, memory management and .image file handling primitives, some initialization code, and some code for IRQ handling.
  • .image: This is a normal Squeak .image file, containing SqueakNOS and NetSqueak classes and methods. It should be straight forward to turn any .image file into one which can be booted into by SqueakNOS using a Monticello Browser.

    The Kernel itself is composed of different parts:

  • trunk/platforms/Cross: This sourcecode is common to every Squeak incarnation and should be 0% platform specific. Includes support for Named Primitives, the InterpreterProxy, and some header files. You should not need to change anything here.
  • trunk/platforms/SqueakNOS/nos/ints.[ch]: 98% platform specific. Includes code for Interrupt Descriptor Table (IDT) initialization, "glue code" to allow IRQ handling from interpreted code, PIC8259 initialization and Timer IRQ initialization and handling. You should not need to change this files unless you want to play with different frequencies for the Timer IRQ, or, of course, if you want to port SqueakNOS to a new platform.
  • trunk/platforms/SqueakNOS/nos/nos.c: 10% platform specific. This file contains support for text console output, useful for debugging the initial steps. It also has a stupid-but-working implementation of malloc(), and the glue code to transition from GRUB (Multiboot) to sqMain(). You should not need to change this file unless you are porting SqueakNOS to a new platform or improving malloc().
  • trunk/platforms/SqueakNOS/nos/sqGlue.c: 30% platform specific. Contains the implementation of functions used by Squeak to copy the Display bitmap to display memory and find out the supported display resolution. Part of this code uses information passed to SqueakNOS by GRUB. Here you can also find SqueakNOS' implementation of ioRelinquishProcessorForMicroseconds(), which may need changes in the future or if porting to a new platform.
  • trunk/platforms/SqueakNOS/nos/sqMinimal.c: 0% platform specific. This file was partly taken from sqMacMinimal.c and contains support for Squeak's attributes like the .image file name, underlying OS name, etc. You should not need to change this file, but may want to do it for cosmetic reasons.
  • trunk/platforms/SqueakNOS/nos/sqPlatformSpecific.c: 5% platform specific (as contradictory as it may sound). This file contains an implementation of a simple in-memory file, to emulate file reads and seeks from the .image file which is loaded into memory by the bootloader. It also contains the implementation for sqGrowMemoryBy() which should check whether there is enough physical memory or not, but it doesn't.

    What now?

    The intention of this article is to give you an idea of what you need to know in order to rebuild and test your own version of SqueakNOS. Be it because you want to add support for some hardware, because you want to port it to a different platform, because you want to test your own modified Virtual Machine or Plugins within SqueakNOS, or because you just want to change it's look and feel... Until we have decent persistency this is sadly the only way to do all this.

    Take care, and first of all, enjoy it!


    New .iso release comming soon.
    2006-08-05 13:23:07 - gera SqueakNOS-8-Aug-2006.iso ready for download
    2006-08-09 15:37:31 - gera hello 2006-11-29 18:48:39 - gonzaR