Linux Format - UK (2020-03)

(Antfer) #1
36 LXF260 March 2020 http://www.linuxformat.com

Raspberry Pi projects


Booting from SSD


Sidestep those slow SD cards with a speedy external drive,


and share your files with Samba.


resuming that you’ve chosen Raspbian, let’s
get you up and running with a system that
boots from microSD and immediately jumps to
an external SSD for storing and running the bulk of the
OS. Note that for older models (anything but the Pi 4),
USB booting is easier to set up (just add the line
program_usb_bootmode=1 to /boot/config.txt on a
Raspbian SD card, then reboot with said microSD card
and your external drive attached to write the change to
firmware). See http://bit.ly/LXF260boot for info.
One day, booting the Pi 4 from external storage will
be simple, but for now we’ll have to settle for pivoting
to the root filesystem. Start by downloading the latest
fully loaded version of Raspbian Buster from http://
raspberrypi.org/downloads/raspbian. Unzip, then

head to http://balena.io/etcher to get the latest
version of balena Etcher, a super-simple disk imager.
Write the Raspbian image not to your microSD card, but
to that USB drive – you will, it goes without saying, lose
everything that’s on there, so don’t wipe a drive full of
beloved content. Do the same thing again, but write the
image to your SD card this time.
Insert the microSD card into your Pi and plug your
drive into one of its USB 3.0 ports. Wire everything else
up, plug in your peripherals, and power on via the mains
adapter. After the initial options, open a command line
with the icon at the top of the screen and run:
$ sudo fdisk -l
to see a list of your attached drives. The Pi’s default
password is “raspberry”. One drive, your SD card, will
have a name starting mmc, while your USB drive (which
is what we’re looking for) should be sda if no other
storage is attached. If it’s sdb use that. Run:

$ sudo nano /boot/cmdline.txt
to edit the options that are passed to the Pi when
booting from that SD card. At the end of the line add
root=/dev/sda2 rootwait
to tell Raspbian that your main filesystem is on the USB
drive. Exit nano (Ctrl-X, Y, then Return), and run
$ sudo reboot
to start your Pi again, this time, running from the USB
drive. The main tell is that you need to set everything up
again – if you previously connected your Wi-Fi, or run
through the initial setup procedure, all of that is
returned back to the defaults written to your USB drive.
There’s a problem, though: you basically have no
space on that drive, because the partition is written to
be only as large as it needs to be. Run
$ df -h
in the command line and you’ll see the /dev/root/
partition just isn’t big enough. The raspi-config tool
that would normally do this only wants to work with SD
cards, so let’s hack it into compliance: Run
$ sudo cp /usr/bin/raspi-config ~
to copy it to your home directory, then run
$ sudo sed -i ‘s/mmcblk0p/sda/’ ~/raspi-config
$ sudo sed -i ‘s/mmcblk0/sda/’ ~/raspi-config
(which substitutes the SD card partition and block
device references to mass storage ones), and then run
the version in your home directory with
$ sudo ~/raspi-config
Head to option 7, then select Expand Filesystem. Restart
with sudo reboot and then try df -h again – you should
see a marked difference in available space. When
booting your Pi in the future, make sure you use the
same SD card and keep the USB drive in the same
physical port to avoid any problems with device
identifiers changing. Now you’re free to start filling that
drive with software and get working.

NAS-ty business
There’s been some realignment in the Pi’s hardware,
and one of its biggest stumbling blocks is now gone: the
USB and Ethernet ports no longer share the same bus.
The Pi 3’s gigabit Ethernet, tied to a USB 2.0 bridge,
could only reach 300Mb/s. This new version runs at
true gigabit speeds. The flipside of the coin is that there
are also now two ports of glorious USB 3.0 to work with


  • we took advantage of one with the SSD boot process,
    but we can also use these ports in conjunction with that
    higher network throughput to use the Pi as a rather
    competent network-attached storage device.
    Optional, but recommended if you’re planning to roll
    this out as a serious storage solution, is a powered USB
    hub to ensure your drives never drains the Pi of too
    much precious energy when worked hard. Truthfully,
    you probably don’t need it, but something like TP-Link’s


P


stoage s attac ed t ssdbuse t at u U
Th
co
tr
ar


  • bu
    hi
    co


th
hu
m
yo

A fast
external SSD
will make
whatever
distro you
choose to run
a lot snappier.

IMPROVING HARDWARE


“The USB and Ethernet ports


no longer share the same bus”


36 LXF260 March 2020 http://www.linuxformat.com

Raspberry Pi projects


Booting from SSD


Sidestep those slow SD cards with a speedy external drive,


and share your files with Samba.


resuming that you’ve chosen Raspbian, let’s
get you up and running with a system that
boots from microSD and immediately jumps to
anexternal SSD for storing and running the bulk of the
OS. Note that for older models (anything but the Pi 4),
USB booting is easier to set up (just add the line
program_usb_bootmode=1 to /boot/config.txt on a
Raspbian SD card, then reboot with said microSD card
and your external drive attached to write the change to
firmware). See http://bit.ly/LXF260boot for info.
One day, booting the Pi 4 from external storage will
be simple, but for now we’ll have to settle for pivoting
to the root filesystem. Start by downloading the latest
fully loaded version of Raspbian Buster from http://
raspberrypi.org/downloads/raspbian. Unzip,then

headtohttp://balena.io/etchertogetthelatest
version of balena Etcher, a super-simple disk imager.
Write the Raspbian image not to your microSD card, but
to that USB drive – you will, it goes without saying, lose
everything that’s on there, so don’t wipe a drive full of
beloved content. Do the same thing again, but write the
image to your SD card this time.
Insert the microSD card into your Pi and plug your
drive into one of its USB 3.0 ports. Wire everything else
up, plug in your peripherals, and power on via the mains
adapter. After the initial options, open a command line
with the icon at the top of the screen and run:
$ sudo fdisk -l
to see a list of your attached drives. The Pi’s default
password is “raspberry”. One drive, your SD card, will
havea namestartingmmc, whileyourUSBdrive (which
iswhatwe’relookingfor)shouldbesdaif noother
storageisattached.If it’ssdbusethat.Run:

$ sudo nano /boot/cmdline.txt
to edit the options that are passed to the Pi when
booting from that SD card. At the end of the line add
root=/dev/sda2 rootwait
to tell Raspbian that your main filesystem is on the USB
drive. Exit nano (Ctrl-X, Y, then Return), and run
$ sudo reboot
to start your Pi again, this time, running from the USB
drive. The main tell is that you need to set everything up
again – if you previously connected your Wi-Fi, or run
through the initial setup procedure, all of that is
returned back to the defaults written to your USB drive.
There’s a problem, though: you basically have no
space on that drive, because the partition is written to
be only as large as it needs to be. Run
$ df -h
in the command line and you’ll see the /dev/root/
partition just isn’t big enough. The raspi-config tool
that would normally do this only wants to work with SD
cards, so let’s hack it into compliance: Run
$ sudo cp /usr/bin/raspi-config ~
to copy it to your home directory, then run
$ sudo sed -i ‘s/mmcblk0p/sda/’ ~/raspi-config
$ sudo sed -i ‘s/mmcblk0/sda/’ ~/raspi-config
(which substitutes the SD card partition and block
device references to mass storage ones), and then run
the version in your home directory with
$ sudo ~/raspi-config
Head to option 7, then select Expand Filesystem. Restart
with sudo reboot and then try df -h again – you should
see a marked difference in available space. When
booting your Pi in the future, make sure you use the
same SD card and keep the USB drive in the same
physical port to avoid any problems with device
identifiers changing. Now you’re free to start filling that
drive with software and get working.

NAS-ty business
There’s been some realignment in the Pi’s hardware,
andone of its biggest stumbling blocks is now gone: the
USBand Ethernet ports no longer share the same bus.
hePi 3’s gigabit Ethernet, tied to a USB 2.0 bridge,
ouldonly reach 300Mb/s. This new version runs at
uegigabit speeds. The flipside of the coin is that there
realso now two ports of glorious USB 3.0 to work with
wetook advantage of one with the SSD boot process,
utwe can also use these ports in conjunction with that
gher network throughput to use the Pi as a rather
ompetent network-attached storage device.
Optional, but recommended if you’re planning to roll
hisout as a serious storage solution, is a powered USB
ubto ensure your drives never drains the Pi of too
muchprecious energy when worked hard. Truthfully,
ouprobably don’t need it, but something like TP-Link’s

P


ge s attac ed use t at u
Th
co
tr
ar


  • bu
    hi
    co


th
hu
m
yo

A fast
external SSD
will make
whatever
distro you
choose to run
a lot snappier.

IMPROVING HARDWARE


“The USB and Ethernet ports


no longer share the same bus”

Free download pdf