This is an overview of my setup:
- Linux Host With Qemu Target
- Tracing and Debugging using qemu’s built-in gdb server.
- pkgin for simpicity.(Sometimes have to use pkg_add to get stuff done)
Make sure you have the latest version of qemu installed as we will be using x86-64 NetBSD guests.
We will be needing GDB that is configured with NetBSD x86_64 abi. So we need to compile it ourself.
First step get the files.
mkdir netbsd && cd netbsd
Now for the time taking part, compiling the sources.
./build.sh -m amd64 -T ../tooldir -D ../destdir -R ../releasedir -O ../objdir -U -j6 release iso-image
Upon completion the directories will have the following files:
- Cross-compilation toolchain in “tooldir”
- Bootable image in “releasedir/images”
We will be using
virt-manager a front-end to qemu for configuring the vm, makes things easier without the hassle of setting up network bridges and all.
sudo apt install virt-manager
Once installed open
Virtual Machine Manager
This should drop you a vm instance with the network capabilities too. Now go through the standard netbsd installation procedure installing all the necessary installation sets(depends on what you want to work with) and reboot.
here you can configure the ssh port and other settings and make sure you have
if you want to login as root. After making all the necessary changes,
service sshd restart
This restarts sshd and now you can ssh into your vm.
Once you are up and running better to install pkgin. It makes package management easier but sometimes it messes up in netbsd-current so if you have any problems with installing via pkgin, use pkg_add.
Now we can install all (well..most of em) the necessary utilities that makes life easier.
NetBSD runs the default GENERIC configuration. So we make a few changes to this and compile our own kernel.
Use the text editor of your choice and fiddle with the configuration.
make sure you have
makeoptions DEBUG="-g" # compile full symbol table for CTF
Now all that is left is compiling.
./build.sh -m amd64 -T ../tooldir -D ../destdir -R ../releasedir -O ../objdir -U -u -j6 kernel=QEMU
Now scp the files to vm and repace the old kernel
scp ~/netbsd/objdir/sys/arch/amd64/compile/QEMU/netbsd [email protected]<ip addr>:~
Start VM with qemu’s gdb stub forwarding tcp through port 1234.
qemu-system-x86_64 -drive file=vhd/netbsd-current.img,format=raw \
We already compiled netbsd kernel with complete symbol table.
Now just simply enter
(gdb) target remote localhost:1234