Is the /dev directory the only place in Linux where device files can be stored?

John

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?

Stephen Harris

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Find out what device /dev/root represents in Linux?

为什么在某些Linux系统上,根文件系统在mtab中显示为/ dev / root而不是/ dev / <real device node>?

Linux内核中struct net_device的dev_addr和perm_addr有什么区别

How can I show the size of all files in my ~/.cache directory?

How can I set up a WiFi-hotspot to host files which can be downloaded by an other device later

延迟dev-sda2.device

Where kernel configuration file is stored?

Where is the background image for windows stored?

什么是Linux上的/ dev / vcs *?

Where should I place the .htpasswd file (phpMyAdmin)?

How to find a directory on linux?

Linux如何使用/ dev / tty和/ dev / tty0

Linux md RAID:/ dev / md0与/ dev / md / 0

在Linux上将/ dev / random链接到/ dev / urandom是错误的吗?

如何在Kubernetes上使用--device / dev / video0?

Where are implementation version string stored in android studio

Where are local stack variables stored in C?

在Linux中如何填充/ sys / dev / char?

Linux键盘事件捕获/ dev / inputX

/ dev / tcp在Linux中不存在

read files from a directory to a list

Linux:/ dev / console,/ dev / tty和/ dev / tty0之间的区别

Linux socket ioctl SIOCGIFNAME No such device error

LINQ on Directory.GetFiles with Substring in Where 子句

Collect files from several different directories and put them in one place

Heroku Only Dev Environment具有Chrome版本81问题

--only = dev在package.json中是什么意思?

'npm install --only=dev' 删除现有的包

Get consistent encoding for all files in directory