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
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
obj-m+=chardevice.o MODNAME = chardevice PRJDIR = "/root/modules/$(MODNAME)" all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules insmod $(MODNAME).ko clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean rmmod $(MODNAME) || true sync: $(MODNAME).c scp -P 3022 $(MODNAME).c firstname.lastname@example.org:$(PRJDIR)/$(MODNAME).c scp -P 3022 Makefile email@example.com:$(PRJDIR)/Makefile ssh -p 3022 firstname.lastname@example.org "cd $(PRJDIR) && make clean" ssh -p 3022 email@example.com "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.
And the output:
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.