[Home]GnuFromScratch

University Of Warwick Hurd User Group | RecentChanges | Login

A proposed project - a guide to creating a GNU install from scratch. The following is a work in progress, and is subject to change.

Part 1

Introduction

Foreword

This is a manual to compiling your own GNU system from scratch. At the end you will end up with a running GNU system, compiled and customised to your wishes.

How to build a GFS system

The GFS system will be built by using bing's Hurd LiveCD onto a computer that has no other operating systems installed. You will compile your own toolchain on the hard drive, and use it to build the system.

The tutorial is based on [LFS (development version)], and follows it very closely. If you have built an LFS system before, you should find GFS to be a very familiar process. In fact we stick to LFS so closely that we use the same packages as they do. This saves us time in testing, and ensures a larger user base that has tried this combination of packages exists.

The hardware and other limitations

Below are recommendations for the hardware you should use:

Additionally USB and sound are currently not supported, and PCMCIA support is still in the final stages of completion.

Naturally, you also need to be able to burn a CD image and boot from it.

You should also have a reasonable working knowelege of how the GNU system works. If you are new, try installing Debian Hurd first, and play with that system for a while first. You are also advised to read the [GNU/Hurd User's Guide].

(TODO: add links to the above)

Part 2

In this part we will prepare the system for the Hurd building.

Obtain the LiveCD and boot from it

First, download and burn the [Hurd LiveCD]. There is a copy mirrored under http://www.uwhug.org.uk/gfs/current/livecd/.

Boot from it. If you have problems booting from a CD you may need to use [sbootmgr]

Creating a partition

After booting, you will see the GNU logo, and the login shell. Enter the following into it:

 login root

You should now be root. Now you need to create the partition table.

 cfdisk -g

Create a 3500MB partition at hd0s1, and a 256MB partition at hd0s2. The rest of the tutorial assumes you have done so.

Write the partition table. If cfdisk fails to re-read the table, reboot and login as root again.

Now create a filesystem. We will be using ext2.

First you need to create the corresponding devices.

 cd /dev
 ./MAKEDEV hd0s1 hd0s2

Creating a filesystem on the partition

Now you can create a filesystem on the partition.

 mke2fs -b 4096 -o hurd /dev/hd0s1

Mounting the new partition

At this point it would be a good idea to enable swap.

 swapon -n /dev/hd0s2

 mkdir /mnt/gfs
 settrans -c /mnt/gfs /hurd/ext2fs /dev/hd0s1

Get Packages

First you need to make sure you have an Internet connection. At boot, DHCP should have configured your networking for you, but if it did not, you can manually set an IP address by excecuting something along the lines of

 settrans -fga /servers/socket/2 /hurd/pfinet \ 
     -i eth0 -a 192.168.0.5 -g 192.168.0.1 -m 255.255.255.0

If configuring networking manually, you also need a nameserver entry in your /etc/resolv.conf file.

 cat > /etc/resolv.conf << "EOF"
 nameserver XXX.XXX.XXX.XXX
 EOF

where XXX.XXX.XXX.XXX is the IP address of a domain name server.

Now, create a directory where all the sources will go.

 mkdir /mnt/gfs/sources
 cd /mnt/gfs/sources

We use the stock packages from LFS for now, and will modify the patch set as needed to work on the Hurd. For now, get the LFS package set, as described on [their website]. If you want an easy tarball, one can be found under http://www.uwhug.org.uk/gfs/current/packages/.

 wget http://www.uwhug.org.uk/gfs/current/packages/lfs-packages-development-20060503.tar

The tarball also includes most needed packages. In addition to those you also need GNU-specific packages, such as gnumach, hurd, and mig. They can be found at these locations:

 wget http://www.uwhug.org.uk/gfs/current/packages/gnumach_cvs20060303.tar.bz2
 wget http://www.uwhug.org.uk/gfs/current/packages/hurd_cvs20060303.tar.bz2
 wget http://www.uwhug.org.uk/gfs/current/packages/mig_cvs20060303.tar.bz2

There are some patches required; these are kept under http://www.uwhug.org.uk/gfs/current/patches/.

By now you should have all the sources and patches that go with them in /mnt/gfs/sources.

Final preperations

We will compile the first set of temporary tools into /root/tools. LFS creates a symlink to /, but we are unable to create a symlink at the root of the LiveCD, and so we do the whole thing somewhere we can write to.

 mkdir /mnt/gfs/root/tools
 ln -s /mnt/gfs/root/tools /root/tools

Since GNU does not use /usr, but many programs insist on using it, we also need to create a /usr symlink.

 cd /mnt/gfs
 ln -s . usr

LFS uses an LFS user to do the next stage, but for us it is not necessary since we have no installation to break by running as root.

Next we will set up the environment for the compile. Should the Hurd crash at any point from now on, re-run the following steps before continuing again.

 cat > ~/.bash_profile << "EOF"
 exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
 EOF

 cat > ~/.bashrc << "EOF"
 set +h
 umask 022
 LC_ALL=POSIX
 PATH=/root/tools/bin:/bin:/usr/bin
 export LC_ALL PATH
 EOF

Now to make sure the settings are applied to your working environment log out and back in

 logout
 login root

Constructing a temporary system

We will now build a temporary system in /root/tools, with which we will later build the minimal system in a chroot.

Patch

Since the livecd does not come with patch, we need to get our own. Unpack the source, and go into the directory.

 cd /mnt/gfs/sources
 tar -xvjf patch-2.5.4.tar.bz2
 cd patch-2.5.4

Then configure it to install into /root/tools, make, and install.

 ./configure --prefix=/root/tools
 make
 make install

Now we are ready to compile binutils

Binutils Pass 1

First unpack the source

 cd /mnt/gfs/sources
 tar -xvjf binutils-2.16.1.tar.bz2
 cd binutils-2.16.1

Create a build directory

 mkdir ../binutils-build
 cd ../binutils-build

configure to install into our temporary location and not to use internationalisation

 ../binutils-2.16.1/configure --prefix=/root/tools --disable-nls \ 
     --host=i486-gnu --build=i486-gnu

Compile and install...

 make
 make install

Prepare for linker "adjusting" phase later.

 make -C ld clean
 make -C ld LIB_PATH=/root/tools/lib

Do not remove the build directory yet, as we will need it later.

Gcc pass 1

Now we will compile gcc which we will use to compile things after we chroot.

 cd /mnt/gfs/sources
 tar xjf gcc-4.0.3.tar.bz2
 cd gcc-4.0.3
 wget http://www.uwhug.org.uk/gfs/current/patches/gcc-4.0.3-gnu_fixes-1.patch
 patch -Np1 -i ../gcc-4.0.3-gnu_fixes-1.patch
 cd ..
 mkdir gcc-build
 cd gcc-build
 ../gcc-4.0.3/configure --prefix=/root/tools \ 
     --with-local-prefix=/root/tools \ 
     --disable-nls --enable-shared --enable-languages=c \ 
     --host=i486-gnu --build=i486-gnu

Now, proceed to the compilation.

 make bootstrap

This command causes gcc not to just compile, but to compile 3 times. It uses the programs compiled in a first round to compile itself a second time, and then again a third time. It then compares these second and third compiles to make sure it can reproduce itself flawlessly. This also implies that it was compiled correctly.

After the compilation is complete, install the newly compiled compiler

 make install

Many programs and scripts run cc instead of gcc, which is used to keep programs generic and therefore usable on all kinds of UNIX systems where the GNU C compiler is not always installed. We work around that by providing a symlink to cc.

 ln -vs gcc /root/tools/bin/cc

Headers

To compile glibc we will need mach and hurd headers. These are obtainable from the respective packages, found at

After downloading the source packages into the /mnt/gfs/sources directory, run

 cd /mnt/gfs/sources
 tar xjf gnumach_cvs20060303.tar.bz2
 tar xjf hurd_cvs20060303.tar.bz2
 tar xjf mig_cvs20060303.tar.bz2

This will unpack the archives. Then configure gnumach, and install mach headers.

(Note: Do we really need more than just Hurd headers, here?)

Mach interface generator

 cd ../mig
 ./configure --prefix=/root/tools --host=i486-gnu --build=i486-gnu
 make
 make install

GNU Mach headers

 cd ../gnumach
 ./configure --prefix=/root/tools --host=i486-gnu --build=i486-gnu
 make install-headers

Hurd headers

 cd ../hurd
 ./configure --prefix=/root/tools --host=i486-gnu --build=i486-gnu
 make install-headers no_deps=t

Glibc

Now we are going to build glibc. First, unpack and patch it:

 cd ..
 tar xjf glibc-2.3.6.tar.bz2
 cd glibc-2.3.6
 patch -Np1 -i ../glibc-2.3.6-gnu_fixes-1.patch

First, create a build directory.

 mkdir ../glibc-build
 cd ../glibc-build

Then, configure glibc.

 ../glibc-2.3.6/configure --host=i486-gnu --build=i486-gnu --prefix=/root/tools \ 
     --without-cvs --enable-add-ons="" --without-selinux \ 
     --without-tls --disable-profile --with-binutils=/root/tools/bin \ 
     --without-gd --with-headers=/root/tools/include libc_cv_z_relro=no

Compiling will take quite a while. :)

 make

Finally, install it.

 make install


for much later: after glibc is installed, make and make install hurd make -r kernel in mach4/kernel copy mach4/kernel to /boot/kernel


University Of Warwick Hurd User Group | RecentChanges | Login
Login to edit | View other revisions | Search MetaWiki
Last edited April 12, 2007 7:43 pm by JasonCozens (diff)
Search: