Linux Format - UK (2020-03)

(Antfer) #1
http://www.techradar.com/pro/linux March 2020 LXF260 37

Raspberry Pi projects


UH720 (£30) offers up more ports (seven to be precise)
as well as adding power, meaning you can expand your
central storage as additional drives become available.
You don’t need the all-inclusive Raspbian distribution
for this – the Lite version will do‚ and you won’t need to
keep it hooked up to a monitor or any peripherals, as
we’ll be able to control it remotely. For the sake of ease
of setup, though, we suggest you hook everything up at
least until the NAS is up and running.
Let’s tick off some prerequisites. Write Raspbian
Buster Lite to your card, boot it up in your Pi, then run
$ sudo raspi-config
from the shell. In Interfacing Options, switch on SSH so
that you’ll be able to access the shell later on, set up
your Wi-Fi if you’re going to use that, change your
password (because leaving the default password on a
device you’re going to leave open on the network would
be a wildly foolish move), then head to the Network
Options page. We recommend changing the host name
to something like “nas” so that it’s easily found later.
The simplest way to proceed is to take advantage of
Samba, Linux’s server message block (SMB) network-
sharing tool, which will give us a simple storage area
that shows up as a network drive in Windows. You can
skip this section if you want to share files from the OS
drive we set up earlier.
First, get your drive (or drives – repeat the following
as necessary) ready. Connect your storage device to the
Pi, and Raspbian should find it automatically; run
$ lsblk
to see its drive designation – in our case, /dev/sdb.
You need to initialise the drive and give it a partition
Raspbian can work with; fdisk is our friend here. Run
$ sudo fdisk /dev/sdb
hit N when prompted to create a new partition, and if
you’re told one already exists, hit D to delete it, then N
again to create a fresh one. You’ll want a primary
partition (P), then hit Return until you get back to the
base command prompt. Hit W to write the changes, and
your disk is initialised – repeat this for any other drives.
Format the drive, create a mount point and mount it:
$ sudo mkfs.ext4 /dev/sdb
$ sudo mkdir /mnt/sdb
$ sudo mount /dev/sdb /mnt/sdb

It’s important if we’re setting up network storage that
this drive gets mounted to the same point every time, so
let’s set it to happen at boot by running sudo nano /etc/
fstab to edit the static filesystem table. Insert the
following on a new line, separating each entry with a tab:
/dev/sdb /mnt/sdb ext4 defaults 0 0
Exit Nano, and it’s time to set up Samba – a mercifully
simpler procedure. Install it with sudo apt-get install
samba samba-common-bin, then run
sudo nano /etc/samba/smb.conf
to edit its configuration file. At the bottom of the file, add
the following to define the parameters of your share:
[storage]
path = /mnt/sdb
writeable=Yes
create mask=0777
directory mask=0777
public=no
Of course, all of this assumes you want to use a
whole drive for network storage – you can just as easily
use a folder on an existing drive. Simply make one in
your home directory with mkdir ~/share , and switch it
out for the drive’s mount point in the above instructions.
Now we can set up our Samba user – it’s a better
idea to do this than setting public=yes in the above for
the security of your files. Run
sudo smbpasswd -a lxf
to create a user, “lxf”, and choose a password. Restart
Samba with sudo systemctl restart smbd – connecting
to NAS should be as easy as mapping a network drive in
Windows and pointing it at \\nas\storage.

MicroSD cards are
nice and all, but
they’re really a
terrible medium
from which to
run an OS.

The Pi
OpenMediaVault
image is still
based on the
beta version, but
in future this will
turn your Pi into
a serious
NAS device.

3332March 0 h2rSenshSnigtom March 2020LXF260 37


Raspberry Pi projects


UH720 (£30) offers up more ports (seven to be precise)
as well as adding power, meaning you can expand your
central storage as additional drives become available.
You don’t need the all-inclusive Raspbian distribution
for this – the Lite version will do‚ and you won’t need to
keep it hooked up to a monitor or any peripherals, as
we’ll be able to control it remotely. For the sake of ease
of setup, though, we suggest you hook everything up at
least until the NAS is up and running.
Let’s tick off some prerequisites. Write Raspbian
Buster Lite to your card, boot it up in your Pi, then run
$ sudo raspi-config
from the shell. In Interfacing Options, switch on SSH so
that you’ll be able to access the shell later on, set up
your Wi-Fi if you’re going to use that, change your
password (because leaving the default password on a
device you’re going to leave open on the network would
be a wildly foolish move), then head to the Network
Options page. We recommend changing the host name
to something like “nas” so that it’s easily found later.
The simplest way to proceed is to take advantage of
Samba, Linux’s server message block (SMB) network-
sharing tool, which will give us a simple storage area
that shows up as a network drive in Windows. You can
skip this section if you want to share files from the OS
drive we set up earlier.
First, get your drive (or drives – repeat the following
as necessary) ready. Connect your storage device to the
Pi,andRaspbianshouldfinditautomatically;run
$ lsblk
toseeitsdrivedesignation–inourcase, /dev/sdb.
You need to initialise the drive and give it a partition
Raspbian can work with; fdisk is our friend here. Run
$ sudo fdisk /dev/sdb
hit N when prompted to create a new partition, and if
you’re told one already exists, hit D to delete it, then N
again to create a fresh one. You’ll want a primary
partition (P), then hit Return until you get back to the
base command prompt. Hit W to write the changes, and
your disk is initialised – repeat this for any other drives.
Format the drive, create a mount point and mount it:
$ sudo mkfs.ext4 /dev/sdb
$ sudo mkdir /mnt/sdb
$ sudo mount /dev/sdb /mnt/sdb


It’s important if we’re setting up network storage that
this drive gets mounted to the same point every time, so
let’s set it to happen at boot by running sudo nano /etc/
fstab to edit the static filesystem table. Insert the
following on a new line, separating each entry with a tab:
/dev/sdb /mnt/sdb ext4 defaults 0 0
Exit Nano, and it’s time to set up Samba – a mercifully
simpler procedure. Install it with sudo apt-get install
samba samba-common-bin, then run
sudo nano /etc/samba/smb.conf
to edit its configuration file. At the bottom of the file, add
the following to define the parameters of your share:
[storage]
path = /mnt/sdb
writeable=Yes
create mask=0777
directory mask=0777
public=no
Of course, all of this assumes you want to use a
whole drive for network storage – you can just as easily
use a folder on an existing drive. Simply make one in
your home directory with mkdir ~/share , and switch it
out for the drive’s mount point in the above instructions.
Now we can set up our Samba user – it’s a better
idea to do this than setting public=yes in the above for
the security of your files. Run
sudo smbpasswd -a lxf
to create a user, “lxf”, and choose a password. Restart
Samba with sudo systemctl restart smbd – connecting
to NAS should be as easy as mapping a network drive in
Windows and pointing it at \\nas\storage.

MicroSD cards are
nice and all, but
they’re really a
terrible medium
from which to
run an OS.

The Pi
OpenMediaVault
image is still
based on the
beta version, but
in future this will
turn your Pi into
a serious
NAS device.
Free download pdf