Saturday 9 May 2020

Linux Raspberry Software I always install

Linux Raspberry Software I always install


sudo apt update

sudo apt full-upgrade

sudo apt-get distro-update
https://phoenixnap.com/kb/update-raspberry-pi

sudo apt install gwenview konsole krename kate dolphin kdenlive gimp chromium-browser synaptic k3b htop ffmpeg handbrake handbrake-cli vlc mediainfo mediainfo-gui caja-mediainfo gparted xz-utils qemu qemu-utils qemu-system-common qemu-system qemu-guest-agent aqemu qemu-system-gui gufw caja-rename rename gprename rename-flac flatpak neofetch nmap iftop cheese imagemagick fswebcam krita pinta kid3 nmap mariadb-common mariadb-client mariadb-server krusader ttf-mscorefonts-installer oxygen-icon-theme xsane bluefish gthumb ffmpegthumbnailer wine dosbox sslh sshfs encfs fuse-zip fuseiso youtube-dl wireshark winff partitionmanager kcalc imagemagick-doc imgsizer imageinfo unrar unrar-free filezilla calibre konqueror pan audacity mousepad ubuntu-restricted-extras net-tools mkvtoolnix shotcut libvpx-dev libvpx-doc vpx-tools hwinfo



MakeMkv - makes MKV backup of DVD
https://www.makemkv.com/

sudo apt remove vim trojita byobu 

sudo apt autoremove

https://www.raspberrypi.org/documentation/raspbian/updating.md

sudo apt-get distro-update
https://phoenixnap.com/kb/update-raspberry-pi

Furthermore you may need to run a dist-upgrade to perform larger upgrades:
sudo apt-get dist-upgrade
https://raspberrypi.stackexchange.com/questions/164/how-do-i-update-software-and-firmware

Overclocking Raspberry Pi 4

Overclocking Raspberry Pi 4

These are the settings I use to
  1. Overclock my Raspberry Pi 4 
  2. Increase the GPU memory allocation to 384 MB (out of 4 GB)
Warning!
The overclocking changes can potentially damage your Raspberry Pi 4.
I accept no responsibility for any damages.
You make these changes at your own risk!

Caveat emptor !



gpu_mem=384
over_voltage=6
arm_freq=2000
gpu_freq=600

Edit the below files depending on your Linux Distribution.



Lubuntu / Ubuntu 20.04


sudo nano /boot/firmware/usercfg.txt



Raspbian


sudo nano /boot/config.txt



Victoria Secret 2018 720p test

Victoria Secret 2018 1080p test




Sunday 15 September 2019

Raspberry Pi Apache Web Server Installation

Introduction

This page describes how I setup the web server Apache, specifically Apache2, along with PHP and MariaDB.

Note I use MariaDB in preference to the original MySQL database.

hostname -I
sudo apt-get install apache2 apache2-doc apache2-utils
sudo apt-get install php libapache2-mod-php php-pear -y
sudo apt-get install mariadb-server mariadb-client php-mysql
sudo service apache2 restart

Apache is run via the binary apache2
To start / stop Apache use:

/etc/init.d/apache2
or
apache2ctl

but not /usr/bin/apache2 directly as it will not work on Raspbian Linux as it is Debian based.

sudo apache2ctl stop   
sudo apache2ctl start
sudo apache2ctl restart



Important Files Location

Put your website into:

/var/www/html/

It will be necessary to rename the default Apache index.html file via

mv index.html oldindex.html

You can then copy your website into /var/www/html/

  • Apache 2 Configuration files

          /etc/apache2/apache2.conf
          apache2.conf is the main Apache configuration file.
          This file is used by Debian instead of the more common httpd.conf

If you have PHP installed then you probably want Apache to serve index.php as the default page instead of index.html


To do this :

sudo nano /etc/apache2/mods-enabled/dir.conf

and put index.php before index.html so that it looks like :

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Note that some Apache configurations put DirectoryIndex in either httpd.conf or apache2.conf

Debian, on which Raspbian is based, uses apache2.conf and dir.conf for some of the configurations.




Further Help


INSTALL APACHE, PHP 7.0 AND MYSQL/MARIADB ON A RASPBERRY PI (LAMP) WITH PHPMYADMIN

