Search This Blog

Mounting a Drive With a Raspberry Pi



When you plug a USB hard drive or flash drive into a Raspberry Pi, you need to mount it to access the data on it. To do that, you need to know what name the OS has given the drive. So plug it in then run this command dmesg | tail. This will output something like this:

[ 1238.761341] sd 6:0:0:0: [sdb] 126058496 512-byte logical blocks: (64.5 GB/60.1 GiB)
[ 1238.762086] sd 6:0:0:0: [sdb] Write Protect is off
[ 1238.762091] sd 6:0:0:0: [sdb] Mode Sense: 43 00 00 00
[ 1238.763149] sd 6:0:0:0: [sdb] No Caching mode page found
[ 1238.763155] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[ 1238.766839] sd 6:0:0:0: [sdb] No Caching mode page found
[ 1238.766846] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[ 1238.767747]  sdb: sdb1 sdb2


You can see that the OS has referred to the drive as sdb, with two partitions sdb1 and sdb2. To mount sdb1, you can make a directory to mount it to:

mkdir ~/mydrive

Then mount it:

sudo mount /dev/sdb1 ~/mydrive

Now your drive is mounted at that location and all the files will be within the mydrive folder. Depending on the filesystem of the partition, you might need to change the ownership to write to the drive:

sudo chown -R your_username:your_username ~/mydrive