0

Recently I installed a 2TB usb drive on Ubuntu 20.04, and copied some files onto it. Now I would like to read those files in a Python program, but I can't get the path to the new drive.

The drive is /dev/sda1, and it's mounted at /mnt/ssk2TB. I have a USB key with files on it, and its path is /media/mpxt/A_MEDIA. In /media/mpxt I also have an entry for the new 2TB drive as /media/mpxt/6e9ee7e7-17af-4501-94aa-ffe6bb90c192.

Lsblk confirms it:

sda           8:0    0   1.8T  0 disk 
└─sda1        8:1    0   1.8T  0 part /media/mpxt/6e9ee7e7-17af-4501-94aa-ffe6bb

Also,

ls -l /dev/disk/by-uuid said its UUID is:

6e9ee7e7-17af-4501-94aa-ffe6bb90c192, which matches.

I used that as a path:

fname = "/media/mpxt/6e9ee7e7-17-af-4501-94aa-ffe6bb90c192/Test_Data/Audit_Python/Python_Results"

testdata_fname = open(fname, 'rb')

I get this error message:

`FileNotFoundError: [Errno 2] No such file or directory: '/media/mpxt/6e9ee7e7-17af-4501-94aa-ffe6bb90c192/Test_Data/Audit_Python/Python_Results`

I can cd /media/mpxt/6e9ee7e7-17af-4501-94aa-ffe6bb90c192/Test_Data/Audit_Python and get a listing of files. So why can't I use that path to open a file?

What do I use as a path for the USB drive described above?

Thanks for any help.

4
  • I don't know what mpyt is
    – RTC222
    Commented Nov 23, 2023 at 0:44
  • @user68186 - yes. It was a typo; I just edited it.
    – RTC222
    Commented Nov 23, 2023 at 17:04
  • I didn't do anything in /etc/fstab or change anything else. If it can't be mounted in both /mnt and /media at the same time, how is it that I can see the drive in Nautilus, and can freely move files in and out? If I were to unmount one or the other, what syntax would I use to open a file, my original question.
    – RTC222
    Commented Nov 23, 2023 at 17:39
  • Are you saying that if I unmount the mount point at /mnt/ssk2B and keep the one at /media then my Python file open command should work? If not, what would the correct syntax be to open a data file on the USB drive?
    – RTC222
    Commented Nov 23, 2023 at 18:01

1 Answer 1

2

Try the following:

Step 1: Unmount from ssk2TB

Unmount the external drive from the mount point you have created: /mnt/ssk2TB. Open a terminal and type:

sudo unmount /mnt/ssk2TB

If the partition was mounted, this command will return nothing. If the partition was not mounted (or was unmounted before) you will see an error message:

umount: /mnt/ssk2TB: not mounted

Make sure there are no files or folders inside /mnt/ssk2TB, after you unmount the partition. If there are files/folders after you unmount the partition /dev/sda1, then it means they were put there by mistake when the partition was not mounted.

Delete the folder ssk2TB from inside /mnt/ if you want.

Step 2: Unmount from GUI and remove the USB

Using the GUI (using either the desktop of the Files/Nautilus app) "Eject" the external drive /dev/sda1 mounted at the mount point /media/mpxt/6e9ee7e7-17af-4501-94aa-ffe6bb90c192.

Wait for the notification that says the drive can be safely removed.

Physically unplug (remove) the USB drive from the computer.

Check if the folder /media/mpxt/6e9ee7e7-17af-4501-94aa-ffe6bb90c192 still exist and if there are any files inside. If there are files inside this folder, then they were put there by mistake.

Delete the folder 6e9ee7e7-17af-4501-94aa-ffe6bb90c192 from /media/mpxt/. This folder should not exist if the USB drive is not connected.

Step 3 Start Again

Insert the USB drive (plug it in). The computer should recognize it and automatically mount it under /media/<Your Username>. For example at /media/mpxt/6e9ee7e7-17af-4501-94aa-ffe6bb90c192.

Now you should be able to access the the files and folders inside the USB drive as the user mpxt. If you try to access these files as another user, you may get permission denied.

File name and extension matters (in python)

Ubuntu (Linux, in general) does not care too much about file extensions. You may name a binary file without an extension such as Python_Results. Ubuntu does not care.

However, within python it matters. Renaming the file Python_Results to Python_Results.bin may help.

Note that in Linux file names are case sensitive. So Python_Results and python_results are two different files.

Hope this helps

4
  • 2
    Thanks very much. It's Thanksgiving day and I have to leave now, but I will do these steps tomorrow, and let you know what happens.
    – RTC222
    Commented Nov 23, 2023 at 23:33
  • Your first instruction was to unmount /mnt/ssk2T. It responded with: umount: /mnt/ssk2TB: not mounted. Your second instruction is to "Eject" the external drive. Nautilus doesn't show an Eject option (just unmount), and GNOME Disks shows only a "power off." I can use Linux eject from the command line, but I'm not clear on whether I should use eject /dev/sda1 followed by udisksctl power-off -b /dev/sda1, as recommended in the second answer here: unix.stackexchange.com/questions/35508/…. Before I proceed, I wanted to ask you first.
    – RTC222
    Commented Nov 24, 2023 at 21:57
  • You may use unmount from nautilus.
    – user68186
    Commented Nov 24, 2023 at 22:41
  • 1
    I followed your steps, and it worked as you said, and it mounted itself at /media/mpxt/6e9ee7e7-17-af-4501-94aa-ffe6bb90c192/ as it did last time. However, when I open a data file from Python, I still get a file not found error. So I put a ".bin" extension on the file (because it's being opened with "rb") and now it does open and read. Thanks for your help. Now the drive is not double-mounted, and the issue is solved. .
    – RTC222
    Commented Nov 24, 2023 at 23:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .