Remember that the kernel and the rest of the operating system are two different things! The kernel is one option of a thing you will need to build and/or modify in this class; the other is what is known as the common utilities
. Here are some notes from my past build experiences that will help you along the way. REMEMBER that a very large part of this process is researching information, especially when things don't work right. You will find that operations RARELY go right with this process the first time through, so BE PREPARED TO LOOK THINGS UP!
- Download a copy of the free VM from Oracle called
Virtual Box
and install it. Versions are available for both Windows [I used version 6.0.4-128413-Win.exe] and Mac [I used 6.0.0-127566-OSX.dmg], so you should be able to do this without regard to which platform you use. There may be later versions available, and they should work. I have found that when I started up the installed versions, I got a notification [on mac] that there is a later version available. If that is the case for you, go ahead and install the later version – it won't corrupt anything you've done previously. Virtual Box is available for free from: this site - Download a copy of Ubuntu Linux from the Ubuntu website. I used version 18.10, which is the SECOND green button on the page. The "LTS" button is for "Long Term Support" and the 18.10 version still has 9 months of support if you want it. Ubuntu is available for free from: here
- When you've downloaded it [it's an
iso
file] you need to make a newmachine
on your Virtual Box VM. Start up the VM, then click thenew
icon to make a new machine. Call it whatever you like [I usedubuntuv1
so I can make more with successive numbers in case of a mistake]. Make sure you select the Linux install [which appears automatically if you name your VM instance with the word ubuntu in it] and click next. Reportedly you should use at least 4GB of RAM for this instance, so set the slider accordingly, and click next. You will also need to give yourself a 40GB hard drive to be able to successfully compile. I tried it with 10, 20, and 30 GB drives and it failed on all of them. You can take the defaults for the rest of the selections. - Start the VM you just built, and us it to install Ubuntu. There are a number of screens that will be required on this first start up and install, but once you have it up and running, it will start Linux automatically every time you start this particular VM instance. DON'T WORRY about the prompt that says something about
erasing your hard disk
… this is just erasing the VIRTUAL MACHINE'S HARD DISK, not the real one on your computer. Also, REMEMBER YOUR PASSWORD as this will be used to log in and to dosudo
tasks later. - Start Ubuntu, if it isn't already started, and wait for it to load completely and display the desktop. Click on the little arrow in the upper right corner of the Ubuntu screen, then click the tool icon. Click the PRIVACY tab and turn screen lock off. Then click the POWER tab and make sure power saving is set to NEVER blank the screen.
- Check if GCC is loaded: open a terminal window in Ubuntu and run the command
gcc to check. If it's not there, you can get it by doing
sudo apt install gcc
to get it. When it is finished, typegcc
again to make sure it's working. NOTE THAT THIS IS A DIFFERENT INSTANCE than the one you installed on your HOST machine to do homework and exercises! - Check out askubuntu.com for help – this site can be your best friend
- Check out the build your own kernel page for some help and advice on the overall process of downloading the source and building the project; make sure you build it BEFORE you modify it, to prove the build process works, THEN do your modification
- Note that building a NEW kernel takes several hours to compile; however, building the EXISTING kernel only takes a few minutes, since you didn't change any code [yet].
- The
sudo
command will give you a temporary access as if you were the root user; you will need the account password you set up when you installed Ubuntu on your VM - The
fakeroot
command is also very helpful, and sometimes you need to use them together to get things to work. I've had success withsudo fakeroot
when the command didn't work for either of them independently - Run
sudo software-properties-gtk
to get a dialog box that has a check box which will enable downloading the source code - Run
sudo apt-get update
to update theapt-get
utility - Run
sudo apt-get install dpkg-dev
to install thedpkg-dev
package if it is missing - Run
sudo apt-get dist-upgrade
to upgrade the distribution manager utility; this will NOT update the UBUNTU O/S, it will ONLY do the distribution manager - Check out Dr. Forney's homework 3 page for more helpful information, including some fun XKCD comics; there are also some helpful links and advice
- Remember that the
frustration
is part of thefun
…
-
Here is a list of things to do and to know that helped my get my build completed:
-
LTS = "Long Term Service" ~ you don't really need, but is slightly more stable than non-LTS version
-
The kernel is a file that is in directory "/boot". The file is called
vmlinuz<version>"
-
Find the linux kernel archives at "www.kernel.org" and download the tarball for the version of interest. I used 4.19.34 which is from April 5th 2019
-
The "xz" extension is yet another type of "zip" archive compression. The Linux "tar" program knows how to unzip it with the correct command line switch option "J" <note: uppercase!>
-
Start firefox and navigate to www.kernel.org
-
Get kernel 4.19.34 tar ball – goes into Downloads folder when using FireFox
-
Use the
mv
command to move the zipped file to your home directory -
Untar with
tar xJvf linux-4.19.34.tar.xz
: the gibberishxJvf
means:- x to extract
- J because it's a zipped file with XZ format
- v for verbose so you can see the listings
- f for the file name which follows
-
Change into the resulting top level directory linux-4.19.34
-
Do
sudo apt install gcc
to make sure that gcc is installed and updated -
Do
sudo apt install make
to make sure that the make utility is installed and updated -
During these operations you may get an error as follows: E: Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? -
Do
ps -eaf | grep -i apt
:: this shows running apt processes ~~ there is a daily check for updates that locks apt ~~ you can kill the processes usingkill -9 <process id>, or you can just wait for them to finish, they don't take TOO long...
-
You can use the
ps -eaf | grep -i apt
command to get the processes using the lock -
You can use the
kill -9 <process ID>
command to kill them off -
Do
sudo apt-get install dpkg-dev
to install the dpkg manager for the development environment -
Do
sudo apt-get dist-upgrade
to update theapt-get
distribution -
Do
make menuconfig
to see options ~ make sure you SAVE so there is a config file for the build -
Execute the command
make && make modules_install && make install
to run the build
The&&
means concatenate the commands, but only continues if the previous one is successful
You might have trouble with some of the required libraries being missing
I had to get the ssl lib withsudo apt-get install libssl-dev
the-dev
makes sure to put the headers where they belong
I had to get the ncurses lib withsudo apt install ncurses-dev
I had to install bison withsudo apt-get install bison
I had to install flex withsudo apt-get install flex
-
Then I had to do the make line again:
make && make modules_install && make install
-
I did this on a VM that had 4096 RAM and 30 GB hard disk and ran out of space; I tried again with 8192 RAM and 40 GB hard disk
-
I started the build at 08:43; build failed at about 12:45 because I couldn't make a directory.
-
I switched to root account and tried again. Just did
and that seemed to workmake
-
I then did
and make skipped the compilation and went directly to "INSTALL"make module_install && make install
-
Finished the build, then restarted Ubuntu
-
FINALLY SUCCESS!! I did a "uname -a" and saw the kernel version is my new 4.19 and the created date is today.
In the directory where you put your source code; e.g., /home/beej/linux-4.19.34
- NOTE: you will need to write the code for your addition first because you need the "entry point"
- change to the directory arch/x86/entry/syscals
- find the file "syscall_64.tbl" [or "syscall_32.tbl" if you are on a 32-bit machine]
- you can list it out with
more
- there are [on my build] 547 entries in there
- edit the file using vi or vim
- add your new command to the end with a new number
The list of calls in the table will show you what you can modify if you are changing something
- Come up with an idea for a modification or addition to the Linux kernel, and get it approved with the instructor. This might be an addition to an existing command, a new command, or an entirely new application that runs on Linux.
- Design the modification; don't do this in the dark. You might start by implementing some version of your idea in a
stand-alone
way so that you can more easily build and de-bug it. Doing this on a prototype can be much faster than having to wait three hours for compilation each time you re-build the Linux kernel - Here is a list of the Spring 2019 project teams with an idea of what needs to be modified or implemented to accomplish the project tasks
- Chu, Edmiston, Keba: drive automounting ~ module[s]: mount
- Crowther, Rajavasireddy, Simmons: user account creation ~ module[s]: useradd
- Moini, Lizarda, Zafiris: "hog" system utility that lists CPU hogs ~ new module: hog
- Santander, Namba, C. Nguyen: "mbob it" file name case randomizer utility ~ module[s]: "mv" and "ls" utilities
- K. Nguyen, Ruiz, Tolliver: "processInfo" module interfaces to kernel log ~ new module: processInfo
- Higgins, Fletcher, KPatterson: fun inefficient task scheduler ~ module[s]: sched.c
- Lopez, Byrne, Boyac: new scheduling algorithm for the I/O scheduler ~ module[s]: sched.c
- Prochnow, Flora, Jay: new output to "w" module ~ module[s]: [[unsure which is required]]
- Ochsner, Peters, West: cursor movement without mouse ~ module[s]: mousedev, keydev
- Braekman, Kern, Martin: combination utility, mimics "find" and "grep" in one ~ new module: search
- Arteaga, Wroblewski, Persily: "top" utility modification for priorities ~ module[s]: top [[might get from http://procps.sourceforge.net/index.html]](http://procps.sourceforge.net/index.html)
- Patterson, Richardson: timedatectl modification ~ modules: set-time
sudothe apt-get command. * note that not all of these are technically
kernelmodifications or addiitons. However, in my view, if you are creating or modifying a utility level program, you will still be making use of the kernel system calls, and you will have had to build your own version of the kernel as part of the class, so it still counts for credit!