Putting an image on a Raspberry Pi

  1. Download a .raw.xz file
    1. In this case, it was https://download.opensuse.org/distribution/leap/15.4/appliances/openSUSE-Leap-15.4-ARM-KDE-raspberrypi.aarch64.raw.xz
    2. Yes, I also downloaded the .sha256 file and ran sha256sum against the downloaded image to make sure the image file was not damaged during transfer.
  2. Open a terminal session and become root
  3. Determine which device the SD card is
    1. In this case, it was /dev/sdc
  4. Copy the image file to the SD card
 xzcat /home/david/Downloads/openSUSE-Leap-15.4-ARM-KDE-raspberrypi.aarch64.raw.xz | dd bs=4M of=/dev/sdc iflag=fullblock oflag=direct status=progress; sync

Raspberry Pi and i3 window manager

I am really liking the combination of Raspbian and i3. I’ve always liked tiling windows; let the computer do the work for me to maximize the screen size of what I can get done. Me messing with window sizes is a waste of my time. Windows got particularly bad when the “tile” function added an extra blank column for people with touch-screens. I don’t have a touch-screen; so why‽‽‽ But I digress.

Novaspirit Tech has a nice video about how to add i3 to Raspbian.

The short form list of steps is:

  1. cd Downloads
  2. git clone https://github.com/Airblader/i3
    1. So this one turned out to be a little more difficult than it is portrayed in the video, because since then, Git Hub has decided that passwords are bad, and I should have to log in, create a token, and use the token in place of the password. Okay, I jumped through those hoops.
  3. sudo apt install meson
  4. sudo apt install dh-autoreconf libxcb-keysyms1-dev libpango1.0-dev libxcb-util0-dev xcb libxcb1-dev libxcb-icccm4-dev libyajl-dev libev-dev libxcb-xkb-dev libxcb-cursor-dev libxkbcommon-dev libxcb-xinerama0-dev libxkbcommon-x11-dev libstartup-notification0-dev libxcb-randr0-dev libxcb-xrm0 libxcb-xrm-dev libxcb-shape0 libxcb-shape0-dev
  5. cd i3
  6. mkdir build; cd build
  7. meson ..
  8. ninja
  9. sudo ninja install
  10. cd /etc/xdg
  11. cd lxsession
  12. cd LXDE-pi
    1. One quibble I have with this video is that using tab completion is a good thing, and this step was an excellent opportunity to demonstrate it. Essentially, we have done cd /etc/xdg/lxsession and now would be the right time to do ll
      1. Well, I do ll because I have set up an alias for ls -l
      2. There are two directories listed, and both begin with “LXDE”
      3. cd (space) and just hit the tab key is the answer here. The result is the same as typing cd LXDE (without hitting the Enter key). If the plain LXDE directory was the right one (it is not) I could just hit the Enter key. Since it is the other one I want, I type the next character (the dash) and hit the Tab key again. Then I hit Enter. I never had to hit the Shift key to get to that uppercase L for LXDE. The computer did the work for me.
  13. Edit both desktop.conf and autostart
    1. Near the top of desktop.conf, change window_manager=i3 then save and exit.
    2. In autostart, comment out @lxpanel and @pcmanfm, then save and exit.
  14. sudo reboot
  15. On start, you will be prompted to configure i3. Yes, generate a config
  16. Pick your modifier key. I do like the key on the left between Ctrl and Alt. I also like the little stickers that put a proper penguin over the Winders logo. I’m going to write this as $mod although the $ is not typed; it is just an indicator that whichever key is the the modifier key is variable and can change depending on your choice.
  17. sudo apt install i3status
  18. $mod+shift+r for restart i3
    1. This gets us the i3 status line at the bottom.
  19. sudo apt install dmenu
  20. sudo apt install rofi
  21. cd .config/i3
    1. because of the reboot above, we started in our home directory. .config is a hidden directory (because of the leading dot in the file name). i3 is the sub-directory underneath, where the file config exists.
  22. edit the file config
    1. There is some good instruction in the video here about checking out which keys do what. For example, seeing that $mod+Enter launches a terminal is important; ditto $mod+d launches drun (which is apparently desktop run ?)
      1. $mod+arrow keys switch the focus between active windows.
    2. Find your way to bindsym $mod+d exec --no-startup-id and replace the end dmenu_run with rofi -show drun -width 400 -lines 5
    3. Save and exit config
    4. $mod+shift+r to restart i3
      1. Now $mod+d brings up a searchable list of things to run (like Firefox).

And now I have a beautiful set up to install WordPress on my Raspberry Pi. I’ve got a terminal side-by-side with the web browser instructions, and I didn’t have to mess with screen sizing at all. The windows are as useful as possible, and the computer did that work for me.

I may have enjoyed this somewhat more than normal because of also listening to Noisestorm on YouTube. 😀

Raspberry Pi – sed for customization

I like automation, and have a project to migrate a friend’s web site to WordPress. There are a lot of MP3 files to move, so I’d like to script it.

I prefer to not test in production (in other words I’m not insane when it comes to computer operations) but that means having a consistent development environment. The Raspberry Pi is a very capable piece of equipment for a very reasonable price. So I think I want to automate building a development environment there.

I’m going to go with the Raspberry Pi OS with desktop

