Permanently Mounting a USB Hard Drive to your Raspberry Pi

Updated on September 9, 2014

The SD card that boots and runs your Raspberry Pi is likely very small, offering only a few GBs worth of space. This can be filled very quickly. The first upgrade to a Raspberry Pi is usually adding a USB hard drive. This guide will go through permanently mounting a USB NTFS formatted hard drive to your Raspberry Pi.

This guide assumes you already have a Raspberry Pi up and running with Rasbian as the operating system. If you're not up to this point yet, check out this guide on setting up a Raspberry Pi from the very beginning!

Your new best friend

Creative Commons (CC BY-SA 2.0) Used Unaltered.
Creative Commons (CC BY-SA 2.0) Used Unaltered. | Source


The ingredients here are simple. You will need:

  • A Raspberry Pi. Ours has Rasbian installed as the operating system.
  • A way to communicate with the Raspberry Pi, such as directly connecting keyboard, mouse, and monitor or going "headless" and connecting with another computer.
  • A USB Hard Drive

For the hard drive, we chose a Seagate 4TB External, available for $139.99 at
This setup has some pros and cons.


  • 4TB is rather large.
  • The hard drive uses an external power source. Therefore, it doesn't drain power from the Raspberry Pi's USB port.


  • It's pricey at $139.99.
  • Because it uses an external power source, it requires another cable and another outlet.

Another option is the WD 1TB Portable Drive, also available from This comes at a nicer price point, only $69.99. The drive is large enough (1TB) to meet all immediate needs and doesn't require an external power source.

The code

If you have experience with Linux and BASH, here is the code you will need to use. If this looks confusing or intimidating, keep reading! We will break down each and every line of code and command used. By the end of the tutorial, you'll be able to come back up to this point, read the code, and congratulate yourself for knowing exactly what each command is doing.

Let's get started!

#For everyone well versed in Linux and BASH, here's everything up front

#Find the drive (in our case /dev/sda1)
sudo fdisk -l
#install NTFS-3g
sudo apt-get install ntfs-3g
#Make the mount directory and manage it's owner
sudo mkdir /media/pidrive
sudo chown pi:pi /media/pidrive
#Mount the drive
sudo mount -t ntfs-3g -o uid-pi,gid-pi /dev/sda1 /media/pidrive
#Now you're done but it's not permanent

#Making it permanent
#Edit file system table
sudo nano /etc/fstab

#Add this line of text after the SD card partitions
/dev/sda1	/media/pidrive	ntfs-3g	uid=pi,gid=pi	0	0
#hit ctrl-o to save and ctrl-x to exit nano

#Now the mounting will be restored on reboot
#Reboot to test it
sudo shutdown -r now
(CC BY 2.0)
(CC BY 2.0) | Source

Step 1: Connecting and finding the drive

First thing's first: boot up your Raspberry Pi and login. Plug in the USB hard drive into a USB port on the Raspberry Pi and plug in the power source for the drive if it requires one.

Now let's see if the Raspberry Pi "knows" about the new hard drive you've connected to it. Open the terminal window. If you're in a Desktop style screen, click on the menu at the bottom left of the screen, navigate to "Accessories" and then click on "LXTerminal".

Now type:

sudo fdisk -l
#You should see something like this
Disk /dev/mmcblk0: 4110 MB, 4110417920 bytes
4 heads, 16 sectors/track, 125440 cylinders, total 8028160 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: 0x000b5098

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     8028159     3952640   83  Linux
Note: sector size is 4096 (not 512)

Disk /dev/sda: 4000.8 GB, 4000787025920 bytes
255 heads, 63 sectors/track, 60800 cylinders, total 976754645 sectors
Units = sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x90a334b0

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   976754644  3907010388    7  HPFS/NTFS/exFAT

Code breakdown

"sudo" - this essentially means "Run as Administrator." We'll be using this a lot.

"fdisk" - This is short for "Fixed Disk" and is a command line utility built into the operating system that allows you to manage partitions on a hard drive. Right now we're using it to look at what partitions on what hard drives your Raspberry Pi knows about by using...

"-l" - This is a "list" command that is passed to the fdisk utility. It tells fdisk to list what it knows.

Looking through the list outputted we see, from top to bottom.

"Disk /dev/mmcblk0 4110MB"

This is the SD card which the Raspberry Pi boots off of. It has two partitions:

"/dev/mmcblk0p1" and "/dev/mmcblk0p2"

Neither of these are what we're interested in. The drive that we're interested in is the 4TB Seagate External.

That drive is listed as:

"Disk /dev/sda 4000.0 GB"

and has one partition:


Remember that. "/dev/sda1" That is the name that the drive is going by and the name we'll use to mount it.

Step 2: Loading the correct drivers

We found the drive and the Raspberry Pi knows about it, so we're done right? Not quite. The Raspberry Pi knows about the drive but it isn't accessible yet. You wouldn't be able to find the drive anywhere in the filesystem. To solve this issue we need to mount the drive.

