Hello Ubuntu Server
Write the Image
Use Raspberry Pi Imager to install Ubuntu Server 20.04.2 LTS (64-bit) to a microSD card.
Click on “Write” and wait until it’s done. This can take a few minutes. Once done, depending on the options you’ve chosen, the card may be ejected.
Setup Wi-Fi
Navigate inside the root folder of the card. The name should be something like system-boot
.
Find the file named network-config
and open it in a text editor.
Uncomment line 15-21, and change line 20-21 to your Wi-Fi info.
1 | # This file contains a netplan-compatible configuration which cloud-init |
Set Static IP
Replace dhcp4: true
line with the following:
1 | ethernets: |
Setup SSH
You should not need to do anything for SSH.
If you open user-data
1 | ... |
So, we’ll be able to connect to the Pi via SSH, and we have the initial username and password: ubuntu:ubuntu.
SSH in to PI
There are seveal ways to look for your new device’s IP, I won’t go into details.
On Windows, you can use Advanced IP Scanner.
I got my IP for the PI from my router (look for a device called ubuntu).
Now that you’ve obtained the IP, SSH in!
1 | $ ssh ubuntu@192.168.1.2 |
Password should be ubuntu
the first time you login.
Setup Ubuntu
First Things First - Update
1 | $ sudo apt-get update |
Set your time zone
Check the time
1 | $ date |
The default time zone will be UTC0.
List all available time zones.
1 | $ timedatectl list-timezones |
Run the following command to set the time zone
1 | $ timedatectl set-timezone your_time_zone |
For example
1 | $ timedatectl set-timezone Europe/Paris. |
NO-IP (Optional)
https://www.noip.com/support/knowledgebase/installing-the-linux-dynamic-update-client-on-ubuntu/
RAID 1 (Optional)
You can skip this setp if you are not planning to use RAID 1.
Learn about RAID in this article (An Introduction to RAID Terminology and Concepts) from DigitalOcean.
Delete Existing Partitions
Find the identifiers for the raw disks that you will be using:
1 | $ lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT |
Output
1 | NAME SIZE FSTYPE TYPE MOUNTPOINT |
sda and sdb are what I’ll be using, and I want to get rid of the partitions.
Let’s delete it:
1 | $ sudo fdisk /dev/sda |
To delete partition, run the d
command in the fdisk command-line utility.
1 | Selected partition 1 |
Reload the partition table to verify that the partition has been deleted. To do so, run the p
command.
1 | Disk /dev/sda: 4.55 TiB, 5000981077504 bytes, 9767541167 sectors |
Run the w
command to write and save changes made to the disk.
1 | The partition table has been altered. |
Repeat the above steps for other drives, for me, it’s sdb
Check the partitions are gone:
1 | $ lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT |
Output
1 | NAME SIZE FSTYPE TYPE MOUNTPOINT |
Creating a RAID 1 Array
Create the Array
1 | sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda /dev/sdb |
If the component devices you are using are not partitions with the boot flag enabled, you will likely be given the following warning. It is safe to type y
to continue:
1 | mdadm: partition table exists on /dev/sda |
The mdadm tool will start to mirror the drives. This can take some time to complete, but the array can be used during this time. You can monitor the progress of the mirroring by checking the /proc/mdstat file:
1 | cat /proc/mdstat |
Output
1 | Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] |
In the meanwhile, we can go ahead to create and mount the filesystem.
Create and Mount the Filesystem
Next, create a filesystem on the array:
1 | $ sudo mkfs.ext4 -F /dev/md0 |
Create a mount point to attach the new filesystem:
1 | $ sudo mkdir -p /mnt/md0 |
You can mount the filesystem by typing:
1 | $ sudo mount /dev/md0 /mnt/md0 |
Check whether the new space is available by typing:
1 | $ df -h -x devtmpfs -x tmpfs |
Output
1 | Filesystem Size Used Avail Use% Mounted on |
The new filesystem is mounted and accessible.
Save the Array Layout
1 | $ sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf |
You can update the initramfs, or initial RAM file system, so that the array will be available during the early boot process:
1 | $ sudo update-initramfs -u |
Add the new filesystem mount options to the /etc/fstab file for automatic mounting at boot:
1 | $ echo '/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab |
RAID 1 array should now automatically be assembled and mounted each boot.
Reference
https://www.digitalocean.com/community/tutorials/how-to-create-raid-arrays-with-mdadm-on-ubuntu-16-04
https://phoenixnap.com/kb/delete-partition-linux
https://unix.stackexchange.com/questions/411206/how-to-wipe-md-raid-meta
NextCloud
1 | $ cd /mnt/md0 |
1 | $ mkdir nextcloud |
Replace $DOMAIN
with your IP/Domain
1 | $ docker run -d -p 4443:4443 -p 443:443 -p 80:80 -v /mnt/md0/nextcloud:/data --name nextcloudpi ownyourbits/nextcloudpi $DOMAIN |
Get the container ID
1 | $ docker ps |
1 | $ docker update --restart unless-stopped <container-id> |
Reference
https://ownyourbits.com/nextcloudpi/
PLEX (Optional)
If you want to have a media server for streaming and to organize video, audio, and photos, here’s how:
Create a folder
1 | $ mkdir plex && cd plex |
Use your preferred text editor to open docker-compose.yml
, copy and paste the following, make sure to change volumes according to your folder structure.
1 | --- |
To get it running:
1 | $ docker-compose up -d |
If you need to update:
1 | $ docker-compose pull and then docker-compose down && docker-compose up -d |