How to install a web server on the Raspberry Pi (Apache + PHP + MySQL)

How to setup a Raspberry Pi web server with Raspbian Stretch Lite, Nginx, MariaDB and PHP as the LEMP stack




Raspbian Raspberry Pi Static IP Address

Introduction


This page will describe how to set a static IP address for your Raspberry Pi using Raspbian.
See separate post on how to do the same for Lubuntu / Ubuntu 20.04



Steps


Begin by finding your current IP address :

hostname -I

You will receive back one or more IP address, such as ;

192.168.1.70 
192.168.1.69

From this you learn that your computer is on the 192.168.1.0 network.

Then run :

sudo apt-get install nmap
sudo nmap -sP 192.168.1.0/24

adjusting 192.168.1.0 according to your network.

From this I learnt that my router (dsldevice.lan) has the IP address 192.168.1.254

The DNS server, which is often the same iP address as your router can be found via :

cat /etc/resolv.conf

which gave:

nameserver 192.168.1.254

Now go into your router's admin pages and find the DHCP range.

The next step, while in the router's admin pages, is to limit the DHCP Network Range to 192.168.1.50 - 192.168.1.99. This provides 50 available dynamic IP addresses, which is sufficient for most households.

What this means is that 192.168.1.100 - 192.168.1.253 or 154 IP addresses are available to be set as static IP addresses. 

Again while in the router's admin pages, looking at the IP addresses connected to my router I found that only 192.168.1.201-192.168.202, and of course 192.168.1.254 for the router itself, had static IP addresses.

All other connected devices had dynamic DHCP addresses within the 192.168.1.50 - 192.168.1.99 range.

See the bottom of this page for screen captures from my router.

Running on my Raspberry Pi :

ifconfig

showed that the address for eth0 was 192.168.1.70 and wlan0 was 192.168.1.69

I therefore chose to setup my main Raspberry Pi using a static IP address for its Ethernet (eth0) connection, but to leave its wireless wlan0 to be dynamically set via DHCP.


sudo nano /etc/dhcpcd.conf


I added the following text to the end of the /etc/dhcpcd.conf file.

interface eth0
static ip_address=192.168.1.205/24
static routers=192.168.1.254
static domain_name_servers=192.168.1.254

sudo ip link set eth0 down
sudo ip link set eth0 up
ifconfig

Running ifconfig should show the change in IP address.

If the static IP address does not show up try running ifconfig several times, it sometimes takes a few seconds to show.






Thursday 12 September 2019

Creating a Raspberry Pi Samba Server

Introduction


This page provides the bare minimum information needed to get a Windows Samba server up and running on your Raspberry Pi.

Once the Samba server is running you will be able to play videos stored on the Samba server using clients such as iPad, Tablet, mobile phones and Windows PCs etc.


Installation


sudo apt update
sudo apt upgrade
sudo apt-get install samba samba-common-bin
sudo mkdir -p /home/shares/public
sudo chmod 777 -R /home/shares/public
sudo nano /etc/samba/smb.conf


sudo nano /etc/samba.conf (/etc/samba/smb.conf in XFCE)


At the end of the file add the following:
[Public]
comment = Raspberry Pi 4GB Samba Storage
path = /home/shares/public 
browseable = yes
only guest = no
create mask = 0777
directory mask = 0777
public = yes
guest ok = yes


sudo smbpasswd -a pi       (  sudo smbpasswd -a ubuntu in XFCE for user ubuntu )

The above creates a new samba user and sets the password.
To simply change the samba password to a new password use:

sudo smbpasswd pi

Adjust the following mount command to reflect the /dev/location of the files being shared (e.g. /dev/sda2).

sudo mount -t auto /dev/sda2 /home/shares/public

sudo /etc/init.d/smbd restart


Samba Client


To access Samba shares on your Raspberry Pi and other computers you will need to begin by installing :

sudo apt-get install smb4k smbclient


More to follow....


ext4 Partition Label


It may help you to arrange your partitions if they have meaningful names.

To change the name of an existing ext4 partition use e2label :

sudo e2label /dev/sda2 Files


Specifying Exact Drive / Partition to use as Samba Drive

