basic configuration - vincios/rpi-setup GitHub Wiki

Other all tutorials in this wiki assumes that you have first followed this paragraph.

Please make sure to follow this steps before all other tutorials!

  1. The OS default user name is raspi

  2. Create an ~/Apps folder

    $ mkdir ~/Apps
  3. Create a ~/.logs folder

    $ mkdir ~/.logs
  4. Create a ~/.bash_aliases file

    • $ nano ~/.bash_aliases

    • Paste these lines

      alias ll='ls -l'
      alias la='ls -lA'
      alias lah='ls -lAh'
      alias cc='clear'
    • Exit and save

    • $ source ~/.bashrc

  5. Create a ~/.bash_env file

    • $ nano ~/.bash_env

    • Paste these lines

      export PUBLIC_DOMAIN=
    • Edit .bashrc file, add these lines

      # Envrionment variables definitions.
      # You may want to put all your additions into a separate file like
      # ~/.bash_env, instead of adding them here directly.
      
      if [ -f ~/.bash_env ]; then
          . ~/.bash_env
      fi
    • Exit and save

    • $ source ~/.bashrc

VNC "cannot currently show the desktop" in headless mode

Run raspi-config and change screen resolution to 1920x1080

AutoMount Nas folders

  • Install dependencies

    $ sudo apt update
    $ sudo apt install cifs-utils
  • Create the credentials files, in a ~/.credentials folder (create if not exists) One for each network device (if they have different credentials)

    • nano ~/.credentials/.qnas-<user>

      user=<YOUR-USER>
      password=<YOUR-PASSWORD>
      domain=WORKGROUP
    • Give access only to the user

      $ chmod 600 ~/.credentials/.qnas-<user>
    • Repeat for each network share you want to login

  • Run raspi-config and enable "Wait for Network at Boot" under "Boot options"

  • Follow Systemd automounts

Systemd automounts

From here and here.

See also 1 and 2.

Systemd can automatically mount shares. Just like services, you have to create some special Unit files that describe how and where to mount.

There are two unit files:

  • .mount units: define how to mount shares
  • .automount units: define mount points that are mounted on-demand, i.e. only when they are accessed

automount units are optional; but, when they exist, corresponding mount units must also exist. The former are meant to add functionalities to existing instances of the latter.

Important

Note that the name of the file must map to the actual filesystem mount target, that is mnt-winshare.(auto)mount refers to /mnt/winshare. This is also CASE SENSITIVE!

Dashes and other special characters must be escaped (see man systemd-escape).

E.g. to mount in /home/user/Myfolder the file names must be home-user-Myfolder.(auto)mount.

Tip

To generate the right file name for the unit file you can use the systemd-escape utility

$ systemd-escape -p --suffix=mount "/media/nas/Media"
$ systemd-escape -p --suffix=automount "/media/nas/Media"

If you want to mount the shrare //192.168.1.1/Multimedia to the mount path /media/nas/Media

  1. Create the unit files

    • /etc/systemd/system/media-nas-media.mount

      [Unit]
      Description=NAS Multimedia Mount
      
      [Mount]
      What=//192.168.1.1/Multimedia
      Where=/media/nas/Media
      Type=cifs
      Options=_netdev,rw,credentials=/path/to/credentials,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm
      
      [Install]
      WantedBy=multi-user.target
      
    • /etc/systemd/system/media-nas-media.automount

      [Unit]
      Description=Automount NAS Multimedia Mount
      
      [Automount]
      Where=/media/nas/Media
      
      [Install]
      WantedBy=multi-user.target
      

Note

Don't forget to replace with your credential file!

  1. Reload the units

    $ sudo systemctl daemon-reload
    

Then you can mount an unmount the share just like all other services:

$ systemctl start media-nas-media.mount
$ systemctl stop media-nas-media.mount

And enable the mount at boot with

$ systemctl enable media-nas-media.mount

OR the on-demand automount with

$ systemctl enable media-nas-media.automount

Tip

You can start all the shares mounted on /media with this command:

systemctl list-units -t mount --all --state=failed --state=dead --no-legend --plain | cut -d ' ' -f 1 | grep media- | sed 's/\\\\/\\\\\\\\/g' | sed 's/.mount/.automount/g' | xargs sudo systemctl start

