10

I ran some commands without completely understanding them while trying to get screen brightness working and now I'm stuck with a nasty symlink in '/sys/class/backlight/asus_laptop' that I am trying to get rid of.

I have tried

sudo rm /sys/class/backlight/asus_laptop
sudo rm '/sys/class/backlight/asus_laptop'

su root
rm /sys/class/backlight/asus_laptop
sudo rm /sys/class/backlight/asus_laptop

Going right into directory and typing rm asus_laptop, changing ownership and using Thunar to try to remove it.

I get

rm: cannot remove '/sys/class/backlight/asus_laptop': Operation not permitted

Same goes for unlink, rmdir doesn't work, and Thunar fails.

The permissions on it are lrwxrwxrwx

How can I remove it?

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
Jzuken
  • 203
  • 2
  • 4
  • 1
    It is the permission on the directory, that matters when removing a file. However `/sys` is special, I don't know if you can add or remove files. – ctrl-alt-delor Dec 02 '18 at 17:13

1 Answers1

28

The sysfs file system, typically mounted on /sys, just like the /proc file system, isn’t a typical file system, it’s a so called pseudo file system. It’s actually populated by the kernel and you can’t delete files directly.

So, if the ASUS laptop support isn’t appropriate for you, then you have to ask the kernel to remove it. To do so, remove the corresponding module:

sudo rmmod asus-laptop

That will remove the relevant /sys entry.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Small note: Some files can be removed, what triggers certain actions. I am not sure which ones are there in sysfs, but e.g. cgroupfs allows creating/removing cgroups with mkdir and rm. – allo Dec 03 '18 at 09:36
  • 3
    @allo the distinction is subtle, but cgroupfs as its name suggests is a different file system. sysfs, which is mounted on `/sys`, only supports reads and writes, it doesn’t support deletion. – Stephen Kitt Dec 03 '18 at 09:44
  • 1
    @StephenKitt: If I as a kernel module writer wanted to add something to /sys I could very well provide my own directory node that has delete wired up. Create gives me the shivers though. mknod() is a special call after all. – Joshua Dec 03 '18 at 18:30
  • @Joshua now you’ve got me intrigued — how would you go about that, without mounting a new kernfs (so no `kernfs_create_root`) or any other fs? – Stephen Kitt Dec 03 '18 at 19:28
  • Modules can add arbitrary nodes to sysfs and procfs with their own vfs handlers. – Joshua Dec 03 '18 at 19:35
  • @Joshua without registering a new file system? I know about `sysfs_create_mount_point` etc.; but how can you register arbitrary `inode_operations` on a node under sysfs without using that? – Stephen Kitt Dec 03 '18 at 21:56
  • There ain't no rule that all nodes in a filesystem have the same vfs operation endpoints. I went wading through the code a long time ago for my master's thesis. It's possible to pull this off, but the unlink() comes from the directory so you have to register a directory node to do it. – Joshua Dec 04 '18 at 00:36