blkid

Exam the output of blkid to find the UUID (unique identifier) of your chosen drive for Samba.

Here the chosen drive is /dev/sdb

/dev/sdb: LABEL="Samba4TB" UUID="979610b6-2a3f-432e-bc11-5465bcb5253c" TYPE="ext4"

To automatically use /dev/sdb without it becoming sdc or sdd etc if more drives are added at boot time, copy the text in red but remove the "

UUID=979610b6-2a3f-432e-bc11-5465bcb5253c

Now make sure your chosen drive is mounted.
Then run to find the mounting information for it in red.

cat /proc/mounts

/dev/sdb /media/ubuntu/Samba4TB ext4 rw,nosuid,nodev,relatime 0 0

Change (if necessary the desired location of the mount point to be consistent with Samba configuration file, e.g. 

/dev/sdb /home/shares/public ext4 rw,nosuid,nodev,relatime 0 0

sudo nano /etc/fstab

Add from the previous two commands the following to the bottom of the /etc/fstab file:

# Storage
UUID=979610b6-2a3f-432e-bc11-5465bcb5253c /home/shares/public ext4 rw,nosuid,nodev,relatime 0 0

Now umount your the Samba drive, e.g.

umount /dev/sdb

Then to reread the edited /etc/fstab and to update /etc/mtab or /proc/mounts that shows mounted drives run:

sudo mount -a



Example External USB Share

Using a USB drive as a share requires that the user mounting the drive be specified so that all guest and other Samba users requests go through that user.
Without

force user = pi

it simply isn't possible to access files via Samba on an external USB drive.

The share can be setup under Linux (not primarily Samba) so that nobody can Write but everyone can Access / View, so essentially everyone has read and execute permissions only.

[Samba-4TB-Hard-Drive]
comment = Samba 4TB USB WD Hard Drive
path = /media/pi/Samba4TB
Public = yes
read only = yes
browseable = yes
only guest = no
create mask = 0700
directory mask = 0700
Guest ok = yes
force user = pi

The Linux user group in this example was also pi

For more details Google for force user and external USB drive.

There is an AskUbuntu post 'Cannot sharing my second harddrive with Samba'

and

Sharing External Drive using Samba in Ubuntu 18.04


Wednesday 11 September 2019

Run Raspberry Pi 4 root directory / from a USB 3 SSD

Update

Since first writing this blog, a much better blog has emerged that covers in detail:

1. Continuing to use SD card for boot via /boot
2. Uses an SSD for everything not /boot e.g. root /

Raspberry Pi 4 USB Boot Config Guide for SSD / Flash Drives

I strongly recommend the James A. Chambers blog.

My original blog is shown below, which will shortly be updated with the above instructions, where relevant.

Until then I would use

Raspberry Pi 4 USB Boot Config Guide for SSD / Flash Drives



Introduction


Running the root directory / from a USB 3 SSD significantly increases the speed of your Raspberry Pi 4.
You will achieve desktop web performance in Chromium.
It is amazing how much faster the Pi 4 is with the root directory / on USB 3 SSD.

The speed increase will be particularly noticeable when you have several Chromium tabs open.

There are two steps:
  1. Edit the file /boot/cmdline.txt file (microSD)
  2. Run sudo rsync -avx / /media/pi/ExternalSSD
    replacing ExternalSSD with the SSD mount point in /media
Editing the /boot/cmdline.txt file tells the microSD to pass control to the USB 3 SSD by specifying that the root directory / is on the USB 3 SSD (i.e. not on the microSD).

You will still need the microSD for initial boot up but after that the Raspberry Pi 4 runs directly from the root directory / on the USB 3 SSD.

Finally you do the following steps at your own risk.
These instructions have been prepared in good faith and are provided without warranty. Things can and do go wrong.
I suggest making an offline copy of your microSD and using that for this procedure. 
In case of any problems you can always access your Raspberry Pi with the original microSD.

Caveat Emptor !




0. Preparation

Before you make any changes to /boot/cmdline.txt it should look similar to:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=4831f5fb-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

Begin by finding the UUIDs for ALL available disks on system:

ls -lha /dev/disk/by-uuid
lrwxrwxrwx 1 root root  10 Jan 19 17:43 3122c401-b3c6-4d27-8e0d-6708a7613aed -> ../../sdb2
lrwxrwxrwx 1 root root  10 Jan 19 17:43 3FFE-CDCA -> ../../sdb1

lrwxrwxrwx 1 root root   9 Jan 19 17:38 979610b6-2a3f-432e-bc11-5465bcb5253c -> ../../sda

cat /etc/fstab
PARTUUID=4831f5fb-01  /boot           vfat    defaults          0       2
PARTUUID=4831f5fb-02  /               ext4    defaults,noatime  0       1

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G   20G  7.9G  72% /
/dev/mmcblk0p1  253M   52M  201M  21% /boot
/dev/sda        3.6T  3.4T   14G 100% /media/pi/Samba4TB
/dev/sdb1       253M   40M  213M  16% /media/pi/temp1
/dev/sdb2        29G   18G   11G  62% /media/pi/temp2


sudo blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="3FFE-CDCA" TYPE="vfat" PARTUUID="4831f5fb-01"

/dev/mmcblk0p2: LABEL="rootfs" UUID="3122c401-b3c6-4d27-8e0d-6708a7613aed" TYPE="ext4" PARTUUID="4831f5fb-02"

/dev/sda: LABEL="Samba4TB" UUID="979610b6-2a3f-432e-bc11-5465bcb5253c" TYPE="ext4"

/dev/mmcblk0: PTUUID="4831f5fb" PTTYPE="dos"

/dev/sdb1: LABEL_FATBOOT="boot" LABEL="boot" UUID="3FFE-CDCA" TYPE="vfat" PARTUUID="4831f5fb-01"

/dev/sdb2: LABEL="rootfs" UUID="3122c401-b3c6-4d27-8e0d-6708a7613aed" TYPE="ext4" PARTUUID="4831f5fb-02"






1. Edit the /boot/cmdline.txt file


Begin by making a copy in case anything goes wrong:

sudo cp /boot/cmdline.txt /boot/cmdline.bak

sudo nano /boot/cmdline.txt

Change the text from:

root=PARTUUID=a4c81466-02
to
root=/dev/sda1

Note you will have a different PARTUUID number from a4c81466-02

So you should change  cmdline.txt  from something like:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=a4c81466-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

to :

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

The text to delete is in blue and the text to add is in red but you may also have to type the file system if not using ext4

Optionally, you may also want to delete quiet splash in order to view Linux's startup messages.




2. sudo rsync -avx / /media/pi/ExternalSSD


You will need an available partition, preferably sda1, on your USB 3 SSD.

I recommend the first partition and that this USB 3 SSD always be plugged in before any other USB storage device.

The USB SSD partition to be used as the root directory / would typically be /dev/sda1

If you really want to use the PARTUUID in place of /dev/sda1 then run

sudo blkid

Example output (not specific to this tutorial) :
pi@Rasp4-4GB:/ $ sudo blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="016B-16E4" TYPE="vfat" PARTUUID="56b1c1da-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="6ead9b69-967c-4c44-ac59-11075ed8e9a7" TYPE="ext4" PARTUUID="56b1c1da-02"
/dev/sdb1: LABEL_FATBOOT="boot" LABEL="boot" UUID="3FFE-CDCA" TYPE="vfat" PARTUUID="a4c81466-01"
/dev/sda1: LABEL="RaspberryPiBoot" UUID="128f5236-c026-44e5-abf8-69397c1e969f" TYPE="ext4" PARTUUID="002be3a8-01"
/dev/sda2: UUID="c0d9a904-2bda-4c38-87e0-5072cfc6ac4f" TYPE="ext4" PARTUUID="002be3a8-02"
/dev/sdb2: LABEL="rootfs" UUID="3122c401-b3c6-4d27-8e0d-6708a7613aed" TYPE="ext4" PARTUUID="a4c81466-02"
/dev/mmcblk0: PTUUID="56b1c1da" PTTYPE="dos"
/dev/sdd1: UUID="ad488156-5256-4e02-9382-cb2bf9c6bfed" TYPE="ext4" PARTUUID="f0cb35b6-01"
/dev/sdd2: UUID="9a4c2ce6-be96-4c66-8bb6-4ec2fda9f58c" TYPE="ext4" PARTUUID="f0cb35b6-02"
pi@Rasp4-4GB:/ $ 

In addition to PARTUUID, blkid will also show the UUID.

If you use root=/dev/sda1 you will be able to use any suitably prepared USB SSD and not just the paritcular SSD identified by PARTUUID.

I further recommend that the USB SSD partition be formatted using ext4 .

A good tool for creating the USB SSD partition and formatting under Linux / Raspberry Pi is GParted.

GParted can be installed via:

sudo apt-get install gparted

The next step is to run :

sudo rsync -avx / /media/pi/ExternalSSD

Replace ExternalSSD with the exact USB SSD mount point name shown when mounting in /media/pi/....

Enjoy !
:-)



