How to send patches with git-send-email


The prerequisites for this tutorial is that you have already made some changes to your local kernel tree and that these changes have been committed.
In this tutorial, are described the steps to follow in order to create and send a patch series using git-send-email.

Initially, you need to determine which of your commits want to be sent, so do:

$ git log --pretty=oneline --abbrev-commit

The output, in my case, looks like:

db868ad xhci: remove conversion from generic to pci device in xhci_mem.c
c010f0c xhci: remove unnecessary check in xhci_free_stream_info()
a166493 xhci: fix SCT_FOR_CTX(p) macro
56e4cd3 xhci: replace USB_MAXINTERFACES with config->desc.bNumInterface

Lets assume that I want to send the last 3 commits i.e db868ad, c010f0c and a166493. The first thing I need to do is to create patches for these commits and store them in a local directory e.g. ~/patches/

Patches that can be sent using git-send-email should have…

View original post 998 more words


Add hardisk to Oracle VirtualBox

I keep forgetting these steps so I decided to document them. Steps to add a extra hard disk space in Oracel virtual box. This is for Ubuntu

1. Add a hardisk using the option from virtual machine settings as shown


2. Start the virtual machine. Once the machine is up run the command to get the mname of the driver

sudo fdisk -l

In my case it is /dev/sdc

3. Partition the disk using the command

sudo fdisk /dev/sdc

Then use the command “n” to add a partition and “p” for primary partition. Use the default values (if you have no idea of what they are) and finally use “w” to write the partition table to the disk.

"The partition table has been altered!" 

message indicates partition is successful

4. Format the disk into the filesystem of your choice. I am using ext4 so the coomand is

sudo mkfs -t ext4 /dev/sdc1

5. Creating a mount point. I mount the disk at the location /media/etc_drive_2/ so I create a drive using the command

sudo mkdir /media/etc_drive_2/

6. For auto mount at every startup edit fstab

gksu gedit /etc/fstab

And add the following line

/dev/sdc1    /media/etc_drive_2  ext4    defaults     0        2

The name of the driver and folder name changes based on your system

7. Access permission. I have set the access permission for my login. To do so first mount the drive using the command

sudo mount /dev/sdc1 /media/etc_drive_2

And set access permission using

sudo chown -R USERNAME:USERNAME /media/etc_drive_2

replace USERNAME with correct username

For detailed reading and much more fun visit

An easy kernel development environment

This article which sounds like anti-oracle virtual box, but it wasn’t and highlighted the use of virtual box made me write this blog.

I have been a big fan of Oracle virtual box and indeed it’s the best Type2 hypervisor (based on features for x86) I have used. I would say qemu as the lightest and the fastest. When I started poking around on Linux kernel running over virtual box, my modules crashed and caused file-system corruptions. This led me to use a desktop machine as a Linux test machine. But I could not carry my test machine with me. And so, I have changed my environment to two virtual machines (test and development) using virtual box.

I will describe here how to Setup two virtual machines for Linux development environment

Please refer these links which describe how to :

  1. Build and test a module using the environment refer here.
  2. Change the kernel of test machine refer here
  3. Removing the kernel of test machine refer here

Overview of the setup:

  • Host OS is windows
  • Virtual box from Oracle
  • Ubuntu as the test and development Linux distribution


1. Downloads and software packages:

  • Download Oracle Virtual Box  and don’t forget the corresponding extension pack.
  • Download the Ubuntu ISO. I use Ubuntu 12.10. You can use Ubuntu 12.04 as it is LTS.

2. Virtual machines: Create two virtual machines,

  • Development machine with at least 20GB hard disk
  • Test machine with 4.5GB hard disk.

Refer the virtual box user guide if any doubts.

3. New network interface: Create a new host only adapter in the virtual box from Oracle VM Virtual Box Manager > File > Preferences > Network.


Create new adapter with the credentials as shown.


So the network adapter appears as shown


4. Tuning the test machine: Boot the test machine and strip it to bare minimum by removing the unnecessary software like games, Firefox etc. Even strip its GUI and make it text only using the grub as described here.

5. Setting up the network: With both the virtual machines stopped configure the network interface as shown.



Leave the first network adapter unaltered in the development machine. This interface will be used for downloading additional softwares.
Now start both the machines and get the IP of both machines using “ifconfig”. In my case development machine IP is 192.10.100 and test machine IP is 192.10.101. Ping both the machines from each other and verify the network connection.

6. First login: To login to the test machine using SSH install openSSH-client in your development machine using the command at a terminal

sudo apt-get install openssh-client

Now type the command at a terminal

ssh test@

I have used test as it is my user name on test machine. You will get a warning for the RSA when you login the first time