The short form of installing this is:

  1. Download the correct image
    1. I went with Raspbian instead of OpenSUSE because I want sound to work. Apparently the sound driver for Raspberry Pi has not been merged into Linux officially. As soon as it is, then OpenSUSE will have the sound driver baked in. But until then, I want to go with a Linux distribution that adds in the drivers for the Raspberry Pi sound hardware.
  2. Copy the image to the Micro SD card
    1. Open a terminal prompt
    2. unzip -p 2021-05-07-raspios-buster-armhf.zip | sudo dd bs=4M of=/dev/sdc iflag=fullblock oflag=direct status=progress; sync
      1. This assumes that current working directory is the directory where the 2021-05-07-raspios-buster-armhf.zip file is.
      2. This comes from https://scribles.net/writing-raspbian-os-image-to-sd-card-on-linux/ – Thank you Max
      3. Note that the “out file” part of the DD command has a device specifier, and if you put in the wrong one, you can completely destroy your machine. Before you plug the Micro SD card in, do df -h and note the list of devices. None of the listed devices must be in your of=/dev/sdx option of the dd command.
      4. For example: I do df -h and I see a bunch of /dev/sda and a few /dev/sdb listed. This tells me that I must not use either of those for my outfile device. In my case, it happens to be /dev/sdc for my outfile device.
      5. My machine does not have a built in Micro SD slot. I bought an external USB dongle that lets me plug in memory cards. When I plug the dongle in, then /dev/sdc becomes an available device. This is correct – I don’t want dd overwriting any of my permanent devices.

After the image is copied to the Micro SD card, I can (software) eject the removable device, plug it into the Raspberry Pi and power on the Pi. After first boot, there are security updates to install; but after that I’ve got a virgin machine with bog standard software on it. Development is ready to begin!

First, create a couple of aliases

echo "..='cd ..'" > ~/.bash_aliases

echo "ll='ls -l'" >> ~/.bash_aliases

Finally, sed to edit /etc/inputrc

sudo sed --in-place=.original -e '/^# "\\e\[5/ s/# //' -e '/^# "\\e[\6/ s/# //' /etc/inputrc

Okay, so what does this do?

sed is the stream editor that let’s one search and replace inside files.

sudo is the command that grants permissions in Raspbian to edit files in /etc

--in-place=.original is the sed option to copy the file to a new name, first, before editing the file. The file will named the same as it was before, but with .original appended to the file name. I could just have easily used .backup or .bak

-e is the sed short form of --expression

It tells sed that what is between the single quotes is an expression to process. Note that the above command line has two expressions.

The two expressions are almost identical. Let’s break the first one down:

/^# "\\e\[5/ s/# //

First is a search, designated by the first /…/ pair. Second is a substitution, designated by the /…/…/ triplet (but the reason it is a substitution is because of the s in front of the triplet).

In this case, what we are searching for is:

^# "\\e\[5

The line in /etc/inputrc literally has this:

# "\e[5~": history-search-backward

You can see that the sed search expression ^# "\\e\[5 differs from the actual line by the leading carat character ^ and a couple extra backslashes.

That leading ^ (carat) is the instruction to sed that the match only works at the beginning of a line. First find the beginning of a line, then proceed.

The next few characters are just an exact match: # "

The line in inputrc has \e following the double quote mark; but, because this is going to processed on a command line (or by a shell script), we have to warn the command line interpreter that there is an actual backslash in the expression. Backslashes are normally an “escape” character on the command line, warning that “whatever you would normally do with the next character that you see, don’t do it. Even though the character is in the list of special characters that get special handling, just ignore that and deal with it as if it were not a special character”. Which is a long way of saying that to deal with \ in the data, we need to specify \\ in the script or command line.

Same thing applies with the [ character; it is normally a special character. The inputrc file has e[5 in the data, so we need e\[5 in the expression.

So the search part within the first two slashes matches when there is a beginning of a new line, a pound sign character, a space character, a (double) quote character, a backslash character, the letter e, an (opening) square bracket character, and the numeral 5.

The substitution part of the expression matches on the pound sign character and the space character, and replaces them with nothing. That’s what s/# // does: “s” in front of the slash triplet says we are going to do substitution, what to substitute are the quote and space, and what to substitute them with is the empty set: between the second and third slashes is nothing.

The second expression differs from the first by 6 instead of 5. This is from Changing the history search keystrokes

Easy button:

update_system_defaults.sh

(One should always look at the contents of the file instead of just blindly running it)

New toy: Raspberry Pi 4

So of course, the first thing I want to do (after installing Raspbian and applying updates) was to add some aliases and switch the editor and history search commands.

Changing the editor to vim

Changing the editor to vim was easier, once I knew how.

  • Install vim
  • update-alternatives

Vim does not come installed by default on a Raspbian. But adding it is easy enough:

sudo apt-get install vim

I had found someone that said (when thing weren’t working the way I wanted) to sudo apt-get install vim-full ← this does not work! There is no package “vim-full” from which to install. At least not on my fresh-out-of-the-box Raspbian machine.

sudo update-alternatives --config editor

This opened up a list of available editors, numbered for selection, with an asterisk next to the default. It was set to nano, but I wanted vim.

Except that there were two vim choices: vim.basic and vim.tiny

Which one to choose? Neither looks like vim.full to me. 😉

Turns out I wanted vim.basic

Now, I can be in the less utility, and if I want to edit the file (and I already have permission to do so) I can hit the v key and be editing in vim.

Adding some aliases

This was super easy. I created a file, ~/.bash_aliases and added the alias commands to it.

alias ..='cd ..'
alias ll='ls -l'

Changing the history search keystrokes

This one was the closest to what is described in my How to make Ubuntu have a nice bash shell like OpenSuSE post.

sudo vim /etc/inputrc

Find the commented out commands, and uncomment them:

# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward

All I have to do is to delete the “#” character that declares \e[5~ and \e[6~ to be a comment. With vim, this is the x key