Further Help


How to Run Raspberry Pi 4 or 3 Off an SSD or Flash Drive

Raspberry Pi 4 With an SSD: Dramatic Speed Improvements, Higher Price

YouTube : How to boot Raspberry PI4 from USB

Tuesday 27 August 2019

Raspberry Pi 4 ffmpeg screen recording using x11grab

Introduction

This page provides simple instructions on how to screen record videos on your Raspberry Pi 4 using nothing more than ffmpeg .

This ffmpeg approach is favoured over using the more common graphical tools for screen recording, as ffmpeg provides greater user control. Not all screen recorders work well with the Raspberry Pi 4.

One interesting finding is that the h264_omx video encoder seems to work a lot faster when the input and output are matroska container files mkv .

The h264_omx video encoder is noticeably slower when the container output file is an mp4 . It is therefore suggested to copy the final h.264 encoded video from a mkv to mp4 container as the final step and to do all video transcoding between mkv container files.

With this ffmpeg based screen capture method the user can create a series of screen recordings that can be combined to create a YouTube video etc using a video editor such as Shotcut.


ffmpeg


echo $DISPLAY
:1

ffmpeg -f x11grab  -s 1824x984 -i :1.0 -r 30 -c:v mpeg2video -b:v 6M -f matroska -y mytest-6MB-r30.mkv 




