Raspi-Mobile: Difference between revisions

From Coolscript
Jump to navigation Jump to search
No edit summary
 
(62 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Intro=
Raspi-Mobile is designed to run as a '''Mobile Device''' together with your '''Tablet''' or '''Laptop''', prepared for conditions such as in a Train, Flight, Hotel and so on.<br>
The project has its focus to run as a '''Streaming Server''' next to common features like '''Wireless''' and '''Internet-Routing''' support.<br>
<br>Two interesting Raspberry/Linux issues are solved:<br>
*'''True automatic mounting of USB flush drives'''
**Plugin any USB flush drives and mount the device automatically, supporting the filesystems ntfs, vfat and exfat
*'''Graceful shutdown'''
**This solves the issue of preventing disk damages in case of losing electricity power.
**No need to login or connecting a keyboard and monitor to shutdown the device graceful, just plugin the '''shutdown usb device''' to initiate an instant and graceful shutdown


=Disk=
=Features=
 
*'''Easy to setup''' just download one of the available image and write it to your memory card.
*Expand the filesystem after fresh installation
*Supporting the [https://www.raspberrypi.org/products/raspberry-pi-4-model-b/ Raspberry4]. The project was developed on Raspian 10 and Raspian 11
raspi-config - Advanced - Expand Filesystem
*Slim image file download, the image size is less than 2GB
 
*Automatic mounting and un-mounting [https://en.wikipedia.org/wiki/USB_flash_drive USB flash drives]
Delete docs to get more disk space
**Supported file systems: ntfs,ext32 and vfat
sudo rm -rf /usr/share/doc/
*Graceful shutdown using a special prepared USB flash drive labeled with '''RASPI-CLEAN-SHUTDOWN'''
sudo rm -rf /usr/share/man/
*Wireless support, the device has a mangement web to customize WiFi settings like SID and password
sudo rm -rf /usr/share/locale/
*Routing support together with ethernet connectivity, all interfaces are using DHCP
 
*Support OpenVPN
=APT=
*Support of common protocols for streaming:
**SMB/CIFS
**WebDav
**SFTP
**HTTP


apt-get update
=Easy Installation=
apt-get upgrade
*Write the image to a '''Micro SD Card''' with the size of equal or better greater than '''2GB''', there is no limit, use any size of your Micro SD Card
**To write the Image you may use tools like [https://sourceforge.net/projects/win32diskimager/ DiskImager]
*Insert the Micro SD Card to your Raspberry and start it
**The disk will get automatically expanded to the maximum size during the first boot
***Optional you may check the disk size by logging in via '''ssh''' and then run '''raspi-config''', goto '''advanced''' and then '''expand filesystem''', finish and reboot
*'''Installation finished'''


*View packages
==Default Username and Password==
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
*Username '''pi'''
*Password '''raspberry'''
*Remove and clean
apt-get remove libraspberrypi-doc --purge
apt-get clean
apt-get purge
apt autoremove


*Install additional packages needed for this project
==Hostname and Aliases==
apt-get install mc autofs iptraf samba samba-common nftables apache2 locate tcpdump ncdu
Note: Hostname resolution is only available when connected through WiFi
apt-get install hostapd wireless-tools dnsmasq iw bridge-utils
*Hostname '''raspberrypi'''
*Aliases
**raspi
**raspberry
*IP (alias to eth0, works even if eth0 is disconnected)
**192.168.5.1


==SSH==
ssh pi@raspi
ssh pi@192.168.5.1
*Become root
sudo -i


=Apapter=
==Wireless default access==
*Turn on WiFi and leave Bluetooth off
*WiFi SID
root@raspberrypi:~# rfkill unblock 0
**Raspi-Mobile
root@raspberrypi:~# rfkill block 1
*WiFi Passwd
**raspberry


  root@raspberrypi:~# rfkill
*RaspAP Web-Interface
  ID TYPE      DEVICE      SOFT      HARD
  http://raspi:8080
  0 wlan      phy0  unblocked unblocked
  http://192.168.5.1:8080
  1 bluetooth hci0    blocked unblocked


=sysctl=
=Change the password for the pi user=
*/etc/sysctl.conf
==Connect using SSH==
  net.ipv4.ip_forward=1
===Change the Linux Password===
*Activate
Note: Changing the Linux password will cover '''sftp''' too
  sysctl -p
  ssh pi@raspi
*Type
  pi@raspberrypi:~ $ '''sudo -i'''
root@raspberrypi:~# '''passwd pi'''
New password:
Retype new password:
passwd: password updated successfully


===Change the SMB/CIFS Password===
This might need a new windows login after the change
pi@raspberrypi:~ $ '''sudo -i'''
root@raspberrypi:~# '''smbpasswd pi'''
New SMB password:
Retype new SMB password:
===Change the HTTP/WebDav Password===
htpasswd /etc/apache2/.htpasswd pi


=User/Group=
=Add a new user=
  addgroup sambagrp
===Add a new user to Linux===
  usermod -a -G sambagrp pi
This example will add the user '''admin'''<br>
Note: Changing the Linux password will cover '''sftp''' too<br>
*Login first
ssh pi@raspi
*Type
root@raspberrypi:/# '''adduser admin'''
Adding user `admin' ...
Adding new group `admin' (1002) ...
Adding new user `admin' (1001) with group `admin' ...
Creating home directory `/home/admin' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for admin
  Enter the new value, or press ENTER for the default
        Full Name []: Raspi Admin
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
  Is the information correct? [Y/n] Y


=Samba=
*Add the new user to the sudo group in order to allow the user to become root
*Set a password for the pi user
  usermod -a -G sudo admin
  smbpasswd -a pi


*/etc/samba/smb.conf
===Add a new user to SMB/CIFS===
[global]
  workgroup = WORKGROUP
  server string = %h server (Linux)
  #interfaces = eth0
  bind interfaces only = yes
  log file = /var/log/samba/log.%m
  panic action = /usr/share/samba/panic-action %d
  server role = standalone server
  obey pam restrictions = Yes
  passwd program = /usr/bin/passwd %u
  passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
  pam password change = Yes
  map to guest = Bad User
  #log level = 4 #To be used for debugging purposes
  local master = no
  disable netbios = yes
[automnt]
  comment = automnt
  path = /automnt
  valid users = @sambagrp
  browsable = yes
  writable = yes
  read only = no
  create mask = 0660


*Enable and start smbd, disable nmbd
  pi@raspberrypi:~ $ '''sudo -i'''
systemctl enable smbd
  root@raspberrypi:~# '''smbpasswd -a admin'''
  systemctl restart smbd
  New SMB password:
  systemctl stop nmbd
  Retype new SMB password:
  systemctl disable nmbd
  systemctl mask nmbd


=AUTOFS/UDEV=
*Add the new user to the samba group
*Add config file for our usb sticks
  usermod -a -G sambagrp admin
touch /etc/auto.rbusb
*Add to the end of auto.master
  echo '/automnt /etc/auto.rbusb --timeout=5 --ghost' >> /etc/auto.master
*Restart
systemctl restart autofs
*Get autofs helper script
wget https://coolgeo.org:/download/scripts/autofs-config.pl -O /usr/local/bin/autofs-config.pl
chmod u+x /usr/local/bin/autofs-config.pl
*Add udev rule
echo 'ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd*", ATTRS{vendor}=="*", RUN+="/usr/bin/perl /usr/local/bin/autofs-config.pl"' > /etc/udev/rules.d/90-local.rules
*Reload udev
udevadm control --reload-rules && udevadm trigger
*TEST USB


=Apache2/WebDAV=
===Add a new user to HTTP/WebDav===
htpasswd /etc/apache2/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin


DavLockDB /var/www/DavLock
=Change the WiFi SID and Password=
<Directory "/automnt/">
*Login to http://raspi:8080/ and navigate to '''Hostspot''', do the changes on the website.
  Options +Indexes
'''OR'''
  Order allow,deny
*SSH to the Raspberry, then edit ''' /etc/hostapd/hostapd.conf  '''
  Allow from all
  Require all granted
</Directory>
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /automnt
    Alias /automnt /automnt
    <Directory /automnt>
    DAV On
    </Directory>
    <Directory "/automnt">
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /etc/apache2/.htpasswd
    Require valid-user
    </Directory>
</VirtualHost>
*Enable WebDAV Mod
a2enmod dav_fs
*Restart
systemctl restart apache2
*Add the PI user to WebDAV
htpasswd -c /etc/apache2/.htpasswd pi


=HOSTS=
=Unexpected Shutdown=
*/etc/hosts
The Raspberry should never get shutdown unexpected during a write operation (eg by pulling the power cable), <br>
  192.168.5.1    raspi raspberry raspberrypi raspap
this may result in a data loss or filesystem damage.<br><br>
The reason for this is the behavior of the SD card, see a very good explanation for this [https://raspberrypi.stackexchange.com/questions/50345/is-it-okay-to-just-pull-the-plug here]<br><br>
For security reasons the syslog facility has been turned off, this way there is less writing activity which protects the filesystem in case of a unexpected shutdown.<br>
To enable syslog in case of debugging:
  systemctl enable syslog.socket rsyslog.service
systemctl start syslog.socket rsyslog.service


=Graceful Shutdown=
Raspi-Mobile has a preconfigured udev rule configured to allow a '''greaceful shutdown''' by conneting a special prepared '''USB flash drive''', <br>
*The drive label '''RASPI-CLEAN-SHUTDOWN''' will instantly shut down the device.<br><br>
*Example of changing the drive label on Windows
{| style="width: 100%;"
|style="width:90%; vertical-align: top;"|
[[image:Raspi-clean-shutdown.png|900px|left]]
|}
<br><br>
*Once connected then please give the device a few seconds to complete the shutdown


=INIT=
=Known Problems=
*/etc/systemd/system/rbinit.service
'''Problem:'''<br>
[Unit]
In case of unplugging eth0 while wlan0 is active then it can happen that the SID is no more visible even after reboot<br>
Description=RaspiMobile Init Script
'''Solution:'''<br>
After=network.target
Shut down the Raspi and start again without eth0, then shutdown again, plugin eth0 and start again.<br>
[Service]
Type=oneshot
ExecStart=/usr/sbin/rbinit
[Install]
WantedBy=multi-user.target


*/usr/sbin/rbinit
#!/bin/bash
#Workaround for Ipdads
/sbin/ip addr add 192.168.5.1/24 dev eth0:0
/sbin/nft -f /etc/nftables.conf


*Apply the new init script
=Download=
chmod 755 /usr/sbin/rbinit
*<span style="color:red">2GB image [https://coolscript.org/download/images/raspi-mobile-raspian11.img Raspbian11]</span><br>
systemctl enable rbinit.service
*<span style="color:red">2GB image [https://coolscript.org/download/images/raspi-mobile-raspian10.img Raspbian10]</span>
systemctl start rbinit


=NFT=
=Links=
*/etc/nftables.conf
*Installation protocol: https://coolscript.org/index.php/Setup-Raspi-Mobile


#!/usr/sbin/nft -f
flush ruleset
table inet filter {
        chain input {
                type filter hook input priority 0; policy accept;
        }
        chain forward {
                type filter hook forward priority 0; policy accept;
        }
        chain output {
                type filter hook output priority 0; policy accept;
        }
}
table ip nat {
        chain PREROUTING {
                type nat hook prerouting priority -100; policy accept;
        }
        chain INPUT {
                type nat hook input priority 100; policy accept;
        }
        chain POSTROUTING {
                type nat hook postrouting priority 100; policy accept;
                oif "eth0" masquerade comment "masq for eth0"
                oif "wlan0" masquerade comment "masq for wlan0"
        }
        chain OUTPUT {
                type nat hook output priority -100; policy accept;
        }
}
*Apply
systemctl enable nftables
systemctl start nftables




=DHCPCD=
[[image:rb01a.png|300px|left]]<br>
/etc/dhcpcd.conf
[[image:rb-bundle01.png|500px|left]]
 
[[image:rb-back01.png|500px|left]]<br>
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private
nohook lookup-hostname
#wlan0 configuration
interface wlan0
static ip_address=192.168.4.1/24
static routers=192.168.4.1
gateway
 
*Apply changes
systemctl daemon-reload
systemctl restart dhcpcd.service
 
 
 
=DNSMASQ=
 
*/etc/dnsmasq.d/090_wlan0.conf
---------------------------------------------------------
#Raspi-Mobile wlan0 configuration
interface=wlan0
dhcp-range=192.168.4.50,192.168.4.255,255.255.255.0,30d
---------------------------------------------------------
 
*Apply
systemctl enable dnsmasq
systemctl restart dnsmasq
 
 
=HOSTAPD=
 
*/etc/hostapd/hostapd.conf
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
auth_algs=1
wpa_key_mgmt=WPA-PSK
beacon_int=100
ssid=raspi-mobile
channel=1
hw_mode=g
ieee80211n=0
wpa_passphrase=raspberry
interface=wlan0
wpa=2
wpa_pairwise=CCMP
country_code=DE
ignore_broadcast_ssid=0
 
 
*Apply
systemctl unmask hostapd
systemctl enable hostapd
systemctl restart hostapd
 
 
=Disable syslog=
*Save disk space and avoid corruptions on the sd card
systemctl stop syslog.socket rsyslog.service
systemctl disable syslog.socket rsyslog.service
 
=Features=
*Neofetch Banner
apt-get install neofetch
bash -c $'echo "neofetch" >> /etc/profile.d/mymotd.sh && chmod +x /etc/profile.d/mymotd.sh'
 
*RaspAP
curl -sL https://install.raspap.com | bash

Latest revision as of 22:20, 12 March 2022

Intro

Raspi-Mobile is designed to run as a Mobile Device together with your Tablet or Laptop, prepared for conditions such as in a Train, Flight, Hotel and so on.
The project has its focus to run as a Streaming Server next to common features like Wireless and Internet-Routing support.

Two interesting Raspberry/Linux issues are solved:

  • True automatic mounting of USB flush drives
    • Plugin any USB flush drives and mount the device automatically, supporting the filesystems ntfs, vfat and exfat
  • Graceful shutdown
    • This solves the issue of preventing disk damages in case of losing electricity power.
    • No need to login or connecting a keyboard and monitor to shutdown the device graceful, just plugin the shutdown usb device to initiate an instant and graceful shutdown

Features

  • Easy to setup just download one of the available image and write it to your memory card.
  • Supporting the Raspberry4. The project was developed on Raspian 10 and Raspian 11
  • Slim image file download, the image size is less than 2GB
  • Automatic mounting and un-mounting USB flash drives
    • Supported file systems: ntfs,ext32 and vfat
  • Graceful shutdown using a special prepared USB flash drive labeled with RASPI-CLEAN-SHUTDOWN
  • Wireless support, the device has a mangement web to customize WiFi settings like SID and password
  • Routing support together with ethernet connectivity, all interfaces are using DHCP
  • Support OpenVPN
  • Support of common protocols for streaming:
    • SMB/CIFS
    • WebDav
    • SFTP
    • HTTP

Easy Installation

  • Write the image to a Micro SD Card with the size of equal or better greater than 2GB, there is no limit, use any size of your Micro SD Card
    • To write the Image you may use tools like DiskImager
  • Insert the Micro SD Card to your Raspberry and start it
    • The disk will get automatically expanded to the maximum size during the first boot
      • Optional you may check the disk size by logging in via ssh and then run raspi-config, goto advanced and then expand filesystem, finish and reboot
  • Installation finished

Default Username and Password

  • Username pi
  • Password raspberry

Hostname and Aliases

Note: Hostname resolution is only available when connected through WiFi

  • Hostname raspberrypi
  • Aliases
    • raspi
    • raspberry
  • IP (alias to eth0, works even if eth0 is disconnected)
    • 192.168.5.1

SSH

ssh pi@raspi
ssh pi@192.168.5.1
  • Become root
sudo -i

Wireless default access

  • WiFi SID
    • Raspi-Mobile
  • WiFi Passwd
    • raspberry
  • RaspAP Web-Interface
http://raspi:8080 
http://192.168.5.1:8080

Change the password for the pi user

Connect using SSH

Change the Linux Password

Note: Changing the Linux password will cover sftp too

ssh pi@raspi
  • Type
pi@raspberrypi:~ $ sudo -i
root@raspberrypi:~# passwd pi
New password:
Retype new password:
passwd: password updated successfully

Change the SMB/CIFS Password

This might need a new windows login after the change

pi@raspberrypi:~ $ sudo -i
root@raspberrypi:~# smbpasswd pi
New SMB password:
Retype new SMB password:

Change the HTTP/WebDav Password

htpasswd /etc/apache2/.htpasswd pi

Add a new user

Add a new user to Linux

This example will add the user admin
Note: Changing the Linux password will cover sftp too

  • Login first
ssh pi@raspi
  • Type
root@raspberrypi:/# adduser admin
Adding user `admin' ...
Adding new group `admin' (1002) ...
Adding new user `admin' (1001) with group `admin' ...
Creating home directory `/home/admin' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for admin
Enter the new value, or press ENTER for the default
       Full Name []: Raspi Admin
       Room Number []:
       Work Phone []:
       Home Phone []:
       Other []:
Is the information correct? [Y/n] Y
  • Add the new user to the sudo group in order to allow the user to become root
usermod -a -G sudo admin

Add a new user to SMB/CIFS

pi@raspberrypi:~ $ sudo -i
root@raspberrypi:~# smbpasswd -a admin
New SMB password:
Retype new SMB password:
  • Add the new user to the samba group
usermod -a -G sambagrp admin

Add a new user to HTTP/WebDav

htpasswd /etc/apache2/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin

Change the WiFi SID and Password

OR

  • SSH to the Raspberry, then edit /etc/hostapd/hostapd.conf

Unexpected Shutdown

The Raspberry should never get shutdown unexpected during a write operation (eg by pulling the power cable),
this may result in a data loss or filesystem damage.

The reason for this is the behavior of the SD card, see a very good explanation for this here

For security reasons the syslog facility has been turned off, this way there is less writing activity which protects the filesystem in case of a unexpected shutdown.
To enable syslog in case of debugging:

systemctl enable syslog.socket rsyslog.service 
systemctl start syslog.socket rsyslog.service

Graceful Shutdown

Raspi-Mobile has a preconfigured udev rule configured to allow a greaceful shutdown by conneting a special prepared USB flash drive,

  • The drive label RASPI-CLEAN-SHUTDOWN will instantly shut down the device.

  • Example of changing the drive label on Windows



  • Once connected then please give the device a few seconds to complete the shutdown

Known Problems

Problem:
In case of unplugging eth0 while wlan0 is active then it can happen that the SID is no more visible even after reboot
Solution:
Shut down the Raspi and start again without eth0, then shutdown again, plugin eth0 and start again.


Download

Links