Marcelo Schmitt

MAC0472 - Agile Methods Lab - Week 3

In the third week of Linux Kernel development in the MAC0472 - LabXP discipline, the objective was to compile and install a version of ArchLinux in a virtual machine (VM). We (Giuliano Belinassi and I) also started developing some improvements to KWorkflow (kw), a tool that we will be using soon.

Warning: This is an old post with potentially outdated information. Read with caution.

As my development distro is Ubuntu 18.04.1 LTS the steps I will describe are for use in that environment.

  1. Having installed the KWorkflow tool, I tried to configure the ssh access to a VM that had Linux Arch installed so that the KWorkflow kw prepare command would configure the rest of the environment. Note: The improvement we are working on will save the manual configuration of ssh access to the VM and this step will no longer be necessary in the future.
# @host
kw up
ssh-copy-id -i ~/.ssh/arch_ssh.pub -p 2222 marcelo@localhost
# say yes
# type the VM user password
# @vm
# As root, copy the ssh public key to ~/.ssh/authorized_keys
# (create the directory if it doesn't exists)
sudo su
mkdir .ssh
cd ~/.ssh
touch authorized_keys
nano authorized_keys
# Copy the content from you public key (for instance, ~/.ssh/<ssh_key>.pub in
# the host machine) to the file ~/.ssh/authorized_keys inside the VM
# @host
kw prepare
  1. Install the dependency packages needed to compile the Linux kernel on Ubuntu.
    sudo apt-get install libguestfs-tools python-guestfs samba libelf-dev
    
  2. Generate the configuration file for the kernel build. Assuming you have cloned the kernel into ~/linux, run the following commands:
    # @vm
    cd ~/shared/linux/
    make clean
    zcat /proc/config.gz > .config
    
    # @host
    cd ~/linux
    make nconfig
    make olddefconfig
    
    # @vm
    make kvmconfig
    make localmodconfig
    
  3. Build the Linux kernel.
    # @host
    cd ~/linux
    make ARCH=x86_64 -j8
    

Compiling the kernel should take some time which can be from 15 minutes to 2 or 3 hours. In the end, if everything goes well, the last lines in the shell output should indicate that a new kernel image has been generated. Something similar to:

Setup is 16188 bytes (padded to 16384 bytes).
System is 5449 kB
CRC dc413c09
Kernel: arch/x86/boot/bzImage is ready  (#1)
  1. Install kernel modules.
    # @vm
    sudo make modules_install
    
  2. Copy the newly generated kernel image to the /boot/ directory so you can boot the VM with it. In place of <name> put a name that helps you distinguish your kernel build from others.
    # @vm
    sudo cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-<nome>
    
  3. Create a new mkinitcpio. We do this by copying the existing mkinitcpio and editing it manually. 7.1 Create a copy of mkinitcpio.
     # @vm
     sudo cp /etc/mkinitcpio.d/linux.preset /etc/mkinitcpio.d/<nome>.preset
    

    7.2. Edit the mkinitcpio file.

     # @vm
     sudo vim /etc/mkinitcpio.d/<nome>.preset
    

    In my installation, I used LABXP instead of <name> and my file /etc/mkinitcpio.d/LABXP.preset had the following lines:

     # mkinitcpio preset file for the 'linux' package
    
     ALL_config="/etc/mkinitcpio.conf"
     ALL_kver="/boot/vmlinuz-LABXP"
    
     PRESETS=('default' 'fallback')
    
     #default_config="/etc/mkinitcpio.conf"
     default_image="/boot/initramfs-LABXP.img"
     #default_options=""
    
     #fallback_config="/etc/mkinitcpio.conf"
     fallback_image="/boot/initramfs-LABXP-fallback.img"
     fallback_options="-S autodetect"
    

    7.3 Generate a new initramfs.

     # @vm
     sudo mkinitcpio -p <nome>
    
  4. Update grub.
    # @vm
    sudo grub-mkconfig -o /boot/grub/grub.cfg
    sudo reboot
    

    8.1 If necessary, update the access permissions for the new image.

     # @host
     # See http://libguestfs.org/guestfs-faq.1.html
     sudo chmod 0644 /boot/vmlinuz*
    
  5. When done, run kw up, select *Advanced options for Arch Linux from the grub menu, and then *Arch Linux, with Linux <name>.