Sunday, March 17, 2013

Run own script on Linux startup


Run own script on Linux startup
Environment: Ubuntu 12.04

Reference Link:
https://help.ubuntu.com/community/UbuntuBootupHowto


Make the script executable
#sudo chmod +x /etc/init.d/myscript.sh

Make the script run on startup
#sudo update-rc.d myscript.sh defaults 98 02

98 is the start sequence numbers
02 is stop sequence numbers

Both are numbers between 00 and 99
Specify how early or late a service is started or killed.

 

Sunday, March 10, 2013

Auto Login in Console Mode


Auto Login in Console Mode

Environment: Ubuntu 12.04

/* ------------------------------------------------------------Method 1

Install mingetty
#sudo apt-get install mingetty

open the tty1 conf
#sudo nano /etc/init/tty1.conf

modify the following lines:
From:
exec /sbin/getty -8 38400 tty1
To:
exec /sbin/mingetty --autologin root --noclear tty1

reboot
#sudo reboot
/* ------------------------------------------------------------End of Method 1

/* ------------------------------------------------------------Method 2

Install package
#sudo apt-get install xorg nodm

Enable Auto Login
#sudo nano /etc/default/nodm


modify the following lines:
NODM_ENABLED = true
NODM_USER = root
PS: NODM_USER is the user you want to login automatically when startup

/* ------------------------------------------------------------End of Method 2

延伸閱讀
What is getty?
wiki :  http://en.wikipedia.org/wiki/Getty_%28Unix%29
按wiki的解說,就是 "get teletype", a utility call by "init", invoke login.

而 teletype 大慨是 teletypewriter / terminal
wiki: http://en.wikipedia.org/wiki/Tty_%28Unix%29


簡單說, 就是在startup的過程裏, 會call這個getty 進行登入程序... 如果要設定成自動登入就得使用mingetty 來取代原本的getty.

那麼甚麼是 mingetty?
根據網上解釋 就是 designed to be a minimal getty for the virtual terminals on the the workstation's monitor and keyboard.

不求甚解下, 總之auto login 就用 mingetty 攪定吧.

mingetty -options as below:

--noclear
Do not clear the screen before prompting for the login name (the screen is normally cleared).
--nonewline
Do not print a newline before writing out /etc/issue.
--noissue
Do not output /etc/issue.
--nohangup
Do not call vhangup() to disable writing to this tty by other applications.
--nohostname
Do not print the hostname before the login prompt.
--long-hostname
By default the hostname is only printed until the first dot. With this option enabled, the full text from gethostname() is shown.
--loginprog /bin/login
Change the login app.
--nice 10
Change the priority by calling nice().
--delay 5
Sleep this many seconds after startup of mingetty.
--chdir /home
Change into this directory before calling the login prog.
--chroot /chroot
Call chroot() with this directory name.
--autologin username
Log the specified user automatically in without asking for a login name and password. Check the -f option from /bin/login for this.
--loginpause
Wait for any key before dropping to the login prompt. Can be combined with --autologin to save memory by lazily spawning shells.