个人工具

启动

来自Ubuntu中文

1.202.222.147讨论2012年10月2日 (二) 10:22的版本 修改配置文件,原链接已失效

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索

Ubuntu 系统的启动流程、增/删启动项

依赖于图形系统

GUI 设置

点击菜单:System->Preferences ->Sessions,中文为:系统->首选项->启动应用程序.这里设置的是启动图形界面以后自动运行的程序

修改配置文件

进入 ~/.config/autostart 目录 ,创建以名字加.desktop的文件,如: thunderbird.desktop

不依赖于图形系统的

init

Linux 内核启动 init ,init进程ID是1,是所有进程的父进程,所有进程由它控制。

/etc/event.d

Ubuntu 的启动由upstart控制,自9.10后不再使用/etc/event.d目录的配置文件,改为/etc/init。

runlevel

查看当前的运行级别,Ubuntu 桌面默认是2。

runlevel

Ubuntu 的系统运行级别:

0        系统停机状态
1        单用户或系统维护状态
2~5      多用户状态
6        重新启动 
S

切换运行级别,执行命令:

init [0123456Ss]

即在 init 命令后跟一个参数,此参数是要切换到的运行级的运行级代号,如:用 init 0 命令关机;用 init 6 命令重新启动。

/etc/rc2.d

该目录为runlevel=2环境(就是Ubuntu默认情况)的启动项

qii@ubuntu:/etc/rc2.d$ ls
README             S20nginx              S20xinetd      S50rsync      S90binfmt-support  S99grub-common
S19postgresql-8.4  S20speech-dispatcher  S25bluetooth   S50saned      S91apache2         S99ondemand
S20fancontrol      S20wicd               S50cups        S70dns-clean  S91lighttpd        S99rc.local
S20kerneloops      S20winbind            S50pulseaudio  S70pppd-dns   S99acpi-support

其中S表示启动,随后的数字表示启动的顺序。

手动的话将S重命名为K,运行

sudo update-rc.d script defaults

可以禁用某个服务,不过比较麻烦,方便的方法是sysv-rc-conf

runlevel下的增/删

sysv-rc-conf

查看/修改不同运行级别的启动项,可以发现Ubuntu(其实是Debian)2-5之间的runlevel效果是一样的。

sudo apt-get install sysv-rc-conf 
sudo sysv-rc-conf 

update-rc.d

添加启动项,例如mysql

qii@ubuntu:/etc/rc2.d$ sudo update-rc.d mysql defaults 
update-rc.d: warning: /etc/init.d/mysql missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
 Adding system startup for /etc/init.d/mysql ...
   /etc/rc0.d/K20mysql -> ../init.d/mysql
   /etc/rc1.d/K20mysql -> ../init.d/mysql
   /etc/rc6.d/K20mysql -> ../init.d/mysql
   /etc/rc2.d/S20mysql -> ../init.d/mysql
   /etc/rc3.d/S20mysql -> ../init.d/mysql
   /etc/rc4.d/S20mysql -> ../init.d/mysql
   /etc/rc5.d/S20mysql -> ../init.d/mysql

删除启动项

qii@ubuntu:/etc/rc2.d$ sudo update-rc.d -f mysql remove 
 Removing any system startup links for /etc/init.d/mysql ...
   /etc/rc0.d/K20mysql
   /etc/rc1.d/K20mysql
   /etc/rc2.d/S20mysql
   /etc/rc3.d/S20mysql
   /etc/rc4.d/S20mysql
   /etc/rc5.d/S20mysql
   /etc/rc6.d/K20mysql

rcconf

查看,修改当前运行级别的启动项

sudo apt-get install rcconf
sudo rcconf

bashrc

Ubuntu默认shell为bash,.bashrc即为配置文件,在用户输入完用户名和密码后生效,可添加启动项目。

.profile和.xprofile

被KDM读取

/etc/profile

查看KDM读取配置

cat /etc/kde4/kdm/Xsession
[ -f /etc/profile ] && . /etc/profile
    if [ -f $HOME/.bash_profile ]; then
      . $HOME/.bash_profile
    elif [ -f $HOME/.bash_login ]; then
      . $HOME/.bash_login
    elif [ -f $HOME/.profile ]; then
      . $HOME/.profile
    fi
    ;;

查看GDM读取配置

cat /etc/gdm/Xsession
# First read /etc/profile and .profile
test -f /etc/profile && . /etc/profile
test -f "$HOME/.profile" && . "$HOME/.profile"
# Second read /etc/xprofile and .xprofile for X specific setup
test -f /etc/xprofile && . /etc/xprofile
test -f "$HOME/.xprofile" && . "$HOME/.xprofile"

可见GDM会读取.profile和.xprofile配置文件。

autostart

/etc/xdg/autostart
/usr/share/autostart
/usr/share/gdm/autostart
/usr/share/gnome/autostart
~/.config/autostart
~/.kde/share/autostart
~/.local/share/autostart

这些目录下的启动项目是这样的文件(举例)

Launchy.desktop

KDE SC 4系统设置中设定的启动项便是

~/.config/autostart

只在KDE中自动启动,就是设定.desktop文件的字段

OnlyShowIn=KDE;