"/dev" and "/sys" directory.

New to Debian (Or Linux in general)? Ask your questions here!

"/dev" and "/sys" directory.

Postby hack3rcon » 2019-09-03 04:26

Hello,
What is the different between "/dev" and "/sys" directories? both of them related to the system hardware?

Thanks.
hack3rcon
 
Posts: 293
Joined: 2015-02-16 09:54

Re: "/dev" and "/sys" directory.

Postby pylkko » 2019-09-03 06:56

User avatar
pylkko
 
Posts: 1563
Joined: 2014-11-06 19:02

Re: "/dev" and "/sys" directory.

Postby hack3rcon » 2019-09-07 04:34

pylkko wrote:https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

Code: Select all
/dev     Device files, e.g., /dev/null, /dev/disk0, /dev/sda1, /dev/tty, /dev/random.
/sys     Contains information about devices, drivers, and some kernel features.

Both are for devices?
hack3rcon
 
Posts: 293
Joined: 2015-02-16 09:54

Re: "/dev" and "/sys" directory.

Postby None1975 » 2019-09-07 09:54

hack3rcon wrote:Both are for devices?

Code: Select all
/dev
is for device file (it is a interface to a device driver that appears in a file system as if it were an ordinary file)
Code: Select all
/sys
contains information about devices, drivers, and some kernel features.
OS: Debian Buster / WM: Awesome
Debian Wiki | DontBreakDebian, My config files in github
User avatar
None1975
 
Posts: 920
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: "/dev" and "/sys" directory.

Postby hack3rcon » 2019-09-10 04:37

Why "/dev" not have information about devices? In "/dev" directory, I can see something "sda1". Can I open it with a text editor or...?
hack3rcon
 
Posts: 293
Joined: 2015-02-16 09:54

Re: "/dev" and "/sys" directory.

Postby p.H » 2019-09-10 09:37

You could open a raw partition with a text editor, but it would not be a good idea. Partitions usually contain binary data, not text. Also, some text editors read the whole file and load it into memory when opening it. If the partition is big, it would take a lot of time and consume a lot of memory ; the editor or the whole system may crash or hang forever.

/dev and /sys are very different in nature.

Like /proc, /sys is not a "real" filesystem but a pseudo-filesystem which is actually an interface with the kernel. Files and directories are automatically created by the kernel ; you cannot create, delete, move or rename them, nor change their permissions. All you can do is read and/or write them.

Conversely, /dev is a normal filesystem. A very long time ago, it was just a directory in the root filesystem, containing statically created device nodes. On current GNU/Linux systems it is a special instance of tmpfs (temporary filesystem in memory) called "devtmpfs", containing dynamically created device nodes (by udev). You can create, modify and delete any file on it.

A device node is a special file which contains no data but is a pointer to a block device (such as a disk or partition) or a character device (such as a console, keyboard, mouse or printer). It allows to read and write a device (almost) like if it was a regular file.
p.H
 
Posts: 1080
Joined: 2017-09-17 07:12

Re: "/dev" and "/sys" directory.

Postby reinob » 2019-09-10 11:33

hack3rcon wrote:Why "/dev" not have information about devices? In "/dev" directory, I can see something "sda1". Can I open it with a text editor or...?


In /dev you have the device files. They are not real files in the common sense of the word, but identify a specific device (like /dev/sda corresponds to your first SATA hard disk). This belongs to the standard Unix way, where everything is (treated as) a file.

You can actually do things like "cat /dev/sda". Have fun with it.

/sys is just a way for the kernel to expose settings. The "files" are not actual files, but identify parameters of the kernel and allow you to change their values.

e.g. cat /sys/kernel/mm/transparent_hugepage/enabled tells you whether THP is enabled, while
echo never > /sys/kernel/mm/transparent_hugepage/enabled allows you to disable that setting.

Add. while submitting I noticed that p.H. has already been a very good answer. I post mine nevertheless.
reinob
 
Posts: 706
Joined: 2014-06-30 11:42


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 9 guests

fashionable