1

I made an error while writing my command too fast and "overwrote"(?) /dev/sda instead of moving a file in /dev directory. How can I recover it?

Also what exactly is /dev/sda? Is it the directory where the hard drive/SSD is mounted?

Anosen
  • 13

1 Answers1

1

When I do (with regular files):

echo 1 > source
echo 2 > target
cp -l target target2
mv source target
cat target2

then I get 2. This means nothing is written to the target, it's just unlinked before source gets renamed, I think. With ls -i -1 I can check that source keeps its inode number even if target existed before.

Another test is

mv /dev/urandom /dev/sr0

It doesn't send data to my optical drive. Instead, after that /dev/sr0 behaves as /dev/urandom.

The conclusion is: your /dev/sda was replaced by some other "entry" (which also lost its original name). Reboot will fix this, unless your system is an old (or unusual) one that keeps these device files as static.


Also what exactly is /dev/sda?

It is a special file that (usually) corresponds to your HDD or another storage. Unix identifies such resources by a major number and a minor number. Generally, the major number identifies the device driver and the minor number identifies a particular device (possibly out of many) that the driver controls. To see these numbers try ls -l /dev/sda. My output is:

brw-rw---- 1 root disk 8, 0 Jul   8 00:48 /dev/sda

This 8, 0 fragment is a <major>, <minor> tuple here.

I wrote that /dev/sda usually corresponds to your HDD because in your case (after mv) you now have something else under this name.

Is it the directory where the hard drive/SSD is mounted?

No. When you mount it the command is like

mount /dev/sda /a/directory/to/mount/to/

so these are two different things.

(Note it's usually /dev/sda1 or so that is passed to a mount command, not /dev/sda. This is because sda1 corresponds to a partition while sda corresponds to the entire HDD. Filesystems usually live inside partitions but it's possible to have one on a device where there are no partitions, so the above command may happen. Compare: Uses of single-partition disk configuration).