Working as a remote admin I’ve often met situations
where the datacenter wasn’t able to provide me with
the OS I wanted. Having to chose between working with an OS
that didn’t fits my needs, changing the datacenter and installing
the OS I wanted I often chose the later.
it is not intended to be a step by step tutorial.
Prerequisites
- the installed OS must have a bootloader that can boot from a tftp server
- your OS of choice must have the ability to boot with a memory resident file system
- you must have access to a tftp server
- you must have access to a system with your OS of choice installed
RedHat to FreeBSD
The following steps are for a FreeBSD install over RedHat
but can be easily adjusted for most of the combinations
- 192.168.0.3 is the ip of the RedHat server
- 192.168.0.1 is the ip of a tftp server (which is the gateway for the RedHat
server in the same time), the tftp server and the RedHat server don’t have
to be on the same network
1. Configuring the bootloader
In this example we’re going to use grub as it supports
a wide variety of OS’s
- download the latest version of grub (currently 0.93)
- download this patch to allow grub to alternatively boot two OS’s
without external intervention (patch details)
- apply the patch in the grub-0.93/stage2 directory
- install grub with support for your network card
- configure grub to boot your current OS
timeout 10
title RedHat
root (hd0,0)
kernel /vmlinuz ro root=/dev/hda1
initrd /initrd.img
savedefault
- reboot
- edit grub’s config again and add the entry for tftp boot
timeout 10
title RedHat
savedefault 2
root (hd0,0)
kernel /vmlinuz ro root=/dev/hda1
initrd /initrd.img
title TFTP BOOT
savedefault 1
ifconfig –address=192.168.0.3 –server=192.168.0.1 –gateway=192.168.0.1
root (nd)
kernel /tftpboot/kernel.gz
- reboot again
- At this point your next reboot will boot using the TFTP BOOT entry,
and in case of failure you will need an external reboot to boot it back
using the installed OS
and without the two extra reboots, the downside of this method is
that you won’t have a way to boot the installed OS in case of a failure
2. Compiling your kernel
On a FreeBSD system compile a kernel with minimal options
Be sure to include support for your network card
Include the following options:
options MFS
options MD_ROOT
options MD_ROOT_SIZE=34000 (this must be bigger or equal with the size of
your root image)
built your kernel:
make buildkernel KERNCONF=YOUR_CONFIG NO_MODULES=yes
For more information about building custom kernels on freebsd
Please see the handbook and the related man pages
http://www.FreeBSD.org
3. Create the root image
- creating the new file system
vnconfig -s labels -c vn0 rootfs
disklabel -r -w vn0 auto
newfs vn0c
mount /dev/vn0c /mnt/rootfs
- install a minimal freebsd distribution in /mnt/rootfs
For tips & tricks : http://neon1.net/misc/minibsd.html
- Be sure to include sshd
- Configure the network with the details of the server where
this is going to be used
- Add yourself an account to be able to login with ssh and su to root
4. Insert the root image into kernel
For this you can use the write_mfs_in_kernel program which comes with freebsd.
You can find it at /usr/src/release/write_mfs_in_kernel.c
gzip kernel
Copy kernel.gz to your tftp server
5. Booting minibsd
- Reboot the RedHat server which will boot the kernel from the tftp server
If everything went ok you should be able to ssh to the old redhat server
running now your minibsd.
Once logged in you can format the harddisk and install freebsd
using your preferred method.
Enjoy.
Emilian M. Ursu
emu@emuadmin.com