Last Modified: Sep. 21, 2011

Lab 4x: Creating a Bootable Root Filesystem

The purpose of this lab is to be able to boot into your minimal root filesystem on the CentOS system.

There are three different ways you can do this, and thus the three procedures below:

Procedure One

Boot into your minimal root filesystem from the existing boot partition on /dev/sda1.
To do this, you will need to make a unique ramdisk (initrd.img) file for your root filesystem, and edit the grub.conf file to add a new entry for your new OS.
  1. Log on to a terminal interface as root.
  2. Mount the filesystem to the /linux directory.
  3. Change directory to your root filesystem, and make a top-level directory called etc
  4. Copy the /etc/fstab file to /linux/etc
    Edit this file to change the root file system to your minimal filesystem, and remove the swap entries. Make sure the root file system is set to ext2!
  5. Create an initrd ramdisk for your root file system on your pendrive:
    mkinitrd --fstab=/mnt/etc/fstab /boot/initrd.img $(uname -r)
  6. All that is left now is to make the appropriate entry in the /boot/grub/grub.conf file for your new root filesystem. You will need to complete the following four line entry:
    title 
    	root
    	kernel
    	initrd

Procedure Two

This is like procedure 1 except that you create a boot directory on /dev/sda3 so that your system has its own kernel.
  1. Make a top-level directory called boot on your minimal root filesystem.
  2. Copy the kernel and the initrd.img file you made above into this new directory.
  3. Make a grub subdirectory under your boot directory.
  4. Copy the stage1 and stage2 files from the /usr/share/grub/i386-redhat directory into the grub directory you just made.
  5. Copy the grub configuration file, grub.conf and the splash screen file, splash.xpm.gz, from the /boot/grub directory on your hard disk to your grub directory.
  6. You should now have four files in your grub directory.
  7. Install the GRUB boot loader by running the grub command and wait for the prompt:
    grub >
  8. Type the following three commands in succession:
  9. Now you need to make the two entries in the grub.conf file for original and your new root filesystem3. You will need to complete two of the following four line entries:
    title 
    	root
    	kernel
    	initrd
  10. The last step to test your new configuration is to change the active partition to sda3 in the MBR partition table.

Procedure Three

Create a Ramdisk to boot directly into.
This involves four steps:
  1. Create the ramdisk.
  2. Create the root filesystem files.
  3. Compress the filesystem giving it the name initrd.gz
  4. Create the grub.conf entry.
Create the ramdisk:
  1. dd if=/dev/zero of=initrd bs=1k count=4000
  2. mkfs -t ext2 -m 0 -N 512 initrd
  3. mount -o loop initrd /mnt
Create the root filesystem:
  1. Change directory to /mnt and repeat lab 3.
  2. add the ram0 device to the dev directory:
    mknod ram0 b 1 0; chmod 640 ram0
Compress and rename the filesystem:
  1. Change back to your home directory and unmount the ramdisk:
    cd; umount /mnt
  2. gzip -v9 initrd
  3. copy the initrd.gz file to the same location as the kernel that you will boot.
Create the grub.conf entry:
title RamDisk Linux
	root
	kernel
	initrd

To turn in

Create a lab4x file from a recursive long listing of your minimal root filesystem and append to it the contents of your grub.conf file. Turn in this lab4x file to your account on opus.cabrillo.edu using the following command:
scp lab4x logname@opus.cabrillo.edu:
Note: logname is your opus account name.

Grading Rubric

2 points -
recursive long listing shows all relevant files.
2 points -
a correctly configured grub.conf file.