# linux Linux is a kernel. See https://xkcd.com/456/ [TPM](TPM) stuff # learn https://kernelnewbies.org/Linux_Kernel_Newbies is a good starting point for learning about the kernel. https://kernelnewbies.org/Outreachyfirstpatch -> Write your first patch for the kernel https://man7.org/tlpi/ -> The Linux Programming Interface -- Michael Kerrisk https://github.com/PacktPublishing/Linux-Device-Driver-Development-Second-Edition -> Linux Device Driver Development, Second Ed. -- John Madieu # kernel ``fs/`` → virtual file system implementation (generic fs code and toplevel implementation of fs syscalls), specific filesystems ``mm/`` → virtual memory management *(``mmap, kmalloc, vmalloc``)* ``kernel/`` → core kernel code, scheduler, primitives (``printk``), process syscalls *(``fork, exit``)* ``net/`` → network generic code and protocol implementations; most syscalls in ``net/socket.c`` [Interactive map of the Linux kernel](https://makelinux.github.io/kernel/map/) # xset change xorg settings ## display power management (DPMS) xset s off Disable screen saver blanking xset s 3600 3600 Change blank time to 1 hour xset -dpms Turn off DPMS xset s off -dpms Disable DPMS and prevent screen from blanking xset dpms force off Turn off screen immediately xset dpms force standby Standby screen xset dpms force suspend Suspend screen # Notes __NOTE:__ This section is meant for tidbits of useful knowledge on linux, mostly commands. Ideally, these notes will branch out over time, and I will refactor them into separate topics under Linux. * On a systemd-based system you can restrict a process’s memory use with ``systemd-run --scope -p MemoryMax=500M --user program`` * To open a port in Linux with iptables: ```sh # allow TCP ipv4 iptables -I INPUT -p tcp --dport 3389 -j ACCEPT # allow UDP ipv4 iptables -I INPUT -p udp --dport 3389 -j ACCEPT # allow TCP ipv6 ip6tables -I INPUT -p tcp --dport 3389 -j ACCEPT # allow UDP ipv6 ip6tables -I INPUT -p udp --dport 3389 -j ACCEPT ``` * To add swapfile to Ubuntu 20 server: * ``sudo fallocate -l 1G /swapfile`` * ``sudo chmod 600 /swapfile`` * ``sudo mkswap /swapfile`` * ``sudo swapon /swapfile`` * **Makes changes permanent:** ``echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab`` * **Java**: * ``apt-cache search openjdk`` to search for all available java packages. * ``update-alternatives --config java`` to select default java runtime * To add a user ``sudo useradd -m username`` which will create user along with home directory. * To list all users run ``cat /etc/passwd`` * To type unicode symbols in Linux, hold ``CTRL+SHIFT+U``, let go of all three, type the unicode code and press space. * Generate a random password with ``tr -dc A-Za-z0-9_ < /dev/urandom | head -c 16 | xargs`` * Enable promiscuous mode on network adapter (for network tools under a VM) with ``chmod a+rw /dev/vmnet0`` * Run linux with bad memory (from pragmaticaddict) * Test with memtest86+ * Use the memmap kernel option to mark the area as reserved * Example: memmap=0x121640a20$0x12410abb0 * Run command as system user: `su - targetuser -s /bin/bash` * See keycodes easily with `xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'` * Parallelize with `NUM_PROCS=$(cat /proc/cpuinfo | awk '/^processor/{print $3}'| wc -l)` `< $@ xargs -d '\n' -P $NUM_PROCS -I {} /bin/bash -c "{}"` * View your webcam with mpv `av://v4l2:/dev/video0 --profile=low-latency` * View speed of interface `cat /sys/class/net//speed` * Rename everything in cwd to lowercase `for f in *[[:upper:]]*; do mv -- "$f" "${f,,}"; done` # MIME Configure default applications for xdg-* at `~/.config/mimeapps.list` # Links * https://www.catb.org/~esr/writings/unix-koans/introduction.html -> Unix teachings of the Master Foo * https://linux-audit.com/about/ -> linux articles, guides, security information * https://beej.us/guide/ - useful resources on unix & programming (sockets, C, GDB, …) - C guide - GDB https://cb.vu/unixtoolbox.html https://sergiu121.github.io/docs/index.html -> USO lab book starter on operating systems and (mostly) linux https://ocw.cs.pub.ro/courses/uso/cursuri/start -> USO wiki, slides and resources http://quotes.cat-v.org/programming/bumper-sticker-computer-science -> 20/20 hindsight CS quotes https://perl.plover.com/ -> Lots of unix stuff: history, teachings, presentations on various topics. https://djoffe.com/stuff/linuxref/ -> useful linux CLI tools with description https://blog.robertelder.org/linux-hardware-debugging/ -> hardware debugging resource https://0xax.gitbooks.io/linux-insides/content/ -> kernel internals; work in progress book https://github.com/mk-fg/fgtk -> helpful public domain scripts ## News * https://lwn.net/headlines/rss -> weekly linux news * https://www.phoronix.com/ -> frequent kernel updates