Schlagwort: Linux

  • Raspberry PI: Restoring a Backed-Up SD Card from dd-Image

    In accordance to this great blogpost I’d like to add restoring the backup for the sake of completion. This one’s real quick so let’s get started.

    A word of warning

    In the following we will work with diskutil (I’m on a Mac). Please take good care when picking and handling a disk device using that tool as mistakes can lead to severe data losses. And as I’m just a guy on the internet that loves to share knowledge I cannot cover any problems and cannot grant any liabilities. I just wanted to – again – share my knowledge and things that worked for me. If you have doubts, please step back, contact a professional and let me know of your doubts and sorrows in the comments down below.

    Restoring your backed-up Raspo-Image

    Given we created 2026-10-11-raspo-backup.img (can highly recommend the date naming schema) and given a fresh card, do the following steps:

    1. Plug in your new shiny card into your laptop containing the backup image using the builtin or external card reader of your choice.
    2. Locate your card’s dev-path. Please be careful to pick the right one using for example the shown name and/or available space as indicators.
      >diskutil list

      For me it was /dev/disk3 so going forward I will use that path as the example. You use yours of course!
    3. Unmount it.
      >diskutil unmountDisk /dev/disk3
    4. Write the backup to your new card. We use the rdisk-path like we did in the awesome post linked above.
      >sudo dd if=/path/to2026-10-11-raspo-backup.img of=/dev/rdisk3 bs=4m status=progress
    5. Eject the new card.
      >diskutil eject /dev/disk3
    6. Plug it into your Raspo.
    7. Recommended: Plug your raspo to an external monitor.
    8. Hit the power button to boot.
    9. Check your Raspo-system. It should be running as expected from a cloned system.

    In case you need it: Expand the new card’s file system

    The reason I had to backup my Raspo was that I ran a way too small SD card for way too long. That had to cause disk space trouble eventually, but I didn’t reckon I reach that point that fast. But well… here we are. So I had to backup everything, buy a new card with more space and deploy my system there whilst carefully working around the lack of disk space on the current system. The method Tony described best fulfilled these requirements. Thank you very much!

    After restoring my image as described above, I did the following to expand the file system on the card:

    The steps

    1. Open the Raspo config TUI:
      >sudo raspi-config
    2. Navigate to „Advanced Options“ and hit Enter
    3. Navigate to „Expand Filesystem“ and hit Enter.
    4. Confirm further panels until raspi-config offers you a reboot.
    5. Hit yes here or hit no and reboot it whenever you feel like.
      I recommend doing it right here.
    6. After reboot use
      >df -h
      in the terminal to check your disk space. It should be on par with your new card.

    Conclusion

    Alright. That one wasn’t that hard at all I hope. At this point I’d like to thank Tony once more for his great blogpost that saved my bottoms during these dire times. Please take good care, always watch your steps when working with diskutil and enjoy your Raspo as like do – again.

    As you might have seen I’m an avid Testautomation Engineer. So if you want to get to know my daily work, feel free to have a look here. Or if you’d rather continue working with Linux, I got you covered as well here, here and here.

    Have a great week!

    Share it with:
  • docker ps formatting – Cheat Sheet

    Checking the status of Docker containers is an important starting point, when it comes to debugging container clusters. docker ps is an ideal tool to get you started. Unfortunately, the output can sometimes be quite verbose and overwhelming.

    The --format parameter is supposed to ease the pain here, but Go templates can be quite tedious to write every time, too. To counter that a little, I reveal my favorite ready-to-alias docker ps calls in today’s post. I hope they make your everyday Docker life a little easier.

    # Are my expected containers up?
    docker ps --format "table {{.Names}}\t{{.Status}}"
    
    # What ports do my containers expose?
    docker ps --format "table {{.Names}}\t{{.Ports}}"
    
    # What networks are my containers assigned to?
    docker ps --format "table {{.Names}}\t{{.Networks}}"

    All of them can be extended with more docker ps command line parameters, even when aliased later on.

    As you may have noticed, my first column is always the container name followed by the property I’d like to analyse. This is my personal way to keep the output compact and focused on the problem at hand, but of course you can query any property you like. Check out the official documentation for a comprehensive list of available properties and pick what you need for the task.

    Do you have a favourite formatting? Or do you want to talk about any other question? Feel free to let me know in the comments below. I plan to publish more cheat sheet-style posts in the future. This helps me out to share recent learnings in a focused way and provides you with quick help and valuable insights. You can find another example here, where I demonstrate how to set up Linux users with low maintenance work afterwards. Or if you are into Rust like I am, the Rust modules cheatsheet might be a valuable companion, when it comes to structuring your code with Rust Modules.

    Until next time!

    Home » Linux
    Share it with:
  • Create a New Linux User

    To create a new Linux user is one of the most common task in traditional Linux system administration. It is so popular that there are even two command line utilities fully dedicated to the task: adduser (Debian and its derivates) and useradd (all). And since it’s so popular many different administrators have many different solutions for the same problem.

    Here I present mine. Note that I prefer sudo over working as root, but the steps work with root as well. Just omit the sudos.

    1. Create a personalised user group.
      $ sudo groupadd newuser
    2. Create the user with a home directory, a good default shell, its user group and further desired groups assigned.
      $ sudo useradd -m -s /bin/bash -g newuser -G sudo,orga newuser
    3. Set the user’s initial password.
      $ sudo passwd newuser

    Step summary for your automation needs

    sudo groupadd newuser
    sudo useradd -m -s /bin/bash -g newuser -G sudo,orga newuser
    sudo passwd newuser

    Prepare SSH access for our newly created Linux user

    If required, we can now enable the user to connect to our machine via SSH. We assume that the SSH demon is up and running and the user’s public key is available on our machine.

    1. Change into the user’s home directory.
      $ sudo cd /home/newuser/
    2. Create the .ssh directory.
      $ sudo mkdir .ssh
    3. Set the directory permissions of .ssh to 0700 (read-write-execute only for the user).
      $ sudo chmod 0700 .ssh/
      Note that the execute permission is necessary to access the directory; read does not suffice. This might be a little counterintuitive for new admins. (It surely was for me.)
    4. Change into our meticulously prepared directory.
      $ sudo cd .ssh/
    5. cat the user’s public key into a new file called authorized_keys.
      sudo cat /path/to/pubkey > authorized_keys
    6. Set the authorized_keys file permissions to 0600.
      sudo chmod 0600 authorized_keys
    7. Make sure that everything we created is assigned to the new user.
      cd ..
      sudo chown -R newuser:newuser .ssh/

      Now the user should be able to connect to us with SSH.

    Step summary for your automation needs

    sudo cd /home/newuser/
    sudo mkdir .ssh
    sudo chmod 0700 .ssh/
    sudo cd .ssh/
    sudo cat /path/to/pubkey > authorized_keys
    sudo chmod 0600 authorized_keys
    
  • cd .. sudo chown -R newuser:newuser .ssh/
  • Conclusion

    User creation is a staple task when working with Linux servers, and now you have a solid solution at hand that will lighten up your daily workload. So long. I hope this little sheet was useful to you. Usually I write about Rust, test automation and business topics. If you want to read more from me, this post combines Rust and test automation. In my day job, I also do lots of test automation, but here my key focus is Java. Hence, if you are rather interested in that, I’m also talking about fuzzing with Java.

    Or if you miss a detail, or you want to get your hands a little dirtier than just cheat sheet level, Linuxize has an in-depth post about the nitty gritty parts of user administration. It really helped me out a lot in the past.

    Have a nice day!

    Home » Linux
    Share it with: