Skip to content

Instantly share code, notes, and snippets.

View sheharyaar's full-sized avatar

Shehar Yaar sheharyaar

View GitHub Profile

I have used virtme-ng here. For QEMU command, refer to : https://gist.github.com/sheharyaar/4a03135a77c8fe5425b856d33b82437c

Why Virtme-ng

  • Easy to use as compared to QEMU.
  • Can build custom kernel or from source.
  • Uses the host file-system (Copy-On Write), changes are discarded when the VM exits.
  • Can run host kernel (useful for debugging kernel modules).
  • For testing kernel modules, easily switch git commits, build and test.
@sheharyaar
sheharyaar / dkms.conf
Last active June 30, 2025 20:12
DKMS module for Lunatik
PACKAGE_NAME="lunatik"
PACKAGE_VERSION="1.0"
# Core module
BUILT_MODULE_NAME[0]="lunatik"
BUILT_MODULE_LOCATION[0]=""
# lib/*.ko modules (dependencies)
BUILT_MODULE_NAME[1]="luadevice"
BUILT_MODULE_LOCATION[1]="lib"
@sheharyaar
sheharyaar / resize_disk_image.md
Created February 14, 2025 14:48 — forked from joseluisq/resize_disk_image.md
How to resize a qcow2 disk image on Linux

How to resize a qcow2 disk image on Linux

This example takes olddisk.qcow2 and resizes it into newdisk.qcow2, extending one of the guest's partitions to fill the extra space.

1. qcow2 format

1.1. Verify the filesystems of olddisk.qcow2

@sheharyaar
sheharyaar / lunatik-conntrack-nat.md
Created August 23, 2024 04:34
Conntrack and NAT Support in Lunatik

Conntrack and NAT support for Lunatik

Reference kernel Version : 6.10

Goal

The goal of the feature should be to :

  • allow fetching the conntrack entries (tuples) and connection info.
  • ability to add entries from lua modules (for custom netfilter modules that need to perform NAT. Eg - L7 load balancing from netfilter using lunatik).
  • ability to perform NAT for atleast inet protocols.

Relevant Headers

@sheharyaar
sheharyaar / network-namespace.md
Last active October 31, 2024 10:35
Creating/Deleting network namespaces

Steps to create a pair of namespace and connect them

  1. Create the namespaces using sudo ip netns add <ns_name>
sudo ip netns add ns1
sudo ip netns add ns2
  1. Connect these namespaces using a virtual ethernet (created in pairs) using sudo ip link add netns type veth peer name :
@sheharyaar
sheharyaar / netfiilter-madness.md
Last active August 6, 2024 09:23
Netfilter madness

API changes

  1. nf_register_hook() till 4.12, from 4.13.0 we have nf_register_net_hook()
  2. nf_hookfn signature changed (with addition of struct nf_hook_state) in version 4.1.0. Before :
static inline void nf_hook_state_init(struct nf_hook_state *p,
				      unsigned int hook,
				      int thresh, u_int8_t pf,
 struct net_device *indev,
@sheharyaar
sheharyaar / cache-line.md
Created June 16, 2024 07:16
My random notes on cs stuff..

cache alignment and packing

  1. Data is transferred between memory and cache in blocks of fixed size, called cache lines or cache blocks. When a cache line is copied from memory into the cache, a cache entry is created.
  2. The cache entry will include the copied data as well as the requested memory location (called a tag).

Resources

  1. https://stackoverflow.com/questions/39971639/what-does-cacheline-aligned-mean
  2. https://en.algorithmica.org/hpc/cpu-cache/cache-lines/
  3. https://en.algorithmica.org/hpc/cpu-cache/alignment/
  4. https://en.wikipedia.org/wiki/Data_structure_alignment
  5. https://ryonaldteofilo.medium.com/memory-and-data-alignment-in-c-b870b02c80fb

Host

$ sudo qemu-system-x86_64 \
 --enable-kvm \
 -cpu host -smp $(nproc) \
 -m 8192 \
 -kernel linux-next/arch/x86_64/boot/bzImage \
 -append "rw nokaslr root=/dev/vda1" \
 -device virtio-net,netdev=vmnic -netdev user,id=vmnic \
 -device VGA,vgamem_mb=256 \
@sheharyaar
sheharyaar / dtschema.md
Created May 7, 2024 21:51
Steps to write yamls for Devicetree bindings and test them
@sheharyaar
sheharyaar / lua-c-api.md
Last active August 15, 2024 08:57
My notes on Lua and Lua C API for GSoC 2024 Lablua project