Issue
I am currently writing a program in Java that will be run on a raspberry pi 4b using a docker container. I am currently trying to figure out how to get the path to the USB so I can move files to and from the USB to the Raspberry Pi. I am using java 17.
Solution
To use an external drive or USB you have to plug the USB into your device first.
You can then run the command lsblk
to receive information about all your disks and USB's plugged into your machine.
The output will look something like this:
To know exactly which is your USB execute the command once before and once after plugging in the USB.
You then need to mount the USB to your Linux file system. Therefore you create a folder anywhere on your system. But normally you would create the folder in the /mnt
or /media
folder.
If you did not format your USB beforehand you can follow this tutorial:
https://phoenixnap.com/kb/linux-format-disk
Now we return to the output of the lsblk command above. Lets say your USB is named sdb
and has a partition named sdb1
. Then execute the command mount /dev/sdb1 /media/usb_folder
.
To create your usb folder type mkdir -p /media/usb_folder
. You can freely choose the name of the folder but make sure to use the same name throughout the explanation.
You can now use the USB and the path is: /media/usb_folder
.
Sources:
https://www.tutorialspoint.com/how-to-mount-usb-drive-in-a-linux-system
https://phoenixnap.com/kb/linux-format-disk
https://wiki.ubuntuusers.de/lsblk/
Answered By - Fabian Hintringer Answer Checked By - Marilyn (WPSolving Volunteer)