An Old Hard Drive and RASPBERRY PI

So you have an old laptop and its days have come to an end but some of the parts in it are still working, most importantly, its hard drive. You have an idea to use this as a portable hard drive since it is small in size and fits easily into your bag or pocket. So what do you do ?

If you want to just use it as a portable drive, the procedure is pretty straightforward. Just go down to your nearest IT shop and spend around 10–15 bucks to buy a SATA 2.5" to USB2.0 converter. Chances are that you will get a plastic casing to fit in your hard drive along with the converter which is pretty neat.

SATA 2.5" to USB2.0 converter (SGD 13 in Singapore)
Using the Drive to expand your Raspberry Pi Storage Capacity

Nah, just using it as a portable drive is too boring for you and you want to be able to use it to add extra storage to your Pi. Here you go-

You will need your:

1. USB Power Adapter that can produce 2.0A of current as 1.0A is not enough to power the Hard Drive

2. Raspberry Pi running Raspbian or some other distro

3. SATA 2.5" to USB2.0 converter connected to your hard

Now, hook up your hard drive to your Raspberry Pi and power it on.

I assume from this point onward that your drive is formatted using NTFS partitioning.

When Linux detects the USB drive, it will create a file in /dev that is used as an interface to your disk. You can list all the disk device files in /dev by typing this command:

$ sudo fdisk -l

For my case, it was listed under /dev/sda1.

You will need to install NTFS driver at this point using this command.

$ sudo apt-get install ntfs-3g

To access the drive, you need to mount it first. First you need to create a folder under /media (you may use other folders as well but it is easier to use /media):

$ sudo mkdir /media/usbhdd

Now change the owner of that directory to your own user name. For my case, it is pi:

$ sudo chown pi:pi /media/usbhdd

To mount the drive, use this command:

$ sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/usbhdd

The part ‘-t ntfs-3g’ means your drive has an ntfs file system. The ‘-o uid=pi,gid=pi’ part of the command means that the disk will be owned by user pi. You could also use this command to unmount the disk:

$ sudo umount /media/usbhdd

You need to edit the file system table so that the disk is mounted every time your Pi boots up:

$ sudo nano /etc/fstab

Add the 5th line as shown (take note of the spacing):

/dev/sda1 /media/usbhdd ntfs-3g uid=pi,gid=pi,dmask=027 0 0

Now you can save this and reboot your Pi to access the drive under /media/usbhdd

An Explanation on fstab folder access permission

The fstab has got 6 columns:

[device name] [mount point] [file system type] [options] [dump] [bootcheck priority]
Device name:
This is the UNIX filename representing the physical device or partition. Typically, this name starts with /dev.
Mount point:
Directory on your root file system (aka mount point) from which it will be possible to access the content of the device/partition. In simple words, the location where you mounted the drive
File system type:
This field represents the filesystem to be used when mounting the device or partition. Typical values for this field are ext2, ext3, reiserfs, vfat, iso9660, and udf. auto can be used if multiple filesystems can be used on removable devices such as card readers, CD-ROMs, and DVD-ROMs.
These are options given to the mount, umount and eject commands. A value of defaults means to use the default options for the filesystem being used.
users (uid) means that any user can mount the device.
owner means that only the owner of the device can mount and unmount the device.

Usually this is the administrator. rw means to mount the device for read and write access. ro means the device is mounted for read-only access. There are quite a few other options that can be placed in this field.
This is usually set to zero for removable devices.
Boot Check Priority(Pass):
When set to zero, this tells Linux not to do a filesystem integrity check on this device at boot time. The boot should have value 1, if set to 2 will be checked after the boot. Enabling this option for removable devices is not recommended.
- Credits to:

So the column in options are set as uid=pi, gid=pi, dmask=027 for our case. This means that the device could be accessed by user pi and members of group pi. As for the access permission, this works a bit differently from the octal values that we used for chmod.

umask sets the same access permission for both files and folders.
dmask sets the access permission for directories.
fmask sets the access permission for files.

Take note of the lines mentioned above.

Now look at this figure:

Access Values

In our case, we set dmask to be 027. This means that any directory created within usbhdd will have rwxr-x — —. This means that the directory’s owner will have r,w,x permission. The group member would have read and execute permission. Others would have no permission to access the folder in anyway.

The same applies to files created or copied into usbhdd if set with fmask perimeter.

I hope you enjoyed it and are now able to use your hard drive as a storage expansion with Pi.

Please Feel Free to Share ☺