0

I've been reading other questions and answers, but none have shown me exactly why mounting is absolutely necessary. They say the drive needs a mounted directory for association with the physical drive, but why, for example, can't files be copied from /home/[user] to /dev/sdb (a USB drive) directly? Does all data copied to the directory where the drive is mounted just get copied to the drive itself immediately after?

6

/dev/sd* can be accessed without mount. Indeed, I have written a file directly to /dev/sdb before with success, but what I wrote to was the raw USB disk. The file I wrote was a disk image of an Ubuntu install disk when I then used to make a bootable USB stick for installing Ubuntu on a new computer. You can write to /dev/sda as if it were a file, but it's writing to the disk raw. If you try to write a second file, it will write on top of the first file, and, unless it's something like a disk image, most other computers/software won't know what to do with it.

What mounting does is attempt to add a file system driver in-between the raw disk and your file system layout. Part of the mount process is selecting the correct filesystem, FAT32, Ext4, NTFS, etc. and initializing that driver to understand the contents of the disk you are mounting. Now, it interprets the disk as a structured file system with folders, files, and metadata about those folders/files.

2

You can certainly copy files directly from /home/user/whatever to /dev/sdb directly assuming you have write privileges to the raw device. However, since you're now bypassing the filesystem on that device you'll just have a stream of bytes on /dev/sdb. The FAT or NTFS, or ext4 file system that used to be there is now gone since you didn't go through the file system driver. If you did mount the device before the copy then the driver takes care of the file system details. Also, you're not doing a double copy since the directory does not exist independently of the device.

1

Mounting isn't absolutely necessary, for example the mtools suite can access FAT filesystems directly, without kernel support.

But you do need a filesystem driver in one form or another to access filesystems on the disk, be it a kernel driver used when the fs is mounted, or a userspace utility. If you don't have a filesystem on the drive (or don't care about the internals of the filesystem), then it's simple to just read or write data directly. This is what you'd do if you write e.g. a disk image to the drive.

  • So if I'm reading these helpful answers correctly, the /dev/sd* device is just for physical acknowledgement that it's there and for properties of it, and mounting it indirectly initiates a driver that will properly translate the data to the appropriate filesystem on the device? – TheRyGuy Aug 20 at 19:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.