Overview
- This tutorial demonstrates how we built up Ubuntu on RPI
- It talks about how to make a copied image with SD card also
Preparation
- Raspberry Pi
- Micro SD card (20GB minimum, 64GB or bigger is recommended)
- Micro USB-C power cable
- Micro HDMI male to HDMI male cable
- Mouse and keyboard
Installation
- NOTE: Skip the following steps and start from “Set Up By The Copied Image“ if you have the copied image.
INSTALL Node.js
- Run this step on Windows
- Download installation toolkit: Raspberry Pi Imager
WRITE OS Into SD card (Ubuntu Desktop 22.04 LTS 64-bit)
- Insert the SD card into the Computer'
- Open Raspberry Pi Imager
- Select Device Model, OS, and Storage options
- Click the NEXT button to start the installation
- Remove the SD card when it pops up the finished message
BOOT The Ubuntu
- Insert the SD card into the RPI
- Set “English (US)” as the system language
- Connect to Wi-Fi: ASUS_AX11000_5G-AUTO
- Set “Taiwan Time” as the Time Zone
- Set username and password
- username: rpiauto
- password: **
- Update the OS system to the latest
TURN OFF The Lock Screen
- Find the “Settings” option from the upper-right panel
- Select “Privacy” > “Screen”
- Change the “Blank Screen Delay“ option to “Never“
- Disable “Automatic Screen Lock“
- Disable “Lock Screen on Suspend“
TURN OFF The Updates Frequency
- Select the “Show applications“ option, and you can find it in the bottom-left panel
- Open “Software & Updates”
- Select the “Updates” tab
- Change the “Subscribed to“ option to “Security updates only“
- Change the “Notify me of a new Ubuntu version“ option to “Never“
- Type the password to activate
- Click Close
UPDATE & UPGRADE
- Open Terminal and type this command
# Update to the latest
$ sudo apt update && sudo apt upgrade -y
# Check if anything doesn't upgrade
$ sudo apt list --upgradable
... It shows any any package wait to update
# Using "sudo apt install --upgrade -y [package name]" to update upgradable packages till up-to-date
$ sudo apt list --upgradable
Listing... Done
- Open “Ubuntu Software”
- Select the “Updates“ tab and click “Update All“
ENABLE NOPASSWD On Linux Commands
# Some of the linux commands need to type admin password to activate it, but we prefer skip the password in Jenkins steps
# Open the sudoers file:
$ sudo visudo
# Add the following lines in the bottom of sudoers file:
...
[your_username] ALL=(ALL) NOPASSWD: [/command/in/bin]
e.g.
rpiauto ALL=(ALL) NOPASSWD: /bin/rm, /bin/cp, /bin/mkdir
# Save && Exit
INSTALL Essential Tools
# Install "screen"
$ sudo apt install -y screen
# Install "vim"
$ sudo apt install -y vim
# Install "nano"
$ sudo apt install -y nano
# Install "curl"
$ sudo apt install -y curl
# Install "net-tools"
# It supports ifconfig command
$ sudo apt install -y net-tools
# Install "ssh"
$ sudo apt install -y ssh
# Set SSH serice will starts after boot
$ systemctl enable ssh
# Install dd
$ sudo apt install coreutils
# Install tio
$ sudo snap install tio --classic
INSTALL And MOUNT SharePoint
# If the device is Linux, and you have cloned the RobotFramework source code, this action can be executed by shell script automatically.
# ./home/rpiauto/RobotFramework/Scripts/***.sh
# Update to the latest
$ sudo apt update && sudo apt upgrade -y
$ If it pops up error message, like:
dpkg: error processing archive /var/cache/apt/archives/python3.12_3.12.8-1+jammy1_arm64.deb (--unpack):
trying to overwrite '/usr/bin/python3.12', which is also in package python3.12-minimal 3.12.7-1+jammy1
...
# Try force-reinstall
$ sudo dpkg -i --force-overwrite /var/cache/apt/archives/python3.12_3.12.8-1+jammy1_arm64.deb
$ sudo dpkg -i --force-overwrite /var/cache/apt/archives/libpython3.12-stdlib_3.12.8-1+jammy1_arm64.deb
...
# Install cifs toolkit, this is a toolkit for share folder client
$ sudo apt install cifs-utils -y
# Create a Mount Point:
# Create a directory where you want to mount the share folder:
$ sudo mkdir /mnt/[samba_share]
or
$ sudo mkdir /home/rpiauto/RobotFramework/****
# Mount the Samba Share:
# Use the mount command to mount the Samba share to the directory you created. Replace server, share, username, and password with your actual server address, share name, username, and password:
$ sudo mount -t cifs [//remote/server/share/folder] [/local/mount/samba_share/folder] -o username=[username],password=[password]
or
$ sudo mount -t cifs //***.***.***.***/JenkinsTestResults /home/rpiauto/RobotFramework/**** -o username=****,password=****
INSTALL Git Bash and Clone Source Code
- No content
INSTALL Python And Packages
- No content
INSTALL Appium
- No content
INSTALL Robot Framework
- No content
INSTALL Chromium and Webdriver
$ sudo apt install -y chromium-browser chromium-chromedriver
INSTALL VSCode (Visual Studio Code) And Extensions
- No content
INSTALL Java / Amazon Corretto
- No content
Set Up By The Copied Image
ERASE SD Card Partition
- If the destination SD card is used, which means it divided, we need to erase it before starts
- Boot your RPI with the source OS and plug in the destination SD card on it
- Click the “Show Applications“ icon on the left-bottle side
- Find “Utilities“ > “Disks“
- There are several SD card info on it
- Check the “Device“ info
- One is “/dev/mmcblk0p1“, which is the current OS SD card
- The other is “/dev/sdaX“, X means the index of the plugged SD card
- Click the “-“ button to erase the “/dev/sdaX“ SD card, the volumes will merge into one partition after that.
BACKUP Image
# Find the INPUT_OS_SD and OUTPUT_OS_SD names
$ lsblk
...
sda 8:0 1 238.3G 0 disk
mmcblk0 179:0 0 238.3G 0 disk
- mmcblk0p1 179:1 0 256M 0 part /boot/firmware
- mmcblk0p2 179:2 0 238G 0 part /var/snap/firefox/common/host-hunspell
# Full Metal Backup
# Install coreutils, so you can use dd command
# [INPUT_OS_SD] is the source SD card
# [OUTPUT_OS_SD] is the destination SD card
# dd if=/dev/[INPUT_OS_SD] of=/dev/[OUTPUT_OS_SD] [Options]
# bs, read and write up to BYTES bytes at a time
# status, The LEVEL of information to print to stderr;
'none' suppressess everything but error messages
'noxfer' suppresses the final transfer statistics
'progress' shows periodic transfer statistics
# conv=sync, all input blocks are written to the output,
even if there are errors. It pads each block to
the specified block size with null bytes if necessary.
This can help prevent issues with incomplete writes and ensure data integrity.
$ sudo dd if=/path/to/source.img of=/path/to/destination.img bs=4M conv=sync,noerror status=progress
e.g.
$ sudo dd if=/dev/mmcblk0 of=/dev/sda bs=4M conv=sync,noerror status=progress
# Wait until the copy proccess finished, it usually takes 3 or more hours for a 256G SD card
CHANGE The Hostname / Computer Nmae
- To identify the current RPI, we set an accumulated number behind the hostname.
- e.g. if we have 3 pcs of RPI already, the newest RPI should be named rpiauto4 on the hostname
# The hostname can be found on the command line, it likes:
[user account]@[hostname name]:~$
# Verify the current hostname
$ hostname
rpiauto
# See more info about hostname by hostnamectl
$ hostnamectl
Static hostname: rpiauto
...
# Change the hostname by hostnamectl
$ hostnamectl set-hostname [new hostname]
$ hostnamectl
Static hostname: [new hostname]
...
# The commandline info doesn't changes util re-login
CHANGE The Displayed User Name / User ID Info (GECOS)
METHOD 1
- Go to “Settings” > “Users”
- Click the “Edit” icon
- Change the displayed user name to the same as the hostname
- Click “Enter”
METHOD 2
# The hostname/computer nmae can be found in /etc/passwd file
# From the above info:
# Username: It is used when user logs in. It should be between 1 and 32 characters in length.
# Password: An x character indicates that encrypted and salted password is stored in /etc/shadow file. Please note that you need to use the passwd command to computes the hash of a password typed at the CLI or to store/update the hash of the password in /etc/shadow file.
# User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.
# Group ID (GID): The primary group ID (stored in /etc/group file)
# User ID Info (GECOS): The comment field. It allow you to add extra information about the users such as user’s full name, phone number etc. This field use by finger command.
# Home directory: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /
# Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell. Please note that it does not have to be a shell. For example, sysadmin can use the nologin shell, which acts as a replacement shell for the user accounts. If shell set to /sbin/nologin and the user tries to log in to the Linux system directly, the /sbin/nologin shell closes the connection.
$ cat /etc/passwd
rpiauto:x:1000:1000:rpiauto4,,,:/home/rpiauto:/bin/bash
...
- After Changed The Hostname And The User ID Info (GECOS), Restart The Device And The Settings Will Be Applied Completely.
ADD New RPI Into Jenkins Server Known Hosts
# We use "Known hosts file Verification Strategy" as Availability method,which means the jenkins_agent should be accessed by server at least once.
# Type the following command under Jenkins server
# Switch to jenkins account
$ su jenkins
# Access to jenkins_agent
# ssh [jenkins username]@[RPI IP]
e.g.
$ ssh jenkins_agent@***.***.***.***
# Once you SSH jenkins_agent success, the jenkins_agent will be recorded into known-hosts
MOUNT Samba Share Folder
# The Samba share folder should be mounted when a copied image first launched.
# Head to Robot Framework directory
$ cd [Robot Framework Folder]
e.g.
$ cd /home/rpiauto/RobotFramework
# Execute the mount shell script
# ./Scripts/MountSamba.sh
Samba share mounted at /home/rpiauto/RobotFramework/Samba/JenkinsTestResults
Samba share mounted at /home/rpiauto/RobotFramework/Samba/JenkinsData
# Check the mounted folder works
FAQ
How To Unmount SharePoint
# Unmount the Samba share
# Using the following command:
$ sudo umount /path/to/mount/point
Reference
- How to install Ubuntu Desktop on Raspberry Pi 4
- Backup Raspberry Pi OS
- Show Progress Bar On dd backup
- How to make a disk image with dd on Linux or Unix
- Disable / Turn Off Lock Screen on Ubuntu 22.04
- Understanding /etc/passwd File Format
- Install Tio on Ubuntu
- Installing SAMBA On Linux