Data disk

For continuous recording, or for storing captured natural radio events, or for SID monitoring, you are going to need some extra storage attached to the Pi.

There are three options for storage: the micro-SD card that holds the Pi's root filesystem, USB memory stick, and external USB hard disk drive. It is not a good idea to continually churn volumes of data through an SD-card based root filesystem, it will wear out and start showing errors within a short period, perhaps less than a few months. The USB hard disk is the best option for large volumes and reliability but requires an amp or so at 12V which in remote installations may not be available. The USB memory stick is better suited to remote operation.

In these notes I'll assume you're going to use a USB hard disk or flash memory stick directly connected to the Pi without an intervening USB hub. The USB hard disk must have its own power supply and not be powered from the Pi's USB port.

File system

Since the disk is going to permanently attached to the Pi and not used to transfer files between the Pi and a Windows PC, it can be formatted with a better filesystem than the DOS/Windows compatible filesystem it probably comes with.

Most Linux systems these days use the ext4 filesystem which is a good choice for general use. However for a USB flash drive, the ext4 journaling will significantly increase the number of write cycles that the flash memory has to bear. Therefore I recommending formating with ext2 instead. I tend to use ext2 on hard disks too that are used for streaming large volumes of data.

Device detection

When you plug a disk into a Linux operating system, there are three ways to identify it: By its volume label, by its UUID, or by its physical device path - essentially which bus address or socket it is plugged in to. We will use the device path. You can list the device paths of the Pi's disk with the command

ls -l /dev/disk/by-path

which will produce a listing like

lrwxrwxrwx 1 root root 13 Feb 13 19:40 platform-3f202000.sdhost -> ../../mmcblk0
lrwxrwxrwx 1 root root 15 Feb 13 19:40 platform-3f202000.sdhost-part1 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 15 Feb 13 19:40 platform-3f202000.sdhost-part2 -> ../../mmcblk0p2

These three entries refer to the SD card which is the only disk you have installed at the moment. The first entry is the whole disk and the other two refer to the two logical partitions that the SD card has.

Now plug a USB memory stick or external hard disk into a USB socket on the Pi and repeat the above command. The result will be something like

lrwxrwxrwx 1 root root 13 Feb 13 19:40 platform-3f202000.sdhost -> ../../mmcblk0
lrwxrwxrwx 1 root root 15 Feb 13 19:40 platform-3f202000.sdhost-part1 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 15 Feb 13 19:40 platform-3f202000.sdhost-part2 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root  9 Feb 14 18:56 platform-3f980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Feb 14 18:56 platform-3f980000.usb-usb-0:1.4:1.0-scsi-0:0:0:0-part1 -> ../../sda1

We have two new devices now, one is the whole USB disk, the other is the first (and in this case the only) logical partition.

Now remove the disk and plug it into a different USB socket on the Pi, then run the listing again:

lrwxrwxrwx 1 root root 13 Feb 13 19:40 platform-3f202000.sdhost -> ../../mmcblk0
lrwxrwxrwx 1 root root 15 Feb 13 19:40 platform-3f202000.sdhost-part1 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 15 Feb 13 19:40 platform-3f202000.sdhost-part2 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root  9 Feb 14 18:58 platform-3f980000.usb-usb-0:1.5:1.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Feb 14 18:58 platform-3f980000.usb-usb-0:1.5:1.0-scsi-0:0:0:0-part1 -> ../../sda1

Note the change of device path, from usb-usb-0:1.4:1.0 to usb-usb-0:1.5:1.0. This demonstrates that the path refers to a particular socket on the Pi. You'll see the path change again if you connect the disk through an external hub, or even a chain of hubs. Each hub and port in the chain appears in the device path - which is why it's called the device path. This is very useful on larger systems where you may have hundreds of disk drives attached.

You must now decide which USB socket your data disk will be permanently installed in. We will set things up so that the Pi will always use the disk plugged into that particular socket for radio recording.

Formatting

It is now necessary to format your data disk to give it an empty ext2 filesystem on its first partition. Use the following formatting command, substituting your chosen device path to the first partition, and use copy and paste.

mkfs -t ext2 /dev/disk/by-path/platform-3f980000.usb-usb-0:1.5:1.0-scsi-0:0:0:0-part1

It will take a few minutes to run, depending on the size of the disk. A large hard disk may take over an hour to format on the Pi.

Unix/Linux doesn't use drive letters like DOS and Windows do. Instead, all the disks on a system appear combined together into a tree-structured filesystem. The initial disk that the system booted from provides the root of the tree and all the other disks are grafted on at 'mount points' which can be placed anywhere you like in the tree. A mount point is just an empty directory. We'll create a mount point called, say, /d for the data disk:

mkdir /d

which creates an empty directory. It is quite common to use single letter names or short names for mounting data disks. On a large system you might find dozens, with mount points like /u, /v, /r1, /r2, /r3, and so on. We'll use /d for data.

Now mount your newly created empty ext2 partition with a command like

mount -o rw,noatime /dev/disk/by-path/platform-3f980000.usb-usb-0:1.5:1.0-scsi-0:0:0:0-part1 /d

Now, whenever you store anything in a file under /d, it will store to your data disk. Check the space with:

df /d

which comes back with something like

Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/sda1       29824988 44996  28264936   1% /d

Linux has given the data disk partition a short name, /dev/sda1, which we can use as an alias for the full by-path name. This example is a 32 Gbyte flash memory stick. It shows a small amount used - this is the overhead of the filesystem itself. We actually have about 28 Gbytes to work with.

Just one thing remains to do now. We don't want to have to manually repeat that mount command every time the Pi boots. Instead we'll add an entry into the operating system's list of disks to mount at boot time. Edit the file /etc/fstab and add the following entry at the end, substituting your chosen device path:

/dev/disk/by-path/platform-3f980000.usb-usb-0:1.5:1.0-scsi-0:0:0:0-part1 /d ext2 rw,noatime,auto,nofail 0 2

The noatime option is important for a flash memory device to minimise the number of write operations. auto means to automatically mount at boot time, nofail means don't hold up the boot if for any reason it doesn't mount.

Save the file and reboot the Pi with a shutdown -r now command and it should boot up with the data disk mounted on /d


Back to Monitor Up to Index   Next to Record