Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

"/dev" and "/sys" directory.

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

"/dev" and "/sys" directory.

#1 Post by hack3rcon »

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

Thanks.


hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

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

#3 Post by hack3rcon »

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?

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1399
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 46 times
Been thanked: 68 times

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

#4 Post by None1975 »

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 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

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

#5 Post by hack3rcon »

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

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

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

#6 Post by p.H »

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.

reinob
Posts: 1195
Joined: 2014-06-30 11:42
Has thanked: 99 times
Been thanked: 47 times

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

#7 Post by reinob »

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.

Post Reply