Lab 3: Creating a Root File System
Last modified: Sep 19, 2011
The purpose of this lab is to create a minimal, yet functional, root file system on a small partition.
This involves four steps:
- Partitioning the drive (fdisk)
- Creating a Linux ext file system (mkfs)
- Creating a rudimentary directory hierarchy (mkdir)
- Populating the directories with required files (mknod, cp)
You will be working with the virtual machine, CentOS
Step One
You must create a space for the root filesystem that will be separate from the existing operating system.
- Log on to the CentOS system as root on a terminal screen.
- Run the command:
fdisk -l
to find out what storage devices are available on the system.
- Run the fdisk command using the scsi device file as the argument:
fdisk /dev/sda
- Create a single primary partition, /dev/sda3, that goes from cylinder 79 to cylinder 86.
Be sure to save the new partition structure by exiting with "w".
- When you get the shell prompt back, run the following command to force the kernel to
re-read the partition table:
partprobe
Step Two
Create an ext2 file system on the device.
- use the following command to create an ext2 file system:
mkfs -t ext2 /dev/sda3
- Record the following information about your file system:
- Block Size -
- Number of inodes -
- Number of blocks -
- Number of blocks reserved for super user
- Remake the file system using the following additional options:
mkfs -t ext2 -m 0 -N 500 -L /linux /dev/sda3
- What does the -m 0 option do? The -N 500?
The -L /linux?
Step Three
Mount the file system and create the directory structure of the root
file system on it.
- Mount your new file system to the /mnt directory:
mount /dev/sda3 /mnt
- Use the ls command to list the contents of your
file system.
ls -l /mnt
- Is anything there?
You might want to change your current working directory to /mnt.
- Add the following directories on your new file system:
bin, dev, etc, lib, proc, sbin, sys, tmp
Change the permissions of the tmp directory to 1777.
Do you know why we do this?
Step Four
Populate the directories with the required files
- In order to create a device file for the console, let's look at
a long listing of the console device file from your system's dev
directory:
ls -l /dev/console
- Now, change directories to your dev directory:
cd /mnt/dev
and use the mknod command to create the console device file.
The syntax is: mknod <name> c|b major# minor#
For example: mknod console c 5 1
Be sure to set the correct permissions, ownership and group the file you just created.
chmod 600 console
- Copy the bash shell to your bin directory.
- Make a symbolic link from the bash file to the file, /sbin/init.
cd /mnt/sbin; ln -s ../bin/bash init
(When the kernel does load into memory and initializes all its device drivers, it will try to turn control over to a program called init. We don't have this program on our root file system, so to trick the kernel into running our bash program instead, we are creating this symbolic link.
This step is necessary only as a temproary measure to get around the fact that we are side-stepping the role of the init command.)
- Use the ldd command to see what libraries bash requires.
- Copy these libraries to your lib directory. For example:
cp /lib/libtermcap.so.2 /mnt/lib/
Note: If a library is named with all numbers, you may ignore that pseudo library.
Congratulations, you have just made a rudimentary root file system with
one program on it. How many files make up your file system?
To turn in
Take a "picture" of your work and save it to a file.
- ls -lR /mnt > /root/myfs
- Unmount the file system:
umount /dev/sda3
- Change your current working directory back to /root
Turn in the "picture" you took of your file system to your account on the machine, opus.cabrillo.edu using the following command:
scp myfs logname@opus.cabrillo.edu:lab3
Note: logname is your personal account name.
If your file is successfully transfered to Opus, you may delete your myfs file.
Grading Rubric
- 3 points for:
- submitting a file called, lab3 to opus which contains a recursive
long listing of your file system.
- 3 points for:
- having all 8 directories with their correct permissions
- 2 points for:
- having the console device file with correct permissions, type and major/minor numbers
- 2 points for:
- having the correct executable and library files in /bin, and /lib.