0

I'm experiencing new "glitch". When I try to run scripts via keyboard shortcut in Cinnamon (Linux Mint 21) there is a window with error:

scriptname failure to remap file to open file descriptor (no such file or directory).

Interestingly web search had not found exact error, so I post the question in hope of learning more about Linux system I'm using. Then I was able to run scriptname from bash terminal which I had opened before "glitch" running my chroot script.

Also most GUI apps do not start. Making new tab in terminal results in tab with:

failed to open PTY no such file or directory.

That pointed me to discover that many of files in /dev are gone. I've been doing script with chroot and that script was run many times before with slight changes, it unmounted and deleted files in chrooted temp working folder, why files in root /dev got deleted? I still have not understood.

I'd like to know how to restore full functionality w/out reboot. Looks like quick restore of /dev is not available, from this answer

"With devtmpfs, the only automated method might be a reboot.

What files do you advise me to make manually in /dev?

Also, any ideas for "failure to remap file" error? TIA

P.S. Ah, one more thing. After I've discovered the glitches above I've tried to start new console via Ctrl+Alt+Fx (with PTY errors, wasn't it foolish?), got blinking prompt, switched back and now my keyboard/trackpad do not work. I've got idea to connect externals via USB and they work. Ideas how to restart laptop's keyboard?

10
  • Difficult to give advice for a manual fix when we don't know what your script does, how you ran it or what exactly happened. Reinstalling the system would be the safest way. Or boot a rescue system and compare your /dev with a fresh install. "failure to remap file to open file descriptor" might be an error message for a failed freopen. Unfortunately it doesn't tell you the file name that does not exist. (Maybe you should not run commands as root unless absolutely necessary. Maybe insufficient error handling or preconditions checking in your script.)
    – Bodo
    Commented Feb 8, 2023 at 9:48
  • @Bodo, the script before slight modifications is in public github repo (github.com/mars4science/…, _make_custom_liveusb.sh), apart from changes which I had not thought important for mount(s). I have a suspicion added rsync -a /folderX /folderY of a location of a mount (mount ... /folderX) might somehow messed things up. Commented Feb 8, 2023 at 11:01
  • @Bodo, another unusual thing is I stopped the script process in system monitor GUI. Might close terminal window in unusual time of script working (though been closing before finish many times before). BTW System Monitor window closed "by itself". Commented Feb 8, 2023 at 11:08
  • Please add all information to the question by editing it. I don't have the time to fully analyze the script, but I think it lacks error handling and can run commands (as root) even if a previous command failed which may lead to unexpected results. You don't know what all went wrong and what all got deleted or overwritten. I suggest to back up your data and reinstall and be more cautious when running scripts that execute commands as root.
    – Bodo
    Commented Feb 8, 2023 at 12:26
  • @Bodo, thanks for trying to help, I was able to reproduce the problem (no idea how the script did it though) and how to fix it with couple of commands. Wrote an answer just in case for posterity. Commented Feb 8, 2023 at 14:04

2 Answers 2

1

All symptoms were reproduced on a newly booted (from liveUSB) system after running

sudo rm -R /dev

Running GUI apps and keyboard shortcuts were restored after

# mknod -m 666 /dev/null c 1 3 

So many applications need null! Only Baobab (disk usage analyzer) and dconf editor started w/out it (from about ten I've tried).

Working new tabs for terminal were (independently from null) restored after

# mknod -m 666 /dev/ptmx c 5 2

Those useful commands are from https://tldp.org/LDP/lfs/LFS-BOOK-6.1.1-HTML/chapter06/devices.html "Linux From Scratch - Version 6.1.1, 6.8. Populating /dev".

2
  • But starting the other console (ctrl-alt-fx) still did not work, even after adding console and tty devices as per the linked LFS page. Commented Feb 8, 2023 at 14:14
  • Root cause identified: During investigation I was surprised to find out even changing file permissions for a file on devtmpfs changes corresponding file permissions on other devtmpfs-es on the system. Deleting files also. So I understood the script deleting files in working folder copy of devtmpfs deleted also files in /dev. Commented Feb 9, 2023 at 2:36
0

Completely power off your system by pressing the power off key on your keyboard. I had the exact same problem as you. Then turn on your system and boot into your OS. This restored all my /dev files and other deleted files. (note that this was caused by running rm -rf /* in my chroot environment and linking the /dev, /sys, and /proc directories)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .