How can I know that a (Bash) script from /etc/initramfs-tools/scripts/init-premount is…
- User
How can I know that a (Bash) script from /etc/initramfs-tools/scripts/init-premount is being run or not (in Debian GNU/Linux)?
- Assistant
There are a few ways to determine if a bash script from /etc/initramfs-tools/scripts/init-premount is being run or not in Debian GNU/Linux:
-
Check if the script is enabled: You can verify that the script is enabled and will run during the initramfs stage by inspecting the symlinks in the /etc/initramfs-tools/conf.d/ directory. Look for a symlink with a name that starts with "resume_" followed by a number. For example, "resume_1" or "resume_9". If the script is enabled, you will likely find a symlink named "resume_0", which points to /etc/initramfs-tools/scripts/init-premount. If the symlink is present, it means the script is being run during the initramfs stage.
-
- User
Redo that answer more concisely.
- Assistant
To determine if a bash script from /etc/initramfs-tools/scripts/init-premount is being run in Debian GNU/Linux:
-
Check if the script is enabled: Look for a symlink named "resume_0" in /etc/initramfs-tools/conf.d/. If it exists and points to the script, it means it is enabled.
-
Check the script existence: Use the
lscommand to verify that the script /etc/initramfs-tools/scripts/init-premount exists. -
Debugging output: Add an echo statement at the script's beginning to print a message. Reboot the system and check if the message appears during the initramfs stage.
-
Log files: Examine /var/log/boot.log and /var/log/syslog for any log entries mentioning the script's name.
Using these methods will help you identify if the script is being executed in Debian GNU/Linux.
-
- User
Do I have to enable scripts that I put in /etc/initramfs-tools/scripts/init-premount?
- Assistant
No, scripts that you put in the /etc/initramfs-tools/scripts/init-premount directory do not require any explicit enabling. By default, all scripts in that directory are automatically executed during the initramfs stage.
The initramfs (initial RAM filesystem) is a temporary filesystem loaded during boot before the actual root filesystem is available. During this stage, scripts in the /etc/initramfs-tools/scripts/init-premount directory are executed to perform necessary tasks before mounting the root filesystem.
Therefore, any script you place in that directory will be executed without needing any additional enabling steps. Just make sure the script has the correct permissions and the necessary shebang (e.g., #!/bin/bash) at the beginning to ensure it is interpreted correctly.
- User
What's the most restrictive permissions that would work?
- Assistant
The most restrictive permissions that would work for a script in the /etc/initramfs-tools/scripts/init-premount directory would be 0700.
To set the permissions to 0700, you can use the chmod command as follows:
codesudo chmod 0700 /etc/initramfs-tools/scripts/init-premount/script.shThis command sets the script.sh file's permissions so that only the file owner has read, write, and execute permissions, while all other users have no permissions.
It is important to ensure that the script is executable for the root user (the owner), as it needs to be executed during the initramfs stage, which runs with root privileges. With the permissions set to 0700, the script will be securely accessible only by the root user and will function as intended.