Snniffing around on a CentOS machine on which I am supposed to have extremely limited access - certainly no root access - I ran across an older gcc (3.4) that didn’t complain when I tried to use it. So I decided to take advantage of the opportunity to give myself Haskell - a Very Nice Funcitonal Programming Language®. This turned out to be a path fraught with difficulty, so I thought I’d post the solution.
- Download the GHC binaries - from here for Red Hat and related Linuxes. This absolutely MUST be able to find libedit.so.0 - which was the crux of my problem. Not only did this not seem to be preinstalled on the system anywhere, it took a lot of coaxing to get GHC to believe that I had installed it after I did so. Which leads to the next step:
- Download and Install libedit - I found some useable sourcecode here. Since I had no root access to the machine in question, I installed it in $HOME/opt/local/lib. Using a c compiler that’s nonstandard on the system you’re compiling on means you have to tell ./configure where to find it. Do this by setting the CC flag. In my case, the command was:
$ ./configure --prefix=$HOME/opt/local/lib CC=gcc34
Then do the normal make install thing.
- Install GHC - This involves basically the same configuration flags as before, only –prefix should be $HOME/opt/local - i.e. without the /lib on the end. Then make install. This will give you Haskell.
- Set up your PATH - Naturally since you installed Haskell in a strange place you have to tell your system where to look. I added this to my ~/.profile file:
PATH=$HOME/opt/local/bin:$PATH
LD_LIBRARY_PATH=$HOME/opt/local/lib
export PATH
export LD_LIBRARY_PATH
It’s that last environment variable that made the difference - the LD_LIBRARY_PATH. Before setting that, ghci (the Haskell interpreter) would fail to laod, complaining that it couldn’t find libedit.so.0 anywhere. None of the usual flags to ./configure seemed to work - including the ones (–with-edit-libraries - or whatever it was called, I can’t remember now - in any case, you don’t need it) that claim to be explicitly for the purpose of telling ghc where to find the line editor. I guess the point is that since this is a binary install, that part of the program was already precompiled in and now can’t be changed. So you have to point it to the right place at runtime - which is fine, as it turns out. Setting the runtime linker library path variable clears up the problem, and GHC/GHCI functions just fine.
I’ve just dual-booted my Dell Inspiron 513S with Windows Vista and Gentoo Linux, apparently with success, so I thought I’d post the step-by-step. (The steps specific to installing Gentoo are given in much more detail in the Gentoo Handbook.)
Best case: install Vista FIRST. Reason being: Vista overwrites the Master Boot Record with its own boot loader - since, you know, who would ever want to use anything but Vista? Anyway - the general strategy is to let Vista have its way when it installs itself (there’s nothing that I know of that can prevent it erasing your boot record, so just go with it), and then go back and fix things from Gentoo once you’ve installed it. Which basically just means: install Gentoo in the normal way with TWO BIG EXCEPTIONS. Those are - first DON’T erase the Vista partition in the part of the manual where it tells you to erase all the disk partitions. Second - increment everything having to do with naming partitions by 1. So - for example - when the manual talks about things like /dev/sda1, you use /dev/sda2 instead. This is because everything is shifted back in the hard drive space on account of Vista being at the front. What follows more or less paraphrases the Gentoo manual with the relevant changes thrown in.
So:
- Install Vista in the usual way. This is idiot-proof - just pop your disk in the drive and let it do what it do.
- Tell Vista to resize itself. You do this in Control Panel -> Administrative Tools -> “Create and format disk partitions.” Choose “Shrink Volume” from the menu and … do so…down to a reasonable size (Vista’s bloated, so leave it some space - I gave it about 65% of my 150GB HD).
- Download Gentoo Minimal Installation CD (note - this assumes you will have an internet connection when installing). I choose the minimal CD because - well, that’s what Gentoo’s all about. You do it all by hand, and the payoff is that you get a system that has only what you specifically asked for on it - no bloat. Go to one of Gentoo’s mirrors (I usually use the Madison Chemlab) and find an appropriate directory (my computer being an Athlon Dual-Core 64-bit, I went to releases/amd64/2008.0/installcd/) and download the iso for the minimal installation. Burn this .iso to a CD.
- Boot from the CD. This will probably involve changing the boot order in your BIOS. For Dells, hold down F12 as soon as you see the “DELL” logo and it will give you a menu from which you can select what your computer boots from. Naturally, you want the CD option.
- Choose the Gentoo Kernel from the menu. It gave me four choices. In all but a very few cases you want the first choice, which is simply (and helpfully) called gentoo
.
- Test your network connection. You should now have a prompt that’s something like
livecd# . In most cases, you won’t need to worry about hooking up your network. I didn’t. To make sure, type /sbin/ifconfig at the prompt to execute a program that gives you basic information about your network. If it gives you a bunch of gibberish next to an eth0 label you’re good to go. Something like this (borrowed from Gentoo website):
eth0 Link encap:Ethernet HWaddr 00:50:BA:8F:61:7A
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::50:ba8f:617a/10 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1498792 errors:0 dropped:0 overruns:0 frame:0
TX packets:1284980 errors:0 dropped:0 overruns:0 carrier:0
collisions:1984 txqueuelen:100
RX bytes:485691215 (463.1 Mb) TX bytes:123951388 (118.2 Mb)
Interrupt:11 Base address:0xe800
You can test it against the Gentoo webpage like so:
livecd# ping -c 3 http://www.gentoo.org/
- Partition your disk. Here’s the crucial step. Run fdisk (type it at the prompt) to split up the remaining space on your disk. In fdisk, if you type p it should show you the current partition map. There should be only one - for Vista. Delete any other partitions (type d and then give it the number of the partition you want to delete). As soon as Vista is the only partition left on your disk, you’ll want to create three for Gentoo. Type n to create a new partiton followed by p to make it a “primary” partition, number it 2 (so as not to confuse it with the Vista partition, which is primary partition 1) and hit enter to start it at the end of the last partition (i.e. accept the default), and then do +32M for the first (which will be your boot partition). Make this parition bootable (type a). Do a swap partition next - again n followed by p, number it 3 and do +512M. Then hit t to explicitly choose a type - the type in this case being 82 (swap). Now eat up the rest of the disk in a third linux primary partition (remember, since Vista is there this is actually the 4th partition on the disk, so number it 4!!!). Type w to save this partition format and exit fdisk.
- Create the filesystems. These partitions are unformatted, so you have to give them a file format (else how would the computer locate anything on them?). In my case, I’m using only one SATA drive, so each partition is called /dev/sda plus the number of the partition. So Vista is on /dev/sda1, my boot partition is on /dev/sda2, my swap partition on /dev/sda3, and my primary Linux partition on /dev/sda4. I just went with the setup suggested by the Gentoo manual, which is to format the boot partition with ext2, the main partition with ext3, and the swap partition as … well, a swap partition. The specific commands are:
mke2fs /dev/sda2
mke2fs -j /dev/sda4
mkswap /dev/sda3
- “Mount” the disks - which is fancy speak for giving yourself access to them. The commands:
mount /dev/sda4 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/sda2 /mnt/gentoo/boot
In English - this just tells the system to call the main Linux parition /mnt/gentoo for now, so that you can get to it to write the files to it. You then make a directory for your boot directory and … who woulda guessed? … tell the system to call your boot partition that.
- Put the Gentoo system files onto your new disk partitions. cd into /mnt/gentoo. Surf to the Gentoo mirrors list using links, which comes on your CD:
links http://www.gentoo.org/main/en/mirrors.xml
Choose a mirror (I used the Chemlab at University of Wisconsin Madison) and download a stage 3 tarball. The name will be something like stage3-amd64-2008.0.tar.bz2 Download it, and then unarchive it:
tar xvpjf stage3-amd64-2008.0.tar.bz2
- Download Portage. Same procedure as before: go to a mirror, find a portage snapshot (portage is a nice Gentoo thing that helps you find and manage packages to download for your system - crucial to setup and maintenance), download it, and untar it:
tar xvjf portage-latest.tar.bz2 -C /mnt/gentoo/usr
It’s important to get that command exactly right (yes, it’s a capital -C) so that the packages go in the right place.
- Edit your /mnt/gentoo/etc/make.conf file appropriately. Best to read the docs for this one. In my case, I added the following lines:
CFLAGS="-march=k8 -O2 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j3"
- Choose your mirrors - i.e. where to download the operating system from. Gentoo gives you a nice way to do this:
mirrorselect -i -o >> /mnt/gentoo/etc/make.conf
- Enter the new environment. Up to now, you’ve been working from the CDROM. Now it’s time to work from within the actual hard drive. Like so:
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
env-update && source /etc/profile
export PS1="(chroot) $PS1"
The first line mounts an interface system with the kernel (main operating system). The second does the same for the hardware. Then you change filesystems into a filesystem that is rooted in what you used to call /mnt/gentoo (aka /dev/sda4). Having changed here, you need to update your environment variables so they make sense from the present location. And the last line is just some candy for the prompt to remind you that you’re in a changed filesystem environment.
- Update your system. You’re in a kind of Gentoo system already - but one big problem with it is it will, almost by definition, be out of date, since you downloaded a snapshot of a system. Update it using emerge - Gentoo’s package manager and package downloader interface:
emerge --sync
Probably it will tell you that emerge itself is out of date - in which case fix this before you do anything else:
emerge --oneshot portage
- Configure USE variables. These are flags that help Portage decide which packages to grab for you and how to compile them. I simply copied their suggestions (which assumes you’re going to be going the KDE rather than the Gnome route for your desktop later on):
USE="-gtk -gnome qt3 qt4 kde dvd alsa cdr"
Add this line to /etc/make.conf.
- Install your kernel. One of the two crucial steps. You have to grab your kernel from the Gentoo website:
emerge gentoo-sources
- Configure your kernel. The step that makes Gentoo Gentoo. cd into /usr/src/linux and type make menuconfig. You’ll get a dazzling array of options. Include everything that’s necessary - especially making sure that your filesystem and human interface devices are enabled. Don’t worry too much about getting it wrong. It will be mostly right as is, for one thing. For another thing, there are help messages to guide you. For a final thing, recompiling the kernel is much easier than you think in case you mess anything up or forget anything.
- Compile the kernel and copy it to the right place. The crucial step. Do it like this:
make && make modules_install
cp arch/x86_64/boot/bzImage /boot/kernel-2.6.27-gentoo-r8
(The name of your kernel might be slightly different, of course. Look in /usr/src/linux to be sure what it’s called.)
It takes less time to compile than your friends have led you to believe. That’s because they used the default genkernel option, which can take 10 hours or so to compile because it includes EVERYTHING. If you want to include EVERYTHING…just to be safe…you should consider Ubuntu Linux instead. Gentoo is Gentoo because you can configure it to your particular situation.
- Create your fstab file. This is how Linux knows which parts of the harddrive it can access. Getting this right is one of the important steps in dual-booting. Edit /etc/fstab to look like this:
/dev/sda2 /boot ext2 defaults,noatime 1 2
/dev/sda3 none swap sw 0 0
/dev/sda4 / ext3 noatime 0 1
/dev/cdrom /mnt/cdrom auto noauto,user 0 0
This is almost exactly the same as what the Gentoo manual tells you, bucept that the partition numbers are all += 1. This, of course, is because VISTA is on /dev/sda1, so everything is shifted down one.
- Configure your network. Which, in my case, meant doing very little since I don’t have a static IP address or designated domain name. Just add this to /etc/conf.d/net:
config_eth0=( "dhcp" )
dhcp_eth0="nodns nontp nonis"
And then make sure that it loads at boot time:
rc-update add net.eth0 default
- Set a root password. Just type passwd and follow the prompts.
- Deal with some details. Edit /etc/rc.conf, /etc/conf.d/keymaps, and /etc/conf.d/clock, doing all the obvious things. In the case of the clock file, the “obvious” thing is to add a line:
CLOCK="local"
to use your local timezone. This does rather assume that you’ve set up your local timezone already. I did that like so:
cp /usr/share/zoneinfo/America/Indianapolis /etc/localtime
Plenty of other timezones are listed in /usr/share/zoneinfo so pick the one that’s appropriate.
- Add some other necessaries. Specifically, add a system logger, a cron daemon, a file indexing system, and a dhcp client (because your network interface is only here courtesy of the CD):
emerge syslog-ng
rc-update add syslog-ng default
emerge vixie-cron
rc-update add vixie-cron default
emerge slocate
emerge dhcpcd
- Configure and load the bootloader. THE crucial step for dual-boot. Basically, the trick to dual-booting with Vista is to keep in mind that Vista messed up your Master Boot Record during install. So, you have to overwrite what it overwrote with your own bootloader. For AMD64 systems there’s really only GNU Grub. First grab it:
emerge grub
Then configure it by editing /boot/grub/grub.conf. Mine looks like this:
default 0
timeout 10
splashimage=(hd0,1)/boot/grub/splash.xpm.gz
title Gentoo Linux 2.6.27-r8
root (hd0,1)
kernel /boot/kernel-2.6.27-gentoo-r8 root=/dev/sda4 video=uvesafb:mtrr:3,ywrap,1024x768-32@85
title Windows Vista
rootnoverify (hd0,0)
makeactive
chainloader +1
The first line means to load the entry 0 of all the entries here by default. That’s the Gentoo entry. Vista would be 1 (but only because I’ve listed it second). Timeout is the number of seconds it waits before booting this by default. I set this to 10. You may want to check that the spalshimage is there. The file is right where it says: /boot/grub/splash.xpm.gz. The first bit is Grub syntax - so a word of explanation. Grub is one of those things that counts from 0, so hd0 is your first (and in my case only) hard drive - aka /dev/sda. The 1 is crucially different from the Gentoo documentation. That’s - again - because VISTA is already at (hd0,0) (aka /dev/sda1) - i.e. the first partition on the first hard drive. So in my case my Linux boot parition is (hd0,1) (aka /dev/sda2). Give it a title (what appears in the boot menu that lets you select which OS you want at boot time - call it whatever you want), tell Grub where it is - (hd0,1) - and then tell it where, specifically, the kernel file is - in this case on partition 4 - that’s /dev/sda4 to Linux, (hd0,3) to Grub - and of course you have to tell it exactly which file we’re talking about. The video flag is dependent on what kind of monitor and graphics card you’re using. In my case, one of the nVidia GeForce series with a framebuffer. Coincidentally, the same setup in the Gentoo manual, but yours might be different (or you might not need it at all). In the case of Vista, Grub doesn’t know how to boot it directly - so most of these commands just tell it where to pass control to. We tell it that there’s another operating system at /dev/sda1, but not to worry about it (rootnoverify (hd0,0)), and to use the chainloader to load it. What that means it simply that this is a proprietary OS that has its own mysterious boot method, so pass control to it and let it handle things itself.
- Install Grub to the MBR. Like so:
grep -v rootfs /proc/mounts > /etc/mtab
grub-install --no-floppy /dev/sda
The first line creates a file that Grub needs from information gathered earlier (I just do what the manual tells me), the second line tells Grub to install itself on the Master Boot Record - to wit, overwriting Vista’s MBR.
- Eject and reboot. You’re done. You have a working dual-boot with Vista and Gentoo! All that remains is to get out of your special environment and reboot:
exit
cd
umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
reboot
Of course, take the CD out of the drive and readjust your BIOS settings as necessary to boot from the hard drive. If everything worked, Grub should load and give you a menu letting you choose between Vista and Gentoo. Gentoo won’t be very impressive or functional at this stage, of course. It’s just a barebones thing that you have to set up as you go. Choosing Gentoo boots it directly, choosing Vista causes the screen to go black for a bit as control is passed to the Vista boot process, but Vista boots forthwith.
DONE!
It’s much easier than one is generally led to believe. Basically, you follow all the steps for installing Gentoo as outlined in the manual - the only REAL differences are (a) that you don’t erase all the partitions from your hard drive before proceeding but rather keep the Vista one around and (b) that all things dealing with partitions are incremented 1 higher than the Gentoo manual - since Vista occupies what that manual thinks of as the first partition. The rest of the process is exactly the same.
Knock on wood, of course - because I only did this today, so who knows what “gotchas” Vista has in store for me? None, hopefully, but we’ll see…