I know that the /dev
directory stores device files, but is the /dev
directory the only place where device files can be stored, or is it just a convention to store device files in the /dev
directory?
It's just convention. Indeed, in a chroot
environment or a container (eg docker) then device entries may be present elsewhere.
What makes a device entry a device entry is the type of entry, not it's name
So, for example:
% ls -ld /dev/vda
brw-rw---- 1 root disk 253, 0 May 26 07:00 /dev/vda
The first "b" means this is a block device. The "253" is the major device number, and the "0" is the minor device number. In this case
% grep virt /proc/devices
253 virtblk
So major device 253 is related to the virtual block layer.
You'll note the name "vda" isn't important, here!
I do could
sudo mknod /tmp/foo b 253 0
Now /tmp/foo
will access exactly the same data:
% sudo dd if=/dev/vda bs=256b count=1 | sum
....
40545 128
% sudo dd if=/tmp/foo bs=256b count=1 | sum
....
40545 128
Common names are important for humans and config files (eg /dev/tty1
is the common name for the first virtual console on a Linux machine; /dev/ttyS0
is the common name for the first serial port), but it's the type (block/char) and major/minor number that makes it work.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句