You can stop all the shares mounted on /media with this command:

systemctl list-units -t mount --all --state=mounted --no-legend --plain | cut -d ' ' -f 1 | grep media- | sed 's/\\\\/\\\\\\\\/g' | sed 's/.mount/.automount/g' | xargs sudo systemctl stop

Explaination:

  • -t mounts limits the list of systemd units to mounts
  • --all also shows the failed ones
  • --state=failed/--state=dead/--state=mounted shows only failed/unmounted/mounted ones
  • --no-legend --plain prints a machine parsable output
  • cut -d ' ' -f 1 shortens the output to just the unit name
  • grep media- limit output to those units that starts with 'media-' (i.e. the ones mounted to /media)
  • sed 's/\\\\/\\\\\\\\/g' escapes backslashes (from '' to '\')
  • sed 's/.mount/.automount/g' uses .automount unit files intead of .mount (OPTIONAL)
  • xargs systemctl start/stop sends the remaining items as arguments to systemctl start/stop

You can show the status of the mounts with this command:

systemctl list-units -t mount --all | grep media- | grep 'dead\|mounted\|failed'

Explaination:

  • -t mounts limits the list of systemd units to mounts
  • --all also shows the failed ones
  • grep media- limit output to those units that starts with 'media-' (i.e. the ones mounted to /media)
  • grep 'dead\|mounted\|failed' highlight the current state

Bonus: Scripts to automate generation/installation of mounts

To install the scripts download systemd-install-mount.sh and systemd-generate-mount.sh from this repository and copy them in /usr/local/bin.

$ wget -O systemd-install-mount.sh https://raw.githubusercontent.com/vincios/rpi-setup/refs/heads/main/General/Systemd/systemd-install-mount.sh
$ wget -O systemd-generate-mount.sh https://raw.githubusercontent.com/vincios/rpi-setup/refs/heads/main/General/Systemd systemd-generate-mount.sh
$ sudo chmod +x systemd-install-mount.sh systemd-generate-mount.sh
$ sudo cp systemd-install-mount.sh /usr/local/bin/systemd-install-mount
$ sudo cp systemd-generate-mount.sh /usr/local/bin/systemd-generate-mount
$ sudo chown root:root /usr/local/bin/systemd-generate-mount /usr/local/bin/systemd-install-mount
$ sudo chmod 755 /usr/local/bin/systemd-generate-mount /usr/local/bin/systemd-install-mount

[Deprecated] fstab

Important

⚠️ DEPRECATED Use the Systemd automounts

From here.

  • Run sudo nano /etc/fstab and add these lines (changes paths as done in point 2)

    #//192.168.1.200/Volume_1         /media/dnas/                   cifs    credentials=/home/raspi/.credentials/.dnascredentials,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm,vers=1.0   0   0
    //192.168.1.210/Multimedia        /media/qnas/Media/             cifs    credentials=/home/raspi/.credentials/.qnas-vincenzo,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm            0   0
    //192.168.1.210/Download          /media/qnas/Download/          cifs    credentials=/home/raspi/.credentials/.qnas-vincenzo,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm            0   0
    //192.168.1.210/homes/vincenzo    /media/qnas/Vincenzo-Home/     cifs    credentials=/home/raspi/.credentials/.qnas-vincenzo,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm            0   0
    //192.168.1.210/Vincenzo          /media/qnas/Vincenzo/          cifs    credentials=/home/raspi/.credentials/.qnas-vincenzo,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm            0   0
    //192.168.1.200/Vincenzo          /media/snas/Vincenzo/          cifs    credentials=/home/raspi/.credentials/.snas-vincenzo,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm            0   0
    //192.168.1.200/Immich-Library    /media/snas/Immich-Library/    cifs    credentials=/home/raspi/.credentials/.snas-vincenzo,uid=raspi,gid=raspi,iocharset=utf8,file_mode=0755,dir_mode=0755,noperm            0   0
    
    
  • Check if OK with sudo mount -a

Samba shares

  • sudo apt-get install samba

  • sudo nano /etc/samba/smb.conf

  • Default Samba share of the user folder have some security restrictions. So, choose one of the following options

    • OPTION 1: edit the default configuration

      • In the [homes] section of smb.conf find the line read only = yes and change to read only = no
    • OPTION 2: crate a new one configuration

      • Add to the bottom

        [PiShare]
        comment = Pi Share
        path = /home/raspi
        browseable = yes
        writeable = yes
        only guest = no
        read only = no
        create mask = 0740
        dierectory mask = 0750
        public = yes
        valid users = %S
        
  • Choose a smb password for raspi user

    $ sudo smbpasswd -a raspi
  • Restart smb

    $ sudo systemctl restart smbd.service

Note for Windows users

If the network folder is not visible or is not writeable, try this solutions (one at time):

  • If windows explorer doesn't ask for password when you open the network share: open the Windows Credential Manager and, under the Windows Credentias tab, manually add the credentias for the network address \\RASPBERRYPI. Then, restart Explorer or the computer.

  • On the raspberry, try this command sudo pdbedit -a -u raspi

Duckdns cron configuration [πŸ¦†]

Adapted from here.

  1. Create a .duckdns folder in your home directory

  2. Create a duck.sh file with following content

    timestamp() {
      date +"%Y-%m-%d %H:%M:%S"
    }
    
    echo url="https://www.duckdns.org/update?domains=$DUCKDNS_DOMAINS&token=$DUCKDNS_TOKEN&ip=" | curl -k -o ~/.duckdns/log.log -K -
    echo " | Last run: $(timestamp)" >> ~/.duckdns/log.log
  3. Create a duck.conf.sh file with following content

    export DUCKDNS_DOMAINS=$(echo $PUBLIC_DOMAIN | cut -d '.' -f 1)
    export DUCKDNS_TOKEN=<YOUR_DUCKDNS_TOKEN>

Warning

Make sure that the $PUBLIC_DOMAIN environment variable exists and is set to a duckdns.org domain. Don't forget to edit and <YOUR_DUCKDNS_TOKEN> field. No quotes needed.

Tip

<YOUR_DUCKDNS_DOMAINS> can be a comma separated (NO spaces) list of domains.

  1. Make the script executable

    $ chmod 700 duck.sh duck.conf.sh
  2. Test the script

    $ . $HOME/.duckdns/duck.conf.sh; $HOME/.duckdns/duck.sh

Warning

Note the leading dot .

Tip

πŸ’‘Check the result in the log.log file

  1. Edit the cron configuration

    $ crontab -e
  2. Add this line to the bottom

    */5 * * * * . $HOME/.duckdns/duck.conf.sh; $HOME/.duckdns/duck.sh >/dev/null 2>&1
  3. Start the cron service

    $ sudo service cron start

zsh and omz

  1. Install zsh

    $ sudo apt update
    $ sudo apt install zsh
  2. Set as default shell

    $ chsh -s $(which zsh)
  3. Logout and login to start zsh. If no .zshrc file exists in your home, the configuration wizard will start automatically.

  4. Install Oh My Zsh

    $ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  5. Install the plugins:

  6. Install powerlevel10k: πŸ”– HOWTO

  7. Link .bash_aliases to zsh aliases ()$ZSH_CUSTOM/aliases.zsh), so you can continue to update a single aliases file.

    $ ln -s ~/.bash_aliases $ZSH_CUSTOM/aliases.zsh
  8. Add to .zshrc to load custom enviroment variables from .bash_env

    $ echo "# Load custom enviroment variables\nsource ~/.bash_env" >> .zshrc
  9. (OPTIONAL) Uncomment these lines in .zshrc

    # ...
    # Uncomment one of the following lines to change the auto-update behavior
    zstyle ':omz:update' mode auto      # update automatically without asking
    # ...
    # Uncomment the following line to enable command auto-correction.
    ENABLE_CORRECTION="true"
    # ...
    # Uncomment the following line to display red dots whilst waiting for completion.
    # You can also set it to another string to have that shown instead of the default red dots.
    # e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
    # Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
    COMPLETION_WAITING_DOTS="true
⚠️ **GitHub.com Fallback** ⚠️