This article is a great resource on preparing a dev machine for kernel work.

However, after developing on this machine for awhile, I needed better automation for writing code locally and syncing it / running it on the Virtualbox machine.

It is possible to have shared folders with Virtualbox, but they require VirtualBox Guest Additions, which I did not want to install in my dev environment.

Instead, while working on a kernel module I have a Makefile in my project root. One of the make targets syncs my files to the dev machine.

Since I use vim for development, I simply type :make sync in vim, and my module is scpd to the dev machine, the module is built, and loaded.

Here is what my Makefile looks like for a module I’m working on called chardevice


MODNAME = chardevice
PRJDIR = "/root/modules/$(MODNAME)"

	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
	insmod $(MODNAME).ko
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
	rmmod $(MODNAME) || true
sync: $(MODNAME).c
	scp -P 3022 $(MODNAME).c root@$(PRJDIR)/$(MODNAME).c
	scp -P 3022 Makefile root@$(PRJDIR)/Makefile
	ssh -p 3022 root@ "cd $(PRJDIR) && make clean"
	ssh -p 3022 root@ "cd $(PRJDIR) && make all"

You can see when I run :make sync from within vim, the program file is scpd to the Virtualbox machine and then make clean and make all are run within the project directory inside the dev machine.

Running make from vim

And the output:

Make output from vim

After you run the make command, you can run copen if you need to see the output again.

Before commiting the code to a shared project, it is a good idea to separate your personal automation into a different Makefile that is not committed. If you do this, you can invoke your own make targets using make -f MyMakefile.