Instituto Superior de Engenharia do Porto 6) You should go through the following main options (explained in more detail below):
Mestrado em Engenharia Eletrotécnica e de Computadores
Arquitetura de Computadores • General setup
• Processor type and features
Linux Distribution: Kernel Configuration • Bus options
• Executable file formats / Emulators
The central element of a GNU/Linux distribution is the kernel of the operating system, "Linux" • Device drivers
itself. • File systems
The purpose of this tutorial is to configure, build and test a Linux kernel to be used in a Under “General setup”:
dedicated distribution for a x86 machine. Moreover, the tutorial intends to illustrate the changes
in the kernel image size as additional features are included in the kernel configuration. • Fill out the "Local version - append to kernel release" with a string
that identifies the group (e.g., student numbers).
Note: this exercise will take about 1 GB of disk space. • Check ".config kernel support". It is not an essential option, but it allows
you to recover the configuration of the kernel, in case the original configuration file is
Obtaining kernel source
lost (the data can be obtained from the kernel image, or from /proc/config.gz in a
running system).
1) If you have not done this in previous classes, create a directory named with you student
• Under “Preemption Model”, choose "Preemptible Kernel (Low-
number (mkdir student_number) and use it as a working directory
Latency Desktop)"
(cd student_number).
• Check "Initial RAM filesystem and Ram disk". This necessary if you
2) Get the kernel source code from www.kernel.org. Get the archive corresponding to the most plan to use of an initrd later.
recent stable version. • Uncheck “Embedded system”
• On the left panel, uncheck “Configure standard kernel features
3) Extract the files from the archive: (expert users)”
tar xvf ARCHIVE_PATHNAME
where ARCHIVE_PATHNAME is the name of the downloaded file, including the path to it
(e.g., ~/Downloads/linux-4.19.tar.xz).
Run the ls command. You should see a new directory (e.g., linux-4.19). Change to that
directory.
Configuration
4) Create a new configuration without any selected item:
Under “General Setup / Timer subsystem”:
make allnoconfig
• Under “Timer tick handling”, choose “Idle dynticks system”
5) Go to the setup menu (for i386 architecture):
Under “Processor type and features”:
make xconfig ARCH=i386
• The target system used in these classes is based on a Pentium MMX processor (i586).
Note: You may have to install the qt-devel, qt-config and gcc-c++ packages. Select that family of processors.
Linux Distribution: kernel configuration 1/8 Linux Distribution: kernel configuration 2/8
ARCOM – MEEC – ISEP – 2018/2019 ARCOM – MEEC – ISEP – 2018/2019
• The target systems of this kernel will have less than 1 GiB of RAM. In this situation, o Check “/proc file system support”.
the best setting for the "High memory support" option is "off". o Check “Tmpfs virtual memory file system support”
• For multimedia applications, and in general, when you want to minimize the response
time, you should a high "Timer frequency".
Under “Processor type and features / Linux guest support”: Compilation and test (static version)
• Check “Enable paravirtualization code”. This may be useful when using 7) Compile the kernel for the i386 processor architecture (the -j option lets you choose the
the kernel under QEMU. number of tasks that will be run in parallel, to take advantage of multiple processor cores):
make ARCH=i386 -j 2
Under “Bus options” (or “Device Drivers”, on more recent versions), select the
support for the PCI bus.
After this, you should find the bzImage file under arch/x86/boot/. This is the resulting
If available (depends on the kernel version), under "General architecture- kernel image.
dependent options", select "Provide system calls for 32-bit time_t".
8) Test the created kernel using the QEMU emulator. To do that, download the system image
available at the course web site, rootfs.ext4.gz, into the ~/student_number
Under “Executable file formats / Emulators”, select the support for the “ELF
directory and decompress it (gunzip ../rootfs-x86.ext4.gz). Finally, test your
format” (the most commonly used format for executable files in Linux distributions) and
kernel with the following command line:
also "Kernel support for scripts starting with #!".
qemu-system-i386 -kernel arch/x86/boot/bzImage -append "root=800" ../rootfs-x86.ext4
Under “Device Drivers”:
Backup and upload your work
• Under “Generic Driver Options”, select “Maintain a devtmpfs
filesystem to mount at /dev” as also the respective “Automount 9) Create a copy of the kernel configuration and kernel image files (adding the suffix -static
devtmpfs (…)“ sub-option. to each filename) in a new directory named build:
• Under “Block devices”, select “Loopback device support” and “RAM
mkdir -p ../build
block device support”. The last option is essential to the initrd mechanism. cp .config ../build/config-static
• Select "SCSI device support" under “SCSI device support”. Then cp arch/x86/boot/bzImage ../build/bzImage-static
choose “SCSI disk support”. This is required to enable support for USB storage
devices (in the usb_storage option, you can find the following note "NOTE: The expected directory structure is the following:
usb_storage depends on SCSI but BLK_DEV_SD may also be needed").
• Uncheck “SCSI low-level drivers”. ~/student_number/build
~/student_number/linux-XXX
• The ATA support will be required in order to use disk emulation in QEMU, as also to
support physical SATA/PATA on the final target. Check “Serial ATA and
In case you haven’t done this before, log in to your account on ave.dee.isep.ipp.pt
Parallel ATA drivers” and, under this group, “Intel ESB, ICH, PIIX3,
and create the following directory: WWW/arcom. This will create a new directory in your web
PIIX4 PATA/SATA support”.
area, which should be accessible (if your PC is connected to the DEE network) as:
• Check “USB support“, “Support for Host-side USB” and select the USB
controller driver corresponding to the one in the target PC (USB 1.1, "OHCI HCD http://ave.dee.isep.ipp.pt/~numero_aluno/arcom/
support"). Select also "USB Mass Storage support".
10) Upload the kernel image and configuration to the arcom directory in your web area on
Under “File systems”: ave.dee.isep.ipp.pt. The kernel configuration is stored in the hidden file
".config", located in the kernel source directory. Append the suffix “-static” to the
• Check the support for “The Extended 4 (ext4) filesystem”. copies of both files and remove the dot from the .config file. Assuming the current directory
• Under “Pseudo filesystems” is student_number/linux-XXX:
Linux Distribution: kernel configuration 3/8 Linux Distribution: kernel configuration 4/8
ARCOM – MEEC – ISEP – 2018/2019 ARCOM – MEEC – ISEP – 2018/2019
scp .config student_number@ave.dee.isep.ipp.pt:WWW/arcom/config-static
• Under “Intel devices”, select the “Intel® PRO/1000 Gigabit
scp arch/x86/boot/bzImage student_number@ave.dee.isep.ipp.pt:WWW/arcom/bzimage-static Ethernet” driver. This will be used for the QEMU network controller.
• Under “Realtek devices”, select the “RealTek RTL-8129/8130/8139
Loadable kernel modules (LKM) PCI Fast Ethernet Adapter support” driver. This will be used for the test
PC network controller.
The next objective is to create a new version of the kernel with some components selected as
"loadable kernel module” (LKM). A configuration option is marked to be compiled as a kernel Compilation and test (LKM version)
module by filling the respective check box with a dot, instead of a check mark.
14) Build the kernel using the new configuration. Do not forget the ARCH=i386 command
In the same directory as before, launch the kernel configuration interface and proceed to the line option.
steps described below (do not forget the ARCH=i386 command line option).
15.1) Create the directory tree of kernel modules, ready for later installation:
11) Start by enabling the support for loadable modules ("Enable loadable Module
support"). On the right side panel, check “Module unloading”. make modules_install INSTALL_MOD_PATH=../build/
12) Under “File Systems”: The above command will create the lib/modules directory, containing the modules, in
../build.
• Under “DOS/FAT/NT Filesystems”, select the “VFAT (Windows-95) fs support”
option as a loadable module (the check box should be marked with a dot). Enter the 15.2) Check if lib/modules contains the expected modules (fat.ko, vfat.ko,
value 860 as “Default codepage for FAT” and check “Enable FAT UTF-8 option by e1000.ko and 8139too.ko):
default”.
find ../build/lib/modules -name “*.ko”
16) Copy the kernel modules directory tree to the file system in rootfs-x86.ext4:
mkdir -p m
mount ../rootfs-x86.ext4 m
cp -a ../build/lib m/
umount m
17) Test the new kernel using QEMU, the changed rootfs-x86.ext4 file system image
and your USB disk from the previous classes:
su
qemu-system-i386 -kernel arch/x86/boot/bzImage -append "root=800" \
-hda ../rootfs-x86.ext4 -hdb /dev/sdb1 -net nic,model=e1000 -net user
• Under "Native language support", select the “NLS ISO 8859-1”,
“codepage 860” and “NLS UTF-8” as static options (i.e., with the check mark).
Set the “Default NLS Option” to “utf8”. • After logging in, in the emulated machine, the LKMs must be loaded manually, using
the insmod or modprobe commands. Recall that the modules should be found in
13) Check “Networking support”. Under “Networking options”, select the subdirectories of /lib/modules/.
“Packet socket”, “Unix domain sockets” and “TCP/IP networking” as static o Find the location of vfat.ko and try to load it with insmod. What is the
options. result?
o Now, try to load the same module using modprobe vfat. Check the loaded
Under “Device Drivers” and “Network device support”, select “Ethernet modules with lsmod. What do you conclude?
driver support”. Next, you should select, as loadable kernel modules, the device drivers o Load the remaining modules.
for the following two ethernet controllers (uncheck all other drivers):
Linux Distribution: kernel configuration 5/8 Linux Distribution: kernel configuration 6/8
ARCOM – MEEC – ISEP – 2018/2019 ARCOM – MEEC – ISEP – 2018/2019
• Mount the first partition of your USB disk on /mnt. Notice that this partition is Document history
identified as the second disk of the emulated machine (because it is passed as -hdb): • 2018-10-08 – updated for Linux 4.19 by Jorge Estrela da Silva (jes@isep.ipp.pt)
o mount /dev/sdb /mnt • Document created by Jorge Estrela da Silva (jes@isep.ipp.pt) in 2010 (initial version
o ls /mnt in portuguese). The document went through several changes (not on record) through
• Restart the network configuration1 and test the network access using the wget the years.
command (note that the ping utility does not work on QEMU):
o udhcpc
o wget http://ave.dee.isep.ipp.pt/~jes/arcom
• Shutdown the emulated machine with poweroff.
18) Create a copy of the bzImage and .config in “../build”, adding the suffix "-lkm"
to the name of the original files. Check the increment in the kernel image size.
cp arch/x86/boot/bzImage ../build/bzImage-lkm
cp .config ../build/config-lkm
du -k ../build
Support for graphics modes through frame buffer
Still following the previous configuration, under “Device drivers”, “Graphics
support”, select “Support for frame buffer devices” (as a static option). Under
“Frame buffer devices”, select “VESA VGA graphics support”. Additionally,
select the “Framebuffer Console support” and “Bootup logo” options. All
options should be selected as static (check mark).
Compile the kernel and test it on QEMU:
qemu-system-i386 -kernel arch/x86/boot/bzImage \
-append "root=800 vga=0x311" -hda ../rootfs-x86.ext4
The boot screen should present a picture of Tux, the mascot of the Linux kernel.
Create a copy of the bzImage and .config in “../build”, adding the suffix "-fb" to
the name of the original files.
Upload your final work
The following commands assume the current directory is ~/student_number/build:
tar cvf modules.tar lib
scp config-fb student_number@ave.dee.isep.ipp.pt:WWW/arcom/
scp bzImage-fb student_number@ave.dee.isep.ipp.pt:WWW/arcom/
scp modules.tar student_number@ave.dee.isep.ipp.pt:WWW/arcom/
1
udhcpc is a DHCP client, part of the BusyBox package.
Linux Distribution: kernel configuration 7/8 Linux Distribution: kernel configuration 8/8
ARCOM – MEEC – ISEP – 2018/2019 ARCOM – MEEC – ISEP – 2018/2019