The authenticity of host '' can't be established.
RSA key fingerprint is b1:2d:33:67:ce:35:4d:5f:f3:a8:cd:c0:c4:48:86:12.
Are you sure you want to continue connecting (yes/no)?

Type yes

7. Test: You can test the setup by shutting down the test machine using the command after logging on to the machine on ssh

$ sudo poweroff

The Linux development environment is configured.

Please feel free to send me queries or improvements for this writeup. If you find this useful or useless please post your reply

A basic Linux kernel module tested on remote machine

I will demonstrate the process in building a basic Linux kernel module and test it on a remote machine by logging in using ssh.

1. Create a file hello.c and copy the below code

#undef __KERNEL__
#define __KERNEL__

#undef MODULE
#define MODULE

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int __init hello_init(void)
    printk(KERN_INFO "Hello world!\n");
    return 0;

static void __exit hello_cleanup(void)
    printk(KERN_INFO "Cleaning up module.\n");


2. Create a file Makefile and copy the below code. Also don’t forget to update the KDIR with the kernel path if you are using a kernel different from the development machine. In my case since development and test machine are running the same kernel, I use the path as shown

obj-m := hello.o
#KDIR := /* update with path of kernel code here */
KDIR:=  /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

	$(MAKE) -C $(KDIR) M=$(PWD) modules

	$(MAKE) -C $(KDIR) M=$(PWD) clean

3. Build the module using the command

$ make

4. Transfer the module using SCP to other machine using the command

$ scp hello.ko test@

Do not forget the “:”. Where test is the user-name and is its ip

5. You can login to the machine using

$ ssh test@

where test is the user-name and is its ip
and insert the module using the command

$ sudo insmod hello.ko

6. Verify the prints using the command

$ dmesg


$ lsmod

Updating kernel of remote Ubuntu or Debian machine

I chose my devlopment environment Debian based as I am familiar with the kernel roll out infrastructure. I will update the kernel of a test machine which runs Ubuntu. I will compile the kernel on another deleopment machine.

This may not work for non-debian based Linux environment like redhat.

Step 1. Kernel sources: I have cloned a git for HID next and will be using it as an example. You can download any Linux kernel from website. Unzip the kernel sources and change directory to the top most directory of kernel source.
So pwd and ls gives me the following result

prajosh@test-box:~/Project/hid_next/hid$ pwd
prajosh@test-box:~/Project/hid_next/hid$ ls
arch     Documentation  init     lib             net             security
block    drivers        ipc      MAINTAINERS     README          sound
COPYING  firmware       Kbuild   Makefile        REPORTING-BUGS  tools
CREDITS  fs             Kconfig  mm              samples         usr
crypto   include        kernel   Module.symvers  scripts         virt

Step 2. I will use the default i386 kernel configuration so run the command

$ make i386_defconfig

You can customise using the command make menuconfig

Step 3. To produce a .deb which can be used to install kernel in another machine run the following command. This is part of the Debian kernel make infrastructure for details refer the references section below

$ fakeroot make-kpkg kernel_image --initrd binary

This will take some time. Once the make is complete, please check the directory above Linux source directory and you will be able to see some .deb files.

prajosh@test-box:~/Project/hid_next/hid$ cd ..
prajosh@test-box:~/Project/hid_next$ ls

Step 4. Copy the linux image to the test machine

$ scp linux-image-3.11.0-rc4+_3.11.0-rc4+-10.00.Custom_i386.deb test@

where test and are user-name and IP of the test machine respectively

Step 5. Login to the test machine using SSH by using the command

$ ssh test@

and do the following commands to install the kernel

$ sudo dpkg –i linux-image-3.11.0-rc4+_3.11.0-rc4+-10.00.Custom_i386.deb

Once complete you can reboot your machine and you can see the new kernel version using the command

$ uname –a


Removing Linux kernel from Ubuntu

I have installed a couple of custom compiled kernels on Ubuntu and want to remove them. I will breifly describe how to remove the kernels
1. Open up a terminal (Ctrl+Alt+T). Type:

$ uname -r

This will show you the kernel you’re using currently, so you don’t want to remove this.

2. Run the following command:

$ dpkg --list | grep linux-image

This will show the all the kernels that are installed. Be careful write down the names of all the kernels which you want to remove.

In my case it shows up as:

3. To remove the kernels use the command:

$ sudo apt-get purge linux-image-x.x.x.x-xyz

In my case to remove the kernel linux-image-3.5.0-17-generic (as shown in the picture above) I will use the command

$ sudo apt-get purge linux-image-3.5.0-17-generic

4. The update has to be reflected at Grub so run the command:

$ sudo update-grub2