Archlinux从initscripts sysvinit迁移到了systemd

Archlinux 2012.12.01 新的安装介质已经默认切换到systemd了。
还有就是官方已经宣布停止对initscripts 的支持了。
Goodbye initscripts ~~

还有就是,我的Archlinux,自从ConsoleKit replaced by systemd-logind后,右上角的reboot ,shutdown 终于不是灰色的。

Archlinux 官方的wiki非常地详细,可以说这次迁移我虽然遇到一些小麻烦,不过都一一搞定了。
systemd wiki: https://wiki.archlinux.org/index.php/Systemd
这里有关于systemd及迁移的详细介绍。

由于我的archlinux已经相当长一段时间没有升级了,因此,首先是升级一下软件。
然后,把rc.conf 文件修改到最新版
可以按照这里修改:https://wiki.archlinux.org/index.php/Initscripts/rc.conf

我之前的rc.conf :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
└─[$] <> cat rc.conf.orig  
#
# /etc/rc.conf - Main Configuration for Arch Linux
#

# -----------------------------------------------------------------------
# LOCALIZATION
# -----------------------------------------------------------------------
LOCALE="en_US.UTF-8"
HARDWARECLOCK="localtime"
TIMEZONE="Asia/Chongqing"
KEYMAP="us"
CONSOLEFONT=
CONSOLEMAP=
USECOLOR="yes"

# -----------------------------------------------------------------------
# HARDWARE
# -----------------------------------------------------------------------
#
# MOD_AUTOLOAD: Allow autoloading of modules at boot and when needed
# MOD_BLACKLIST: Prevent udev from loading these modules
# MODULES: Modules to load at boot-up. Prefix with a ! to blacklist.
#
# NOTE: Use of 'MOD_BLACKLIST' is deprecated. Please use ! in the MODULES array.
#
MOD_AUTOLOAD="yes"
#MOD_BLACKLIST=() #deprecated
MODULES=(fuse acpi-cpufreq)

# Scan for LVM volume groups at startup, required if you use LVM
USELVM="no"

# -----------------------------------------------------------------------
# NETWORKING
# -----------------------------------------------------------------------
#
# HOSTNAME: Hostname of machine. Should also be put in /etc/hosts
#
HOSTNAME="HuangYe"

# Use 'ifconfig -a' or 'ls /sys/class/net/' to see all available interfaces.
#https://wiki.archlinux.org/index.php/Configuring_Network
#https://wiki.archlinux.org/index.php/Internet_Share
#https://wiki.archlinux.org/index.php/Internet_Share

lo="lo 127.0.0.1"

INTERFACES=(lo eth0 eth0_0)

gateway="default gw 172.30.16.254"
ROUTES=(gateway)

#NETWORKS=(main)

# -----------------------------------------------------------------------
# DAEMONS
# -----------------------------------------------------------------------

DAEMONS=(syslog-ng @acpid dbus cpufreq_ondemand cpufreq_powersave cpufreq iptables network @sshd !netfs crond alsa !mysqld !httpd sensors)

按照官方的说明,新的rc.conf已经被分解为N多个文件了:

Configuration Configuration file(s) or tool Legacy rc.conf section
Hostname /etc/hostname NETWORKING
Console fonts and keymap /etc/vconsole.conf LOCALIZATION
Locale /etc/locale.conf

/etc/locale.gen

LOCALIZATION
Timezone /etc/localtime LOCALIZATION
Hardware clock /etc/adjtime LOCALIZATION
Kernel modules /etc/modules-load.d/ HARDWARE
Daemons systemctl tool DAEMONS
Static network /etc/conf.d/network NETWORKING

LOCALIZATION 部分:
LOCALE="en_US.UTF-8"
└─[$] <> cat locale.conf
LANG=en_US.UTF-8

Run locale-gen to update changes. The system-wide locale can be set in /etc/locale.conf.

HARDWARECLOCK="localtime" => /etc/adjtime
关于hwclock方面,Archlinux建议使用UTC

There are two time standards: localtime and Coordinated Universal Time (UTC). The localtime standard is dependent on the current time zone, while UTC is the global time standard and is independent of time zone values. Though conceptually different, UTC is also known as GMT (Greenwich Mean Time).
The standard used by hardware clock (CMOS clock, the time that appears in BIOS) is defined by the operating system. By default, Windows uses localtime, Mac OS uses UTC, and UNIX-like operating systems vary. An OS that uses the UTC standard, generally, will consider CMOS (hardware clock) time a UTC time (GMT, Greenwich time) and make an adjustment to it while setting the System time on boot according to your time zone.
When using Linux it is beneficial to have the hardware clock set to the UTC standard and made known to all operating systems. Defining the hardware clock in Linux as UTC means that Daylight Saving Time will automatically be accounted for. If using the localtime standard the system clock will not be changed for DST occurrences assuming that another operating system will take care of the DST switch (and provided no NTP agent is operating).

而我之前一直是按windows的,使用localtime.

TIMEZONE="Asia/Chongqing"
/etc/localtime 链接到 /usr/share/zoneinfo/Asia/Chongqing 即可。

剩下的
KEYMAP="us"
CONSOLEFONT 变为了FONT
CONSOLEMAP 变为了 FONT_MAP
USECOLOR="yes" 已经被废弃
在vconsole.conf 中配置:

