Raspberry Pi Connection To A USB Hard Disk

0

Raspberry Pi Connection To A USB Hard Disk:

USB Cable

The space available in a hard disk is more than the space available in a SD card, so it’s required to connect a hard disk to your Raspberry Pi. The easiest way to increase the storage capacity of is with a USB hard disk.

If you want that consistently the same USB hard disk connected to your Raspberry Pi, then you must check that when it boots, your  mounts the drive automatically.

A file will generated in /dev and used as an interface to your disk, when USB drive detected by Linux. By following this command, you can register all the disk device files in /dev:-

$ sudo fdisk -l

Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes

4 heads, 16 sectors/track, 121008 cylinders, total 7744512 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00014d34

Device Boot      Start         End      Blocks   Id  System

/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)

/dev/mmcblk0p2          122880     7744511     3810816   83  Linux

Disk /dev/sda: 320.1 GB, 320072933376 bytes

255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x8be4e163

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *          63   625137344   312568641    b  W95 FAT32

My USB disk listed In/dev/sda1 and Fat 32 is the file system type. You will require installing an NTFS driver, if your USB drive has an NTFS 3g file system.

sudo apt-get install ntfs-3g

Linux must mounting to use the files and folders on a disk consecutively. In /media, the contents of the disk will show as a folder. It’s usual to use /media to mount disks in other folder. In the media directory, the mounted disk will appear but for that you need to generate a directory first and change its owner to .

sudo mkdir /media/usbhdd

$ sudo chown : /media/usbhdd

Type this command, in order to mount the disk:

sudo mount -t vfat -o uid=,gid= /dev/sda1 /media/usbhdd

 Your drive has a fat32 file system, ‘-t vfat’ tells the mount command barely. You should apply ‘-t ntfs-3g’, if your drive is format with NTFS. The disk will owned by user because of the ‘-ouid=,gid=’ part of the command. To unmount the disk, you have to type this command:

sudo umount /media/usbhdd

This disk is mounted every time your Raspberry pi starts up; you require editing the file system table:

sudo leafpad /etc/fstab &

The fstab file is owned by root, so you have to use sudo. Without using sudo you are able to open the file in leafpad, but you can’t able to save changes. While leafpad is running, you can keep using the terminal for other commands and the command runs in the background which means ‘&’ will appear.

It will appear like this:

proc            /proc           proc    defaults          0       0

/dev/mmcblk0p1  /boot           vfat    defaults          0       2

/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1

To save the file, add the following line and save it:

/dev/sda1       /media/usbhdd   vfat    uid=,gid=     0       0

You can able to use your USB drive via /media/usbhdd after you reboot your Raspberry Pi.

Share.

About Author

Leave A Reply