From: Kenn Humborg (kenn at domain research.wombat.ie)
Date: Sun 24 Oct 1999 - 21:50:58 IST
On Sun, Oct 24, 1999 at 08:11:39PM +0100, Vincent Murphy wrote:
> i was thinking about building a linux system from scratch over the weekend,
> basically as a learning exercise. all going well i would use the machine
> for day-to-day stuff, and maybe try the same thing with netbsd or something.
> i was hoping some of the gurus on the list could clarify some points for me.
First off, you're a bit mad, you realise that? :-)
> from reading gcc docs, i reckon i am going to need to build gcc for the
> target machine on a host machine. however, i'm not sure whether this will
> be sufficient. will the toolchain (binutils and stuff) be built for the host
> machine or the target machine? do i need to build a cross-compiler for the
> target system on the spare system, and then build a native compiler on the
> cross-compiler (on the spare system)? this is getting complicated.
Are the host and target system the same architecture? If so, then no
cross compiler is needed. Just build binutils and gcc as normal.
You'll also need bash, sh-utils, fileutils, textutils, gnumake and glibc to build
stuff on the target, so you'd want to compile them up too.
For booting the target, you'll need init and a basic inittab that
just runs (say) /etc/rc.d/rc.sysinit. This should just fsck and mount
filesystems and drop you to a shell. (Oops - you'll need to compile
up e2fsck as well...)
At this point, you've got a bunch of binaries on your host machine.
Best thing to do is probably to configure them to use a /usr/target-binaries
prefix, so that you know exactly what went where when you do the
make install. (You _will_ have to do a make install for some of them
anyway. Trying to decipher what the gcc build is going to install from
looking at the makefiles will drive you mad. Trust me, I've just
built a GCC cross compiler and it's a scary piece of code.)
Now boot the target with some sort of boot/root floppy or rescue
disk, make the filesystems and copy over the binaries you've built.
(They'll have to be copied into the same locations (/usr/target-binaries)
as on the host, because things like GCC will have paths to certain
files and directories compiled in. Eventually, you will rebuild them
on the target with a --prefix=/usr and re-install.)
This assumes that you can get networking working with the rescue
disk, otherwise you'll be swapping hard disks around...
Manually create the necessary stuff in /dev and /etc (probably just
/etc/inittab, /etc/mtab and /etc/fstab).
Now boot from your floppy and specify the target systems root filesystem
as the root.
Now copy over a kernel source tree and build. Also get the LILO
sources and build. At this stage, you'll be able to boot the target
without the boot floppy.
From here on, it's just download, compile, install and configure.
If you want the system to be Filesystem Hierarchy Standard-complient,
you'll need to patch a lot of these other packages.
Note that this method isn't a completely from-source method because
we're using a pre-prepared boot floppy. You could compile your own
boot floppy to get around that 'technicality'.
This is a hell of a lot of work, and not really worth it from a
'learning experience' point of view. You'd probably learn more
by building your own boot/rescue floppy set.
Of course, if the host and target are different architectures, (and
nobody's done the target architecture before) then the rules of the
game are completely different. Your first step is to get a GCC
cross-compiler built (no trivial task). Then port the kernel and
build a minimal kernel. Boot this kernel (somehow) and copy over
the essentials (previous compiled with the cross-compiler).
As it happens, I'm getting involved with the Linux/VAX project and
we're at just this stage. The cross-compiler is about 60% done
and the kernel compiles (but doesn't link). The VAX boot code
seems to work (in that it boots across the ethernet, enables VM,
switches to C code, prints a couple of messages and halts).
We've got a long way to go yet. Fun stuff!
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:04:47 GMT