Western Digital USB PiDrive kit setup

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

Reply to
James Harris
Loading thread data ...

Cheers for documenting your steps. Placing the swap as a file rather than a partition made me stop and think and do some research as I've always set up swap as a separate partition. Even old dogs can learn something new!

Most of my Linux installs have been from Live CD or an installer and the default answers regarding partitioning have always worked. I can't recall ever being offered the option to put swap as a file. This is on assorted x86/AMD64/PPC machines. Even my many cloud based virtual servers were typically setup by the hosting provider. I've checked and they are using partitions, moot as the partitions are virtualised on to some disk elsewhere.

I don't run my Pi with swap, it's not GP computer but a turnkey device that is used for one IO job so swap isn't needed. Likewise I have an old eeePC running Lubuntu that runs without swap (It has 2GB of Ram and a 4G SSD, swap would use up 50% of the disk). But the knowledge you can add swap as a file is good to know.

Reply to
mm0fmf

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.