Sunday, May 03, 2020

kernel in qemu

Wanted to start with kernel development and experiment with it. But i did not want to have to have to install  the kernel in my main machine. In this case the virtualization is the answer. I write the steps i did and the link(s) i used in order to get started.

To put everything together this is what i needed to do:
  1. install necessary packages
  2. download the kernel and build it
  3. create a root filesystem for qemu using buildroot
  4. run the kernel with the root filesystem with qemu

https://medium.com/@clem.boin/creating-a-minimal-kernel-development-setup-using-qemu-and-archlinux-987896954d84 has every detail to get started. There is no need to create a disk on anything and the debugging is a bonus. Although i dont know if the configure as it describes actually works, as i follow slightly different approach here.

Basic, i download the latest kernel (5.6.10) from https://www.kernel.org/ in a directory and then i did the normal make menuconfig, make and sudo make modules_install. If i wanted to install the kernel in my system and boot into it i will have to run also sudo make install and then configure the bootloader with sudo grub2-mkconfig -o /boot/grub2/grub.cfg.

Before go on, i want to share the parameters i used to build the kernel. I was actually trying to follow the http://linuxdocs.org/HOWTOs/Kernel-HOWTO.html#toc4 so the first thing i did was to disable the CONFIG_MODVERSIONS. That was for some convenience as i was just experiment. to find this when the menuconfig opens type / and copy paste the name that you are looking for. This will provide the path of where the config is located and exit. I had to repeat this for another error as the first attempt to build failed.

At the end build was ready and the modules were installed. now i had to build the filesystem. I cloned the buildroot, cd into it and i run make. This also takes some time and apparently you need Internet as it seems to download stuff (if you have perl installed and PERL_MM_OPT is set you will have to unset it).

finally i run the kernel in the qemu:

qemu-system-x86_64 -no-kvm -kernel arch/x86_64/boot/bzImage -boot c -m 2049M -hda ../buildroot/output/images/rootfs.ext2 -append "root=/dev/sda rw console=ttyS0,115200 acpi=off" -serial stdio -display none






























Sunday, April 26, 2020

configuring i3 with py3status

i used to run the vpn connection from the terminal. I could not find a way to make the i3 status show the correct status when the VPN was running. i use the py3status and taking a look in the documentation i though that it would be as simple as to edit the i3 configuration to point to a pid file that i would store the pid process when i run the openvpn. Something like

vpn_status {
  check_pid = True                 
  pidfile = "/var/run/openvpn-client/myvpn.pid"
}
and adding in the vpn config

writepid /var/run/openvpn-client/myvpn.pid

After some research and taking a look in the vpn_status module of the py3status, i decided to try my luck using the NetworkManager. This work quite well as the module checks for dbus messages of the NetworkManager. the modue does not need any additional in the py3status config.

To add the vpn connection from nmcli, the commands are:

sudo nmcli connection import type openvpn file /etc/openvpn/myvpn.ovpn 

Add the username to the vpn connection that it needs to connect

nmcli connection modify myvpn +vpn.data username=<username>

And finally run the onnection up using --ask to prompt for the password of that specific user

sudo nmcli --ask connection up myvpn
Now the i3 status shows the VPN is up and running displaying the name of the vpn. Giving the correct password you should see that the connection is activation (Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

With ip route you can check that vpn has setup the routing. in my case i have a problem as it adds a default route to the vpn address which could not see outside. i had to delete this because i could not access the Internet

sudo ip r delete default via 10.100.200.1

if you want to close the connection

nmcli connection down myvpn

i dont know how i could do that without NetworkManager but i would be happy if someone has some hints.

Sunday, March 15, 2020

Switch connection between two interfaces using nmcli

A way to switch network interface from console is using nmcli. Going through the man page you can see a small set of examples. For example to create a new connection you can run

$ nmcli dev wifi con "Cafe Hotspot 1" password caffeine name "My cafe"

Some Basic Background

What you need is:
- A valid network device
Make sure that the device has recognized and the drivers have been loaded. After that you should be able to find the interface with nmcli

$ nmcli device 
or
$ nmcli device status

should give you an output like this(if you have no active connection yet)

DEVICE             TYPE      STATE           CONNECTION         
wlp2s0                wifi          disconnected  --

- A connection configuration that can be found under /etc/sysconfig/network-scripts/ (at least in fedora). The configuration file is created by nm when ever for example you run the command that we saw above first to create a new connection.

to check the connection from nmcli

$ nmcli connection show "My Cafe"
Here is good to check some things
- The connection.autoconnect. Make sure that it has "yes" value
- The connection.interface-name. This might have the name of the interface.

Use nmcli to change the interface of the connection

In case you have two interfaces and you want to switch between each other you should be able to do so with

$ nmcli connection up "My Cafe" ifname wlp2s0

This is not always easy as that but it is usually easy to fix. To make this work you might change a few things in the connection configuration. For instance if i have the following error, personally

Error: Connection activation failed: No suitable device found for this connection (device enp1s0 not available because profile is not compatible with device (mismatching interface name)). 
or
Error: device 'wlp0s29u1u3' not compatible with connection '1925_www.radlice.net': The MACs of the device and the connection didn't match..

For the first i solve the problem as i have already say above, removing the you connection.interface-name. For the other one, i checked the the 802-11-wireless.mac-address. it had the MAC from the other interface. I made sure that it is also not set. Easy modify any variable with

$ nmcli connection modify "My Cafe"  802-11-wireless.mac-address ""