1
2
3
4
└─[$] <> cat vconsole.conf
KEYMAP="us"
FONT=
FONT_MAP=

HARDWARE 部分
主要是开机自动启用和禁用的模块
新的配置应该放在/etc/modules-load.d下面,在配置文件中只要一行一个简单地写上之前的module即可。
我这里自动加载的模块主要是

1
2
3
4
5
6
[admin@HuangYe] - [/etc/modules-load.d] - [Mon Dec 03, 12:42]
└─[$] <> cat modules-autoload.conf
fuse
acpi-cpufreq
vboxdrv
vboxnetflt

HOSTNAME 被配置在 /etc/hostname
我的网络连接配置都是用net-profiles管理了。因此,没有必要在rc.conf 配置。

然后就是DAEMONS了。
新版的rc.conf (在initscripts下时)还是保持没变的。
做完这些调整,然后重启。
OK,一切正常。
======================================================

需要注意的事项:
sysetmd 有它自己的日志系统用于替换 syslog,不过这二者是可以并存的。
尽管systemd 可以替换cron, acpid, or xinetd的部分功能,但没有必要从传统的daemon切换到systemd,除非你愿意那么做。
交互式initscripts在systemd下是不能工作的。特别是netcfg-menu无法在系统启动时运行。这一点有点点蛋痛了。
Note: systemd and systemd-sysvcompat are both installed by default on installation media newer than 2012-10-13.
安装systemd ,这个已经没必要做了,因为系统更新时已经安装好了。
只需要把init=/usr/lib/systemd/systemd 这一句加到kernel 命令行
由于我是用的grub2 ,因此:
sudo vim /etc/default/grub
把 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" 修改为:

1
GRUB_CMDLINE_LINUX_DEFAULT="init=/usr/lib/systemd/systemd"

更新grub2配置:

1
sudo grub-mkconfig -o /boot/grub/grub.cfg

然后运行systemctl enable 来启动需要启用的daemon.
这些名字可能与原来在rc.conf中的名字不同。
查看Daemons List 可以找到你需要的信息。
我目前启用的:

1
2
3
4
5
6
HuangYe# pwd
/etc/systemd/system/multi-user.target.wants
HuangYe# ls
cpupower.service  lm_sensors.service         netcfg.service    remote-fs.target
dnsmasq.service   net-auto-wired.service     ntpd.service      sshd.service
iptables.service  net-auto-wireless.service  openntpd.service

关于运行 systemctl enable dbus.service ,systemctl enable alsa-store.service, systemctl enable alsa-restore.service 时提示:
The unit files have no [Install] section. They are not meant to be enabled using systemctl.
原因:默认已经被systemd启用了。they are not meant to be enabled because they are already enabled by default (=static).
问题见:https://bbs.archlinux.org/viewtopic.php?id=146794

好了,做完这些,重启系统。
到挂载ntfs分区时,sda1 (我win7在的那个分区)无法挂载。
然后,还提示找不到 fsck.ntfs-3g
后来发现不知道什么原因,sda1 的uuid改变了。。。而我在 /etc/fstab 中填写的自动挂载参数是指定的uuid.
找不到 fsck.ntfs-3g 这个错误的原因是systemd试图对ntfs分区执行 fsck ...
把 /etc/fstab 挂载ntfs分区那几行的第6个参数修改为0 ,搞定这个错误。
好了,终于顺利启动了。
查看下systemd是否处于活动状态:

1
cat /proc/1/comm

返回systemd 字符.
好了,现在可以卸载initscripts and sysvinit了。

1
2
pacman -R initscripts sysvinit
pacman -S systemd-sysvcompat

好了,现在可以选择从 kernel command line 中移除 init=/usr/lib/systemd/systemd 了,因为systemd-sysvcompat提供了默认的init.
关于 Display Manager,我目前用的是slim.安装archlinux官方版的slim,默认会提供有 slim.service的。
只需要执行 systemctl enable slim.service 即可。
再重启~~
一切看上去似乎是正常的。只是我的rc.local文件在卸载时被删除了。。。Orz

=============================================
一些配置的调整
由于systemd下无法运行netcfg-menu,因此,我把netcfg配置文件修改为了开机自动使用上一次的配置profile,修改/etc/conf.d/netcfg:
NETWORKS=(last)
配置netcfg 添加要自动尝试连接的无线连接:
AUTO_PROFILES="wireless-wpa android-ap"
在要自动选择的有线连接的profile中添加 AUTO_WIRED=1

扩展阅读:
https://wiki.archlinux.org/index.php/Systemd#Writing_custom_.service_files

https://wiki.archlinux.org/index.php/Time#Hardware_clock_and_system_clock

https://wiki.archlinux.org/index.php/Initscripts/rc.conf#New_configuration_file

https://wiki.archlinux.org/index.php/Netcfg

https://wiki.archlinux.org/index.php/Kernel_line

https://wiki.archlinux.org/index.php/NTP#Configuring_connection_to_NTP_servers

fedora 关于systemd的介绍:
https://fedoraproject.org/wiki/Systemd/zh-cn
https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet/zh

更多
2 Responses Post a comment

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS