In case this is of use to anyone else, and for my reference in future, here are the steps I took to set up the WD PiDrive on Raspbian. Your choices may differ. Feel free to comment if there are areas where you think a different setup would be better.
I should say that I have put this together from looking back in the command history. The steps I took were not at all as well organised as the simple list below may suggest! I had some problems in particular with getting the drive to spin down after a period of non-use.
As I understand that swapping to flash memory is likely to increase its wear I decided that the hard disk would be an ideal place to add swap space of higher priority than the default. I chose to use a swap file rather than a partition.
First steps:
sudo fdisk -l (find disk id, mine was sda) sudo smartctl -d sat /dev/sda -HA (basic check) sudo badblocks /dev/sda 2000 -v (scan low blocks) sudo fdisk /dev/sda (partition the disk)
With fdisk I put all space in one partition, sda1.
Next:
sudo mke2fs /dev/sda1 -c -t ext4 (check, make a file system) sudo tune2fs /dev/sda1 -L wd0 (label the file system wd0) sudo mkdir /mnt/wd0 (make a mount point) sudo mount /dev/disk/by-label/wd0 /mnt/wd0 (mount the partition)
I chose, next, to make a swap file while the volume was in a virgin state. That should reduce the chances of the swap file requiring multiple extents, though it still required 9 extents for some reason (as found in /var/log/dmesg).
sudo dd bs=1K count=1M if=/dev/zero of=/mnt/wd0/.swap0 (make a swap file) sudo chmod 600 /mnt/wd0/.swap0 (protect the swap file) sudo mkswap -c /mnt/wd0/.swap0 (format the swap file) sudo vi /etc/fstab (add to fstab)
The following lines were added to fstab. The first is for the new volume. The second is for the new swap file (with priority 1).
LABEL=wd0 /mnt/wd0 ext4 defaults 0 2 /mnt/wd0/.swap0 none swap defaults,pri=1 0 0
The drive did not seem to spin down by itself. After some research and tests I seemed to get spindown to work (but cannot be certain this is reliable) and added the necessary commands to /etc/rc.local as follows.
sudo vi /etc/rc.local (to add lines to allow spindown)
The lines added were as follows (where -S 180 means 15 minutes).
hdparm -B 127 /dev/sd[a-z] 2>&1 | logger hdparm -S 180 /dev/sd[a-z] 2>&1 | logger
Finally, reboot to test that all the necessary commands and mounts are effected on boot.
sudo shutdown -r 1 (test reboot) df -h (check partition has been mounted) swapon -s (check swap file is active)
As I say, that list was reconstructed but I do think it's a good list of steps. Feel free to challenge any choices made or add other recommendations.
James