First, we need to download the software that will handle talking to the drive. Drives come in different file system formats. The drive you have, if it's newly bought, has ever been used or will ever be used on a Windows PC, is most likely formatted as NTFS. NTFS is great for Windows but isn't native in Linux, which means Linux doesn't like to communicate with NTFS drives. This is easy enough to fix. Make sure your Raspberry Pi is connected to the internet, open the terminal window and type:

sudo apt-get install ntfs-3g

Code breakdown

"apt-get" - "apt" is short for "Advanced Packaging Tool" and "apt-get" is another command line utility. It allows you to grab software packages online and install them onto the local computer.

"install" - This is the keyword we pass to "apt-get" so that it knows that we want it to install something.

"ntfs-3g" - This is the something we want installed. "ntfs-3g" is a read-write driver for NTFS, which means it enables communication between Linux and NTFS formatted drives.

Step 3: Creating a mount point

Now we need a place in the filesystem to mount the drive to, so let's create that.

The next two lines of code will create the file location and then change the user that "owns" that location.

#Type this line then press enter
sudo mkdir /media/pidrive

#Then type this line and press enter
sudo chown pi:pi /media/pidrive

Code breakdown

For the first line of code:

"mkdir" - This is short for "Make Directory." It creates a folder in the file system.

"/media/pidrive" - This is the folder you want to create. The Linux convention is to mount USB connected devices in the "Media" folder. The folder I want to use to access the USB drive I'm calling "pidrive." You can call yours whatever you want.

For the second line of code:

"chown" - This is short for "Change Owner."

"pi:pi" - This is choosing the owner:group for the folder. If you're using the Raspberry Pi, the default user is "pi." The default user group is also "pi." Thus, user:group becomes pi:pi.

"/media/pidrive" - This is the folder we want to change ownership of.

We change ownership of the folder so that you don't need "sudo" or root permission to use the hard drive.

Step 4: Getting the drive mounted temporarily

Okay, let's get mounting!

Remember the hard drive location? In our example it was "/dev/sda1". In the terminal type the following code:

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

Code breakdown

"mount" - mount is an operating system action that will mount the drive to the filesystem.

"-t ntsf-3g" - "-t" is the filesystem type flag and "ntfs-3g" is telling the mount command what filesystem to use.

"-o uid=po,gid=pi" - This is setting the owner of the drive. "uid" is user ID and "gid" is group ID. This is exactly like the ownership settings we put on the mount point folder.

"/dev/sda1" - This is the reference to the hard drive itself and...

"/media/pidrive" - Is the reference to the mount point folder.

Congratulations! Now your hard drive is mounted to the filesystem, accessible, and ready to use! However, this approach has one downside. Every time you reboot the Raspberry Pi, you'll have to execute this line of code again. Now we're lazy and don't want to do that, so let's setup this mount point permanently!

Step 5: Getting the drive mounted permanently!

To get this drive to mount itself every time the Raspberry Pi is rebooted, we have to edit a configuration file on the Raspberry Pi called fstab short for "File System Table." Now this sounds a lot more complex than it really is. Fstab is just a text file that tells the Raspberry Pi what to do with the hard drives connected to it. To edit it, we're going to use a text editor that comes with the Rasbian Operating System and works in the terminal called Nano.

In the terminal type in this code:

sudo nano /etc/fstab
#You will see something like this
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1	/media/pidrive	ntfs-3g	uid=pi,gid=pi     0       1
#A swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

The terminal window will look different. We are now in the text editor Nano and are ready to edit this file.

Press the down arrow to navigate to one line below the line that says "/dev/mmcblk0ps" and press enter to insert a new line.

Arrow up one to place your cursor on the new line and type in:

/dev/sda1	/media/pidrive	ntfs-3g	uid=pi,gid=pi     0       1
#So that your window now looks like this
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1	/media/pidrive	ntfs-3g	uid=pi,gid=pi     0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

This code should look familiar since it's very similar to the mount command we used to manually mount the drive.

Now press Ctrl+O (not Ctrl+Shift+O) to save the file. Press Enter to acknowledge the file name and then press Ctrl+X to exit Nano.

Now the terminal should return to the way it originally looked.

Congratulations! You're done! Your USB hard drive is now permanently mounted to the Raspberry Pi and will be remounted on every reboot. Now you're ready to use the USB drive to store your files, music, documents, videos, solutions to all the world's problems, and whatever else you want on your Raspberry Pi!

PiDrive ready to roll

Creative Commons (CC BY 2.0)
Creative Commons (CC BY 2.0) | Source

Give me feedback!

Was this guide useful?

See results

Drop me a line

Please let me know if this guide has been helpful to you. Take the poll on the right and leave a comment below! Thank you for listening.

Happy Computing!

© 2014 John Himics


    0 of 8192 characters used
    Post Comment

    • profile image


      7 months ago

      This was a great help! Thank you so much:D

    • profile image


      2 years ago


      I have a problem, "sudo chown pi:pi /media/pidrive" doesn't work he says pi:pi invalid user. can you help me?


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)