Quantcast




A new version of the software that powers this site is now available for beta testing at Pyplate. Check out the installation instructions, and build your own Raspberry Pi powered site. Now includes seven free themes.

Follow me on Twitter and Google+

Google+







submit to reddit       
       

Connect your Raspberry Pi to a USB hard disk

Raspberry Pi connected to a USB hard disk

The amount of space available on an SD card is much more limited than the amount of space on a hard disk, so it's worth attaching a hard disk to your Pi. The simplest to expand your Pi's storage capacity is with a USB hard disk.

If you're planning on leaving the same USB hard disk connected to your Raspberry Pi all the time, then you need to make sure that your Pi mounts the drive automatically every time it boots. You can do this by editing the file system table file.

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 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 is listed in /dev/sda1, and the file system type is Fat32. If your USB drive has an NTFS 3g file system, you will need to install an NTFS driver.

sudo apt-get install ntfs-3g

In order to access the files and folders on a disk, Linux needs to mount it. The contents of the disk will appear as a folder in /media. You can mount disks in other folders, but it's conventional to use /media. You need to create a directory where the mounted disk will appear in the media directory, and change its owner to pi (or any other user account that you might have created).

$ sudo mkdir /media/usbhdd
$ sudo chown pi:pi /media/usbhdd

In order to mount the disk, type this command:

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

The '-t vfat' tells the mount command that your drive has a fat32 file system. If your drive is formatted with NTFS, you should use '-t ntfs-3g' instead. The '-o uid=pi,gid=pi' part of the command means that the disk will be owned by user pi. You can use this command to unmount the disk:

$ sudo umount /media/usbhdd

Now you need to edit the file system table so that this disk is mounted every time your Raspberry Pi starts up:

$ sudo leafpad /etc/fstab &

You need to use sudo because the fstab file is owned by root. If you don't use sudo, you'll be able to open the file in leafpad, but you won't be able to save changes. The '&' means the command runs in the background, and you can keep using the terminal for other commands while leafpad is running. You should see something like this:

proc /proc proc defaults 0 0 /dev/mmcblk0p1 /boot vfat defaults 0 2 /dev/mmcblk0p2 / ext4 defaults,noatime 0 1

Add the following line, and save the file.

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

Reboot your Pi to and you should be able to access your USB drive via /media/usbhdd.


Comments

Comments

comments powered by Disqus