HowTo: Raspberry Pi - Mount drive under Linux

As a user of the Raspberry Pi sooner or later you come across the question of how to connect a USB stick, external hard disk or SD card to the Raspberry Pi and access it.

The process is similar for all drive types. Whether USB stick, external hard disk or SD card. After connecting to the Raspberry Pi, the corresponding drive must first be mounted.

I have described how you can do this in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you start with this article, you should have prepared a RaspberryPi so that it can be reached via the network and controlled via SSH.

The following articles describe what needs to be done to prepare the RaspberryPi.

In the following lists you will find all the parts you need to implement this article.

Required tool:

NumberLink
1xScrewdriver set  Buy at Amazon
1xSD card reader  Buy at Amazon

Required material:

NumberLink
1x Raspberry Pi  Buy at Amazon
1x Raspberry Pi power supply  Buy at Amazon
1x Raspberry Pi case  Buy at Amazon
1x Micro SD card 64GB  Buy at Amazon


Log in to the RaspberryPi via SSH

To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.

After entering your username and password you can enter the first commands.

Show recognized drives

Before you can mount your drive, you should check whether it has already been recognized. This way you can also find out the name of the partition that you will mount later.

By entering the command

lsblk

you can display the recognized drives.

There you can then view all connected drives (first red arrow at "disk") and associated partitions (second red arrow at "part").

At this point, note the name of the partition that you want to mount. In this example, this would be "sda1".

For drives that are already mounted, you can see the corresponding path in the "Mountpoint" column.


Prepare mount path

Before you can mount your drive, you must first select a mount point. The mountpoint is basically a simple directory on your system drive (in the case of the Raspberry Pi, the system drive is the SD card on which you have also installed the Raspberry Pi image). To create a mountpoint, you can also simply create a specific directory or folder.

For example, you can create a directory in the temporary folder.

With the help of the following command

mkdir /tmp/mountPoint/

for example, the "mountPoint" folder is then created in the temporary folder. This temporary folder is emptied each time the system is restarted. This also removes the mount point.


Mount drive

Now that you have created a mount point, you can mount the connected drive.

To do this, you need the information from the previous steps.

  • Partition name: sda1
  • Mount Point: /tmp/MountPoint

Now you can mount your drive with the following command:

sudo mount /dev/sda1 /tmp/mountPoint/

It is important that you do not just enter "sda1" as the partition name. Here you must enter the complete absolute path (i.e. including /dev/).


Accessing the mounted drive

After you have mounted the drive as described above, you can of course now access it.

To check whether the drive has been mounted correctly, you can use the command

df -h

enter.

This will list all drives including mountpoiunt. The entry for the example used here can be found in the bottom line. The partition path (/dev/sda1) is shown in the left-hand column and the mount path (/tmp/MountPoint) in the right-hand column.

If you now change to the mount path (/tmp/MountPoint) you can display the contents of the mounted drive.

If you now want to copy a file to the mounted drive, for example, you must select the MountPoint of your mounted drive as the target.


More articles on the topic

In the following category you will find more links about Rasperry PI.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.