Method

Key points to remember are:

  1. Use the MKV matroska container
  2. Use the mpeg2video video codec for original screen recording
  3. Convert to mp4 and h.264 (if desired) as later steps

Note these instructions consider video only, they would need to be expanded to included audio. See bottom of page for further details.

ffmpeg -f x11grab  -s 1920x1080 -i :0.0 -r 30 -c:v mpeg2video -b:v 6M -f matroska -y mytest-6MB-r30.mkv

This example uses a 6 megabit video bit rate and a frame rate of 30 frames per second (fps). See ffmpeg documentation. The command also records the full screen.  

Now convert to h.264 using the GPU hardware encoder h264_omx using a 3 megabit video bit rate. Note the movflags and faststart are flags are optional but enable the file to start up quickly without the need for the entire file to download first.

ffmpeg -i mytest-6MB-r30.mkv -c:v h264_omx -b:v 3M -movflags +faststart -f matroska -y mytest-3MB-r30-h264_omx.mkv

Alternatively, consider 2 pass encoding which produces higher quality video but takes longer to encode:

ffmpeg -i mytest-6MB-r30.mkv -c:v h264_omx -b:v 3M -pass 1 -y -f matroska /dev/null && ffmpeg -i mytest-6MB-r30.mkv -movflags +faststart -c:v h264_omx -b:v 3M -pass 2 -f matroska mytest-3MB-r30-h264_omx.mkv 

Finally copy the video encoded to the mp4 container if desired:

ffmpeg -i mytest-3MB-r30-h264_omx.mkv -c:v copy -f mp4 -y mytest-3MB-r30-copy.mp4


That is it!



Further Help

For further advice, including recording audio at the same time as video please see the below links.

ffmpeg Capture Desktop wiki


How to get near-perfect screen recording quality?

How to make an MPEG2 video file with the highest quality possible using FFMPEG?


Screen recording (in X11) with ffmpeg

An Overview of H.264 Advanced Video Coding

Video Encoding Settings for H.264 Excellence (good discussion)