Sunday, December 13, 2009

Grub

Haven't posted for a while, so thought I'd go a bit geeky and give some information on the usage of various technologies (since I get asked these types of questions a lot on various IRC / IM channels). My first post will be on the architecture and usage of GRUB (note, the latest versions of Ubuntu etc using GRUB2 which is a complete rewrite of GRUB. I'll try and highlight some of the differences as I'm going along, but I'm still getting my head around GRUB2. For a complete breakdown of the differences between GRUB and GRUB2, then look here), then (at some point in the future) I'll blog about Xorg. These are the two most common queries and, in my opinion, the two most unappreciated pieces of software in existence.

So, what is GRUB? Well, simply put, it's a bootloader. However, that really is simplifying it rather too far. For one, it's the reference implementation of the Multiboot specification on the GNU OS. What this means is that it pretty much defines the de-facto standard for bootloaders. Without GRUB, you wouldn't have UNIX, Linux or even Solaris (since v10).

So, what's a bootloader? Well, generally speaking, when a computer is powered on, the BIOS reads the first 512 bytes of the hard disk (known as the Master Boot Record (MBR)). The MBR contains code known as the "bootstrap" program. Control is then passed to the bootstrap program. This is known as "Stage 1".

Stage 1 generally does little more than just load and execute code located at some other point in some partition on the hard disk, known as "Stage 2". (Actually, there is a situation where the GRUB MBR, for example, reads code from the 30K immediately following the MBR. This is generally termed "Stage 1.5". GRUB2, however, has eliminated this stage completely.).

Stage 2 generally presents an interface to the user (dependent on settings) to decide which OS to load. GRUB2 doesn't do this if there's only one OS installed, although you can get to the menu if you press the shift key. In situations where the OS installs a completely different bootloader into the MBR (such as Microsoft Windows), GRUB handles this by "chainloading", which creates a copy of the alternative MBR, and then executes that as though is was execute by the BIOS. It is this which allows GRUB to boot Windows (and even allow multiple versions of Windows).

So, how do I install GRUB? Well, it's obviously the default on most Linux distributions, but if the question really is "how do I install GRUB when it's not already installed?", the answer is to use a Linux distribution (any really small one will generally do) and use the "grub-install" routine. This will then install stage1 into the MBR, and the stage2 code into a usable partition, for example :

# grub-install /dev/hda

Installs GRUB stage1 onto the MBR of /dev/hda which is, typically, the first IDE disk. See below for typical device mappings.

# grub-install --root-directory=/boot /dev/hda

Installs GRUB stage1 onto the first disk, with the boot manager code in /boot.

So, how do I configure GRUB stage 2? Well, this is the power of GRUB really. It's all done by a single config file on the "usable" partition defined when using grub-install. In Debian, the file is /boot/grub/menu.lst, whereas in Fedora (and Gentoo) it's in /boot/grub/grub.conf. In GRUB2, it's been replaced by /boot/grub/grub.cfg (although, this is not meant to be edited, not even by root, GRUB2 provides /etc/default/grub which is merged into /boot/grub/grub.cfg when the update-grub command is used).

In terms of GRUB terminology of how your hard drive partition(s) are denoted, they follow the layout of "hd" followed by a number, a comma followed by the partition number (starting at 0 in GRUB, 1 in GRUB2), i.e. :

Primary Master=hd0,0
Primary slave=hd1,0
Secondary Master=hd2,0
Secondary slave=hd3,0

Therefore, in GRUB, hd0,0 denotes the first partition on the primary master, hd0,1 the second, and so on. In GRUB2, these would be hd0,1 and hd0,2 respectively.

A typical GRUB menu.lst looks something like this :

#
# GRUB's menu.lst config file, with examples for various OSes
#

# Default: boot the first entry. Problems? boot the second entry.
default 0
fallback 1

title Ubuntu hardy (development branch), kernel 2.6.24-12-386
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-12-386 root=UUID=d1562435-e820-4486-99b8-eaad92e502cd ro clock=pit acpi=off noapic nolapic
initrd /boot/initrd.img-2.6.24-12-386
quiet

title Ubuntu hardy (development branch), kernel 2.6.24-12-386 (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.24-12-386 root=UUID=d1562435-e820-4486-99b8-eaad92e502cd ro clock=pit single
initrd /boot/initrd.img-2.6.24-12-386

title Microsoft Windows XP
root (hd0,1)
rootnoverify (hd0,1)
makeactive
chainloader +1

title Linux from second HDD
kernel (hd1,0)/vmlinuz root=/dev/hdb1

Here showing the first partition containing an installation of Ubuntu (Hardy Heron = 8.04) on the first partition (hd0,0) and an installation of Microsoft Windows XP on the second partition (hd0,1), as well as others. The "chainloader +1" command, specifies that (as I mentioned above) GRUB should pass control over to the subsequent boot manager specified in the first sector of the relevant partition.

The version of GRUB installed can be found easily (here on my Ubuntu 9.10 installation, which uses GRUB2 by default when newly installed)

chadders-desktop:/boot/grub$ grub-install -v
grub-install (GNU GRUB 1.97~beta4)

GRUB (now termed "GRUB legacy") would have a version of 0.97 or similar.

Obviously, GRUB (and certainly GRUB2) is an extremely complex beast. A full breakdown of all commands etc is explained at https://help.ubuntu.com/community/Grub2.

Saturday, November 08, 2008

More musings on Xubuntu

I'd been getting more and more annoyed with some bugs in Xubuntu 8.04 ( Hardy Heron ), particularly with USB drives being detected twice and my DVD+RW drive not working correctly. I also had occasional problems with wireless not detecting the access point, or if it did, it didn't connect properly using WPA (although, WEP was usually fine).

They weren't major bugs, but they were annoying. I'd also realised that I hadn't used my Ubuntu 8.04 partition since I installed it. So, a week ago, I made the jump to Xubuntu 8.10 ( Intrepid Ibex ), completely repartitioning the drive and having solely 8.10.

To say I'm impressed would be an understatement. I'm also glad that I upgraded my Nvidia card a while ago, since previous nvidia cards aren't supported under the 8.10 kernel (2.7.1.27), so they regress to the "nv" driver which doesn't support 3D acceleration. Fortunately, I don't have any of those problems.

So, let's run through the checklist :

1. USB drive(s) detected correctly? check.
2. DVD drive(s) detected correctly? check.
3. Wireless functionality working? check.
3. Anything else that was annoying me with 8.04 fixed? check.

Astonishing. The speed increase of 8.10 is also breathtaking. It won't be long, and more and more people will be on Linux, and at that point, the world will be a better place.

Friday, October 24, 2008

Not much to say...

Wow... how long has it been since I posted anything? Frankly, this post hasn't got much to say either. However, I just wanted to post a link to possibly the most beautiful landscape picture I have ever seen...
http://flickr.com/photos/dotdoubledot/1281864495/sizes/l/
Astonishing.

Friday, April 25, 2008

Hardy Heron and NVidia

Well... I've finally taken the leap from Feisty to Hardy, and wow... I'm glad I did. The performance difference alone is worth the money. I've currently got Xubuntu and Ubuntu dual booting (lovely tool GRUB!).

Most stuff worked straight out of the box, apart from one thing. The nvidia drivers had a problem initialising, the "nv" drivers worked ok, but not the nvidia ones, and, unfortunately, you need the nvidia ones for 3D acceleration to work, and, of course, you need 3D acceleration to do Second Life etc. etc.

The problem I was having was that every time I installed the nvidia 96.43 drivers (I have a GeForce4 440MX), the display looked rubbish (to the point where I couldn't even read the text). So, a quick look at /var/log/Xorg.0.log showed the following error :

Failed to initialize GLX extension (Compatible NVIDIA X driver not found)

It all basically (after about two days of investigation) found that there's a bug in Hardy which doesn't detect the monitor correctly, so you basically have some kind of basic monitor which doesn't have the correct resolutions, and this throws the driver completely. Anyway, a quick addition of :

SubSection "Display"
Viewport 0 0
Depth 24
Modes "1024x768" "800x600" "640x480"
EndSubSection

to the xorg.conf file and it sorted it.

Other than that, no problems, and more than happy.

Saturday, March 15, 2008

Data breaches

I blog quite a bit about the amazing ineptitude of various government departments with regards to data security. On the subject, FlowingData has published a picture of the 10 largest data breaches since 2000. It's fascinating reading.

Thursday, January 03, 2008

Virtualisation (take 3)

Okay, one minor hiccup overcome. I attempted to RDP into one of my VirtualBox VMs yesterday, and found that I couldn't, for one reason and one reason only. By default, VirtualBox (on Linux, anyway) sets up the VM running via a NAT connection, and for those in the know, this basically piggybacks on the current IP address, rather than getting it's own MAC / IP address. This is fine for VMs where you only ever want to communicate "out", i.e. surf the web from the VM etc., but when you want to use them as "servers", i.e. to communicate "to" them, it's no good. And this is precisely what I pretty much exclusively use them for.

Well, it's a bit bizarre to set up a bridging network in Ubuntu, but it is possible, and actually works really well, it's just a little bit more fiddly than VMware, which does it by default.

I'm not going to go into too much detail (if anybody wants the detail, then by all means email me), but you basically have to set up some custom bridging network adapters, (via the bridge-utils package), assign the bridged adapter an IP address, and then associate the VM with the adapter. Now, I've currently only got it working via DHCP, and, unfortunately, my router's not fantastic at this, so, in the past, I've tended to manually assign the IP addresses to my network nodes, but it seems to be working at the moment, fingers crossed.

I suppose a downside, and it's whether you consider it a downside or not, is that, using this approach, you have to have a seperate bridge adapter for each VM, since VirtualBox can't even start a VM which is sharing an adapter, but I can live with this at the moment, even though I have 5 adapters defined. Fortunately, a quick

$ ifconfig down

disables the currently unused adapter.

So, what's the state of play?

Well, I currently have the following VMware VMs :

1. MediaWiki running via a JumpBox
2. Oracle Enterprise Linux 5
3. Minix

And the following VirtualBox VMs :

1. Ubuntu 7.10
2. Ubuntu 7.10 JeOS
3. Google gOS
4. Damn Small Linux 4.2.2

Sad, moi? ;-)

Saturday, December 29, 2007

Virtualisation (take 2)

Well, hope everyone had a nice christmas and are looking forward to a great new year. I certainly am.

Anyway, just thought i'd blog about a development in my quest for the perfect virtualisation approach. People who know me know that I am passionate about the use of Virtual Machines (VMs) for practically everything I do. I just love the idea of having my main OS (currently Ubuntu 7.04), but being able to run Ubuntu / OpenSUSE / Damn Small Linux (DSL), or, indeed, any other OS that has the feature that I require (such as my 11g instance on Oracle Enterprise Linux, or my Ubuntu 10g XE database, again all running as RDP'able VMs).

In the past, I've always used VMWare Player, and got my head around the creation of VMDK and VMX files by the use of QEMU. However, recently, I've started to get my head around VirtualBox, an open-source project for managing your VM server, and, I must say, how impressed am I? The software is an absolute breeze to install / run, and the creation of the VMs through the use of wizards is a bit funny to start off with, but once you understand it, it's by far the easiest way to create all the fiddly configuration settings for a given VM, such as hard disk size, memory usage etc.

One problem with simply using VMWare player, as opposed to VMWare Workstation (or similar), is that you have to basically manage your VM server like you're managing file(s) and window(s), i.e. through a file manager. However, what I like about VirtualBox is that the software is
full enterprise-class software, having a VM manager, the full works! And, the fact that it's one of the only software which fully supports Remote Desktop Protocol (RDP) (although, you can do this with other VM products, they don't fully support it... not yet anyway). For a little bit more information on this, see here.

Of course, it's OSS as well, and extremely light-weight.

So, as I'm writing this, Ubuntu 7.10 is being installed. I'll let you know how I get on with my future VM projects in future blog posts.

Have a happy new year!