Sunday, 9 February 2014

Useful Linux stuff (mostly Debian)

Just a collection of useful Linux scripts or commands.

Booting the system to console with grub2

Edit the file /etc/default/grub:
sudo nano /etc/default/grub
Change the line GRUB_CMDLINE_LINUX_DEFAULT to include "text":
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash text"
Save the file and update grub:
sudo update-grub
Reboot.

Auto-login user on console tty1 after boot

Edit the file /etc/init/tty1.conf:
sudo nano /etc/init/tty1.conf
Replace the "exec" line with this:
exec /bin/login -f USERNAME < /dev/tty1 > /dev/tty1 2>&1
replacing USERNAME with you user name. Snatched from here.

Use .bash_profile to start a program when user logs in

Edit the file ~/.bash_profile (create if it doesn't exist):
nano ~/.bash_profile
Here's a script template:
if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then
  exec su -c "xinit PATH_TO_EXECUTABLE --standalone -- -nocursor :0" USERNAME
fi
replacing USERNAME with you user name. Snatched from here.

Use upstart to start a program using on login

Create a new script file file in /etc/init/, e.g.
sudo nano /etc/init/SCRIPTNAME.conf
Here's a script template:
# Starts a program on startup by using xinit.
# Change USERNAME to your user name below and
# PATH_TO_EXECUTABLE to the executable you want to run.

env USER=USERNAME

description "EXECUTABLE-upstart-script"
author "You"

start on (filesystem and stopped udevtrigger)
stop on runlevel [016]

# tell upstart to respawn the process if abnormal exit
respawn

script
  exec su -c "xinit PATH_TO_EXECUTABLE --standalone -- -nocursor :0" $USER
end script
Note: -- -nocursor option kills all X cursor on XBMC startup and does not interfere with mouse use/operation

Allow all users to start X from the console

Edit /etc/X11/Xwrapper.config and replace the last line that says:
allowed_users=console
by
allowed_users=anybody
Found here.

Force a monitor resolution in X

Edit /usr/share/X11/xorg.conf.d/modes.conf or create it if it doesn't exist. Add the mode you want to use:
Section "Monitor"
  Identifier "HDMI1"
  Option "PreferredMode" "1024x768"
EndSection
where HDMI1 is the port the monitor is on and 1024x768 the preferred resolution.

Allow a non-root user to shutdown/restart

Edit /etc/group and add a line that says:
shutdown:x:NUMBER:USERNAME
Where NUMBER is an unused number (usually > 1000) and USERNAME is the user you want to grant the permission. USERNAME can now do e.g. shutdown -h now or shutdown -r now.

Rescuing deleted files in Linux

How-To in another post here.

Switching GCC/G++ compiler versions

How-To in another post here.

Using find and hide error messages

How-To in another post here.

No comments:

Post a Comment