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'
    • 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 mountpoints into the /media folder

    # $ sudo mkdir /media/dnas
    $ sudo mkdir /media/qnas
    $ sudo mkdir /media/snas
    $ sudo mkdir /media/qnas/Download
    $ sudo mkdir /media/qnas/Media
    $ sudo mkdir /media/qnas/Vincenzo
    $ sudo mkdir /media/qnas/Vincenzo-Home
    $ sudo mkdir /media/snas/Immich-Library  # Only if Immich is installed
    $ sudo mkdir /media/snas/Vincenzo
  • 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.

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!

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

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=cred=/path/to/cred-file,uid=raspi,gid=raspi
      
      [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 (or remove the Option line if there is no login).

  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

[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=<YOUR_DUCKDNS_DOMAINS>
    export DUCKDNS_TOKEN=<YOUR_DUCKDNS_TOKEN>

Warning

Don't forget to edit the <YOUR_DUCKDNS_DOMAINS> and <YOUR_DUCKDNS_TOKEN> fields. 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
⚠️ **GitHub.com Fallback** ⚠️