To attach external HDD to your Raspberry Pi3, we assume you already installed nextcloud server on your Pi.

The Raspberry Pi 3 selling here pre-loaded nextcloud server with username: pi-store, password: pi-store

Partition and format the external hard disk

!!! You can do this on Raspberry Pi3 or different linux machine !!!

This will create a single partition formatted with the ext4 filesystem.

Find the disk label

sudo lsblk

Sample print:

NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                           8:0    0 931.5G  0 disk 
├─sda1                        8:1    0   512M  0 part /boot/efi
├─sda2                        8:2    0   244M  0 part /boot
└─sda3                        8:3    0 930.8G  0 part 
  ├─node1--vg-root (dm-0)   252:0    0 882.8G  0 lvm  /
  └─node1--vg-swap_1 (dm-1) 252:1    0    48G  0 lvm  [SWAP]
sr0                          11:0    1  1024M  0 rom  
sr1                          11:1    1  1024M  0 rom  

Start partition: sda as /dev/sda (Please very careful find the disk you want to format)

sudo fdisk /dev/sda

Do the following to create the partition:

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x253fea38.

Command (m for help): n
Partition type
    p   primary (0 primary, 0 extended, 4 free)
    e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-1953458175, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-1953458175, default 1953458175):

Created a new partition 1 of type 'Linux' and of size 931.5 GiB.

Command (m for help): w

Now format the partition and give it the label data. This label will be used to reference it for mounting later, please select different label name if label: data already been used:

sudo mkfs.ext4 -L data /dev/sda1

Automatically mount the partition

Most of the Ubuntu Core root file system is read-only, so it is not possible to edit /etc/fstab. Therefore we’ll use systemd to achieve that.

Be aware of one of the systemd.mount pitfalls:

Mount units must be named after the mount point directories they control. Example: the mount point /home/lennart must be configured in a unit file home-lennart.mount.

Yes that’s right! The unit filename must match the mount point path.

Create the media-data.mount unit:

sudo vi /writable/system-data/etc/systemd/system/media-data.mount

Add the following content:

[Unit]
Description=Mount unit for data

[Mount]
What=/dev/disk/by-label/data
or by UUID (command: sudo blkid -o full -s UUID to get UUID)
What=/dev/disk/by-uuid/[uuid]
Where=/media/data
Type=ext4

[Install]
WantedBy=multi-user.target

Reload systemd, scanning for new or changed units:

sudo systemctl daemon-reload

Start the media-data.mount unit, which will mount the volume, and also enable it so it will be automatically mounted on boot.

sudo systemctl start media-data.mount
sudo systemctl enable media-data.mount

And just like any other unit, you can view its status using systemctl status:

sudo systemctl status media-data.mount

Update Ubuntu Core

Make sure Ubuntu Core is up-to-date and reboot.

sudo snap refresh
sudo reboot

After the reboot, make sure /media/data is mounted. If not double check the steps above.

Attach external HDD to Nextcloud

Login to your nextcloud server with http://nextcloud.local, click on admin->admin on right-up corner, then select external storage menu.

Or

Directly access url: http://nextcloud.local/index.php/settings/admin/externalstorages

Folder name can be any name you want as long as it's not existing, configuration field must match Where field in configuration file, it's /media/data here.

After the green dot shows up, wait for few second, you will see data folder attached to nextcloud server file system.

Enjoy hacking !!!

Any questions, please don't hesitate to send email to: ebiz@chen.me, we will response within 24 hours