0%

Starter Guide: Get NextCloud Running on Raspberry Pi 4 Model B

Hello Ubuntu Server

Write the Image

Use Raspberry Pi Imager to install Ubuntu Server 20.04.2 LTS (64-bit) to a microSD card.
Raspberry Pi Imager
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.
network-config
Uncomment line 15-21, and change line 20-21 to your Wi-Fi info.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#
# Some additional examples are commented out below

version: 2
ethernets:
eth0:
dhcp4: true
optional: true
#wifis:
# wlan0:
# dhcp4: true
# optional: true
# access-points:
# myhomewifi:
# password: "S3kr1t"
# myworkwifi:
# password: "correct battery horse staple"
# workssid:
# auth:
# key-management: eap
# method: peap
# identity: "me@example.com"
# password: "passw0rd"
# ca-certificate: /etc/my_ca.pem

Set Static IP

Replace dhcp4: true line with the following:

1
2
3
4
5
6
7
8
ethernets:
eth0:
addresses:
- 192.168.101.23/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
optional: true

Setup SSH

You should not need to do anything for SSH.
If you open user-data

1
2
3
4
5
6
7
8
9
10
11
12
13
...

# On first boot, set the (default) ubuntu user's password to "ubuntu" and
# expire user passwords
chpasswd:
expire: true
list:
- ubuntu:ubuntu

# Enable password authentication with the SSH daemon
ssh_pwauth: true

...

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
2
$ sudo apt-get update
$ sudo apt-get upgrade

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
2
3
4
5
NAME         SIZE FSTYPE   TYPE MOUNTPOINT
sda 4.5T disk
└─sda1 4.5T ext4 part
sdb 4.5T disk
└─sdb1 4.5T ext4 part

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
2
Selected partition 1
Partition 1 has been deleted.

Reload the partition table to verify that the partition has been deleted. To do so, run the p command.

1
2
3
4
5
6
7
Disk /dev/sda: 4.55 TiB, 5000981077504 bytes, 9767541167 sectors
Disk model: BUP Portable
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0A457385-D922-4012-861A-51F6677BA9EF

Run the w command to write and save changes made to the disk.

1
2
3
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

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
2
3
NAME         SIZE FSTYPE   TYPE MOUNTPOINT
sda 4.5T disk
sdb 4.5T disk

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
2
3
4
5
6
7
8
9
10
11
12
13
14
mdadm: partition table exists on /dev/sda
mdadm: partition table exists on /dev/sda but will be lost or
meaningless after creating array
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
mdadm: partition table exists on /dev/sdb
mdadm: partition table exists on /dev/sdb but will be lost or
meaningless after creating array
mdadm: size set to 4883638464K
mdadm: automatically enabling write-intent bitmap on large array
Continue creating array? y

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
2
3
4
5
6
7
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdb[1] sda[0]
4883638464 blocks super 1.2 [2/2] [UU]
[===>.................] resync = 16.4% (803331264/4883638464) finish=708.5min speed=95974K/sec
bitmap: 33/37 pages [132KB], 65536KB chunk

unused devices: <none>

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
2
Filesystem      Size  Used Avail Use% Mounted on
/dev/md0 4.6T 89M 4.3T 1% /mnt/md0

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.

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>

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
2
$ mkdir plex && cd plex
$ touch docker-compose.yml

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
---
version: "2.1"
services:
plex:
image: ghcr.io/linuxserver/plex:arm64v8-latest
container_name: plex
network_mode: host
environment:
- PUID=1001
- PGID=100
- VERSION=docker
- PLEX_CLAIM= #optional
volumes:
- /root/docker/plex/config:/config
- /mnt/md0/nextcloud/nextcloud/data/username/files/Media/Movies:/movies
- /mnt/md0/nextcloud/nextcloud/data/username/files/Media/TV Series:/tv
- /mnt/md0/nextcloud/nextcloud/data/username/files/Media/Animate:/animate
- /mnt/md0/nextcloud/nextcloud/data/username/files/Media/Music:/music
restart: unless-stopped

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