Posts

  • Resizing images

    For the projects that I work on, be it the computer stuff or my cars, I like to document it with taking photos of the process and the result. Sometimes it is easier to use a photo to show something, instead of many lines of code.

    Some of the photos is shared on online communities like forums, and I don’t like posts where the images are so big that I have to side-scroll (even on my big monitors.. ), so I adjust the size of the images that I post myself. I also self-host the images, so it also helps me minimize the used space on the VM and also helps in the bandwitdh use on the website.

    It started with an easy little bash script, that loops through all the files it sees in the directory from where the script is run and for each .jpg file, it resize it to correct aspect ratio of the original and set the corresponding size correctly (e.g. 4032×3024 -> 1024×768). The 768^ sets the lowest size of the image to 768, meaning if the image is 800×1024 the 800 will be set to 768 and the 1024 will follow the ratio, and if it is 1024×800, it will still use the 800 to change the size of the image.

    for FILE in *.jpg; do
            echo "Converting: $FILE"
            magick $FILE -resize 768^ \
                    converted/cnv-$FILE
    done

    After the file is resized it is output’ed to the directory converted and the letters cnv- is added to the file, making it easy for me to see that it is converted. It will most likely be changed later on, but I still want something to differentiate it from the old file, in case they are copied to the same directory at one point.

    The new script is quite bigger, because it checks a lot of things before it even attempts to resize the image. It has checks to see if the variable actually holds a directory name instead of a file name, and it checks if the image has already been converted.

    It ensures that the file trying to be resized is an image, and also strips the metadata from the converted image, making sure it keeps the default orientation. I think a script that rotates the image for you, in the case it is needed is better than not keeping the original orientation of the image.

    So, here’s the new script

    #!/usr/bin/env bash
    
    # Check to make sure that the directory is not empty.
    shopt -s nullglob
    
    # Create directory if it does not exist
    mkdir -p converted
    
    # Initialize counters
    count_new=0
    count_skipped=0
    
    # Check if the file is an image.
    checkImage() {
            local filename="$1"
    
            # Check if it is a file we are handling
            if [[ -f "$filename" ]]; then
                    # Read out the mime-type of the file
                    MIME_TYPE=$(file --mime-type -b "$filename")
    
                    # Check if it is an image, then resize it.
                    if [[ "$MIME_TYPE" == image/* ]]; then
                            resizeImg "$filename"
                            ((count_new++))
                            return 0
                    fi
            fi
    }       
    
    # Resize the image
    resizeImg() {
            local filename="$1"
            
            # Resize the image, and strip out metadata
            magick "$filename" -auto-orient -strip -resize 768^ "converted/cnv-$filename"
    }
    
    # Loop through and check if the file is an image
    for FILE in *; do
            # Check if the variabel is actually an directory 
            # We check for a file in checkImage, but its good to stop as early 
            # as possible.
            if [[ -d "$FILE" ]]; then 
                    continue
            fi
    
            # Check if the file has been converted earlier
            if [[ -f "converted/cnv-$FILE" ]]; then
                    ((count_skipped++))
                    continue
            fi
    
            checkImage "$FILE"
    done
    
    # Output the amount of images that have been resized
    echo "---------------------------------------"
    echo "Done! Prosessed in $(pwd):"
    echo "  - New images converted: $count_new"
    echo "  - Previously converted:   $count_skipped"
    echo "---------------------------------------"

    If I put it in one of my paths in the shell, I would be able to use this in any picture folder that I have, and make sure that every image is uniform in size, and also make sure that the it does not matter if it is a .jpg, .jpeg, .png etc.

  • Networking – MTU and ping

    So, sometimes you need to test the size of a package or optimal maximum transmission unit (MTU) that goes through the network or a tunnel. For instance the MTU of a WireGuard tunnel is usually 1420 bytes (for IPv4), and with the header overhead it comes out around 1380 bytes.

    To actually test if the tunnel passed the amount of bytes needed to not fragment (dividing up the package), one way to test is to use ping.

    ping -M do -s 1380 IP

    From the man page:
    -M pmtudisc_opt
    Select Path MTU Discovery strategy. pmtudisc_option may be either do (set DF flag but subject to PMTU checks by kernel, packets too large will be rejected),
    want (do PMTU discovery, fragment locally when packet size is large), probe (set DF flag and bypass PMTU checks, useful for probing), or dont (do not set DF flag).

    From what we can see, the -M do enables the do not fragment part of ping, and it tries to send the packet through.

    Pinging through an WireGuard tunnel with a size of 1400 bytes:

    ping -M do -s 1400 10.10.50.10
    PING 10.10.50.10 (10.10.50.10) 1400(1428) bytes of data.
    ping: local error: message too long, mtu=1420
    ping: local error: message too long, mtu=1420

    Same test with the size set to 1380 bytes:

    ping -M do -s 1380 10.10.50.10
    PING 10.10.50.10 (10.10.50.10) 1380(1408) bytes of data.
    1388 bytes from 10.10.50.10: icmp_seq=1 ttl=63 time=33.2 ms
    1388 bytes from 10.10.50.10: icmp_seq=2 ttl=63 time=32.4 ms


    So.. where can this be usefull? When working with networks, sometimes you encounter different technologies that has different MTU’s, like for instance the WireGuard tunnel.

    Other such things are VLans, QinQ – which is VLans inside of VLans, IPSec tunnels and more.

    Ping is a great tool to test basic network functionality before breaking out bigger guns. Maybe it’s just the size that is misconfigured.

  • My current running hardware

    I have 2 laptops, 1 desktop, 4 “servers” running, and one media center PC that is not currently set up. Not counting raspberry pi’s.

    The main laptop that I use is a Lenovo X1 Carbon 5th gen, which is running Fedora 43. It is used for when I’m configuring things and for when I’m doing some programming.

    This is the type that I am using:

    X1 Carbon 5th Gen – Kabylake (Type 20HR, 20HQ) Laptop (ThinkPad) – Type 20HR – Model 20HR0022MX

    It is dual-Core (2 cores, 4 threads) with a base Frequency of 2.5 GHz with a maximum frequency of 3.1 GHz, and 8 GB of ram.


    Second laptop is an Lenovo T450s with 8 GB of ram, running Fedora 42 at the moment.

    It is used as an work station in my garage, so that I am able to search for things when I work on my cars.

    The plan is to also use it to update my todo-lists while I’m working on them, and when I get my minimal viable product (MVP) of my todo app (web interface) up and running, it will be used to update while I’m working.


    The desktop was built in the autumn of 2025, luckily before the price hike on ram, ssd and everything else that can be used in a datacenter.

    The specs are:

    • MSI B760 Motherboard
    • Intel Core i7-14700K – 3.4 GHZ with maximum frequency of 5.6 GHZ – 20 Cores + 8 HT cores.
    • Kingston Fury Beast RGB DD5 – 64 GB
    • Kingston NV3 SSD – 1 TB
    • Asus Prime GeForce RTX 5070 OC – 12 GB

    The desktop is running Fedora 43, and is used for gaming (Steam), programming and just normal PC use. I’ve had some strange instability with the Nvidia card and Fedora 43. On 42 it was rock solid, so still looking into what could be the fault of it.

    The instability is that it sometimes goes into a powersave state (blanks screen and stops), where it never comes back or if it comes back it goes to the powersave state again.

    Moving forward I will also use it to test different things using kvm/qemu to run virtual machines, just to get more run time and experience of using that.


    The media center PC is an Lenovo ThinkCentre M60e with 8 GB ram, running Debian and not much else at the moment.

    The plan for this one, is to set up some sort of media player so that I’m able to use it in my living room. Today I don’t have anything that I can play my stored media from. I do have a blueray/dvd player, but all my media is ripped and stored on my fileserver, so I would much rather use the stored media instead of looking through all my dvd’s to see which one I want to watch.


    Servers – not actual server hardware, more their function in the network.

    The Fileserver is a Intel Core i5-7400 cpu and 32 GB of ram. It has 4x 4 TB disks set up with ZFS on ubuntu 24.04 LTS. It has 2 network cards running in LACP mode, mostly for throughput. Gives the network the ability to use 2 Gbps of bandwith for my SMB traffic.

    The only reason for the amount of ram, is that it was used as a virtualization host, now it sits idle with only samba running on it.

    Virtualization server 1 is an Dell Optiplex of some sort, not sure which iteration it is. It runs the VM’s in KVM/Qemu, and is the host for the VM that holds my Unifi Network controller and PI-Hole, and the VM that holds my internal Wiki.

    PVE 1 – Virtualization server 2 is a Intel Core i7-8700 CPU with 64 GB ram, and some SSD storage. This is used as my main virtualization server for running services that are to be used for internal and external services. Running Proxmox

    PV2 – Virtualization server 3 is a Intel Core i7-6700K CPU with 32 GB ram, and some SSD storage. This is used as an testing server, where I’m not in any way afraid of losing anything that is running on the server. It is not used for anything critical. Running Proxmox


    The network consist of a mini pc running PFSense as my router and firewall, which is connected to a Cisco 2960 switch, which again is connected to a 8 port Unifi switch. The mini pc is powerful enough to route the full bandwidth of my internet connection which is 250 Mbps, whit some traffic analytics running on top.

    This gives me the ability to separate things into different VLans and manage the network in a way that gives me more options on how I can design the various services that I want to run.

  • Hello world!

    The launch of Ardal Labs – The site for me to document what my weird mind comes up with!

    When I write this it is a Monday evening, and during the weekend I finally got most of the things I have been looking at to work. I wanted a site that loaded pretty quick, on a budget friendly Virtual Private Server (VPS).

    So this is it, up and running and ready for me to write more about what I do and what I try. I hope you will enjoy reading about it as much as I enjoy tinkering and getting things working.

    I will use this space to document how and why I have setup things the way that I have, and also as an reminder of how I set it up.

    Still some small tweaks I need to fix, so that I get the page as I want it. Hope you come back for more.