mathr / blog / #

Installing Linux on a 386 with 4MB RAM

I may have posted about this before, I forget. Anyway, the way I did it before was messed up, primarily because I had 3 data partitions on a 50MB hard drive, which was excessive, and secondarily because I managed to fubar the previous installation completely by upgrading to an incompatible version of uClibc, which meant that no programs at all could start. So I reinstalled from scratch, and here's how. Some knowledge of Linux is assumed.

Phase 1: Install smalllinux2

Get smalllinux2, follow its instructions and make two floppy disks 'boot' and 'root'.

Insert the 'boot' disk into your 386 and turn it on. Insert the 'root' disk when prompted, and log in as the root user.

fdisk /dev/hda to partition the hard disk (warning: this will erase all data). Primary Partition 1: 4MB swap. Primary Partition 2: the remainder of the disk, bootable Linux.

mkswap /dev/hda1 -- make the swap partition able to act as swap.

mkfs.ext2 /dev/hda2 -- make the data partition able to store data.

mkdir /mnt/hd -- make a directory to mount the data partition on.

mount -t ext2 /dev/hda2 /mnt/hd -- do the mount.

cp -a /bin /lib /etc ... /mnt/hd/ -- copy root filesystem to hard disk, you should know enough about Linux to know what needs to be copied.

mkdir /mnt/floppy -- make directory to mount floppy disks on. Now eject 'root' floppy and insert 'boot' floppy.

mount -t ext2 /dev/fd0 /mnt/floppy -- mount 'boot' floppy.

cp -a bzImage lilo.conf lilo.gz ... /mnt/hd/boot/ -- copy boot stuff to hard disk, you should know enough about Linux to know what else needs to be copied and where.

umount /mnt/floppy -- unmount 'boot' floppy and eject the disk.

e3 /mnt/hd/boot/lilo.conf -- set up LILO to enable booting from hard disk (e3 is a text editor).

gunzip /mnt/hd/boot/lilo.gz -- uncompress lilo.

/mnt/hd/boot/lilo -v -r /mnt/hd -C boot/lilo.conf -- the -r flag does a chroot, for some reason this is necessary for it to work properly...

e3 /mnt/hd/etc/inittab -- set up what should run on start-up.

mkdir /mnt/hd/mnt /mnt/hd/mnt/floppy /mnt/hd/proc -- create some directories.

Fingers crossed, reboot now should boot from the hard disk - so go for it!

Now some configuration can be done, for example I edited /etc/init.d/rcS to set the hostname and turn swap on at boot time, and I edited /etc/passwd to make root's home directory be '/root/' instead of '/'.

Phase 2: Backup

To make it easier to redo the install, now back up the system.

mkdir /root/backup -- create a place to store the backup.

tar -c -v -z -f root/backup/bin.tar.gz bin/ -- create archives for each directory in '/' similarly.

Now copy via floppy(s) to your main computer for backup. A reinstall now will just involve untarring these archives and running lilo.

Phase 3: Upgrade Kernel

Kernel 2.4.22 is kinda old, so I wanted to upgrade to Kernel 2.4.32. It was relatively easy to compile the kernel to boot on a 386, there were some issues with TSC from what I remember (on boot it would complain about needing a newer CPU and panic). A couple of tries and it worked fine, you can set a prefix for make modules_install so it doesn't install in /lib on the compiling computer. Once copied to the 386 you need to edit lilo.conf and run lilo before the new kernel is bootable.

Phase 4: Cross-compile A New System With uClibc/buildroot

smalllinux2 is rather lacking in software. I wanted more. So I download uClibc/buildroot, and followed the instructions to compile the software I wanted. Once configured and compiled, I mounted the generated ext2 file on a directory using the loop device, and tar'd each directory in its / and /usr, and copied them to the 386 to be unpacked in a temporary directory in /root (hint: 'split' and 'cat' help when an archive is too big to fit on a floppy). The software I selected was just small enough to fit on my 386's small drive, I needed to delete the .tar.gz files as I unpacked them.

Then chroot into the new unpacked filesystem, with the new uClibc and all sorts of wonderful software, and check that it works ok. If it does, then reboot from the smalllinux2 floppies, and 'new lamps for old' the system on the hard disk (mv /mnt/hd/* /mnt/hd/OLD, mv /mnt/hd/OLD/root/* /mnt/hd/, be careful with /boot and /lib/modules/ though).

A final reboot should give you a brand spanking up-to-date Linux (on a 15-year-old computer...). Note that this first reboot may take an immensely long time (over an hour on my 386SX-20) as it involves generating private/public key-pairs for a number of cryptographic thingies like ssh. Just leave it going and everything will be fine eventually. Later reboots will be much quicker.

Phase 5: Enjoy Your New Linux System

The End. Coming soon... the kernel config and uClibc/buildroot config I used.

Everlast - Whitey Ford Sings The Blues - 11 - Praise The Lord


motherboard 5 tinies