1

I have a flash drive that I don't want mounted. Instead, I just want to use it to transfer files between my computers.

Is there a way that I can access my flash drive from the terminal via the Devices directory? Or is the only way to access a flash drive from the terminal to mount it first, then access the mount point?

1
  • 1
    I don't think you understand the concept of "mounted". It's not physical "mount", it's a fancy word for disk being "connected" or "in use". Naturally, if usb device isn't mounted, you can't use it, and can't transfer files – Sergiy Kolodyazhnyy Dec 31 '16 at 21:52
3

You can not access any form of storage media without mounting the drive first. However, you can do this entire process from your terminal.

First, you need the partition ID (/dev/sdXY). You can use the lsblk command to find this. Once you have this ID, you can run sudo mount /dev/sdXY /mnt. Your flash drive's filesystem will now be available at /mnt and can be used from the terminal.

Devices in /dev are known as block devices, and are raw representations of the filesystems contained within those devices (where applicable). While you can directly read and write from these devices, it's often a bad idea because you're ignoring a huge layer of filesystem abstraction and protection.

For most use cases, the only time you'd be reading from/writing to the raw block devices is for cloning or very low level device operations. The filesystem provides a huge layer of abstraction, error checking, and file safety.


Note: The section below this block of text is meant for educational purposes only. Please do not try this on any system/drive that you care about, as the results could very easily be catastrophic. I take no responsibility for what you do if you follow anything I say below.

You have been warned.

With that warning being said, and if you don't care about the contents of your flash drive, it is theoretically possible to read and write data to/from the flash drive using raw block operations.

At its simplest, you'd write a file (let's say files.zip) to the flash drive using this command:

dd if=files.zip of=/dev/sdd bs=1024

This will copy the zipfile to your flash drive's raw block, but will also (likely) corrupt any partition or related data currently on the drive. It will also make a record of how many "blocks" were written to the drive -- make note of this. For this example, I'm going to say 1234 blocks were copied.

When you want to read the file from the flash drive onto another computer, you can do this with the inverse command:

dd if=/dev/sdd of=files.zip count=1234 bs=1024

This will pull the raw block data from the drive (containing a ZIP file) for the first 1234 blocks, and write it to files.zip on your computer in the current directory. Also note that this ZIP file may not be actually readable due to corrupt/garbage data at the end of the file or similar. Be sure to note this if necessary. You can use the head command to trim the ZIP file back if needed.

When you are done, you'll likely need to format the flash drive and re-partition it and the like, making this very infeasible for large operations. Just use the file system.

1
  • You can access the data partition as one complete raw binary data blob without mounting it, which is enough to e.g. clone the entire partition or make an image. You just can not access any contained file structures. – Byte Commander Dec 31 '16 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy