2014年11月17日月曜日

gentooをsystemd化する

最近、systemdが流行ってるのか


ここ最近、DVDが見たいがために(決してイヤらしいものではありません...)いろいろなディストリビューションのGUIな環境を試してみたものの全てダメで自分の技術力のなさに打ちひしがれていました。
しかし、どのディストリビューションもディフォルトでsystemd化されていて、

「色々な意見が見られますが、時代はsystemdへ行ってしまっているのかな?」

なんか感じてしまい、まぁ、cgroupとかgnome3なんか既にsystemdが必須と言われますし、LXCとか、dockerとか巷ではコンテナ仮想化とかやってないと、JKとかに人気ないとか、若手SEの糸に言われるので、gentooユーザーの私は

「是非、僕のgentooをsystemdにしたい」

と思いまして、面倒だったのですがやってみました。

systemdインストール開始


systemdが利用できるLinux kernelは2.6.39、gccも4.6以上を要求されるので先にupdateしておく
vkarimakubo ~ # emerge -pv gcc glibc

必要なもの

  • kernel 2.6.39以上
  • gcc 4.6以上
  • glibc 2.19以...曖昧
とにかく時間がかかる...
Linux vkarimakubo 2.6.36-gentoo-r8 #1 SMP Tue Jul 9 20:14:27 JST 2013 x86_64 Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz GenuineIntel GNU/Linux
2.6.36ではダメダメです...
vkarimakubo ~ # emerge -pv gentoo-sources
sys-kernel/gentoo-sources-3.16.5:3.16.5 [2.6.36-r8:2.6.36-r8, 3.1.6:3.1.6] USE="-build -deblob -experimental -symlink" 78,854 kB
vkarimakubo ~ # emerge gentoo-sources

あとはカーネルを再度ビルドする、その時にカーネルの設定を一部しておく。

* systemd系オプション

このオプションを指定するとsystemd関連のカーネルオプションが有効になります...知りませんでしたw
Gentoo Linux  --->
     [*] Gentoo Linux support (NEW)
     [*]   Linux dynamic and persistent device naming (userspace devfs) support
         Support for init systems, system and service managers
             [*] OpenRC, runit and other script based systems and managers (NEW)
             [*] systemd

* 追加設定

cgroupの設定
General setup --->
    Control Group support
        [ ]   Example debug cgroup subsystem (NEW)
        [*]   Freezer cgroup subsystem
        [*]   Device controller for cgroups
        [*]   Cpuset support
        [*]   Include legacy /proc//cpuset file (NEW)
        [*]   Simple CPU accounting cgroup subsystem
        [*]   Resource counters
        [*]     Memory Resource Controller for Control Groups
        [*]       Memory Resource Controller Swap Extension
        [*]         Memory Resource Controller Swap Extension enabled by default (NEW)
        [*]       Memory Resource Controller Kernel Memory accounting
        [ ]     HugeTLB Resource Controller for Control Groups (NEW)
        [ ]   Enable perf_event per-cpu per-container group (cgroup) monitoring (NEW)
        [*]   Group CPU scheduler  --->
        [*]   Block IO controller
        [ ]     Enable Block IO controller debugging (NEW)
    Namespaces support
        [*]   UTS namespace (NEW)
        [*]   IPC namespace (NEW)
        [*]   User namespace (NEW)
        [*]   PID Namespaces (NEW)
        -*-   Network namespace
* CONFIG_UEVENT_HELPER_PATHを空に設定

systemdパッケージをインストールするさイに以下のエラーが出る場合「path to uevent helper」を未設定にしておく
..

 * It's recommended to set an empty value to the following kernel config option:
 * CONFIG_UEVENT_HELPER_PATH="/sbin/udevadm"
なので
Device Drivers  --->
   Generic Driver Options  --->
     [*] Support for uevent helper (NEW)
       ()    path to uevent helper
これでカーネルをビルドし直しなおす。
vkarimakubo ~ # cd /usr/src/linux
vkarimakubo ~ # make -j6
vkarimakubo ~ # make_modules install
vkarimakubo ~ # make install

* grubの設定を忘れずに..

grub.confを書き換え、grub2もだいたい同じです
default 0
timeout 30
splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title Gentoo Linux x86_64-2.6.36-gentoo-r8
root (hd0,0)
kernel /boot/kernel-genkernel-x86_64-2.6.36-gentoo-r8 root=/dev/ram0 real_root=/dev/sda1
initrd /boot/initramfs-genkernel-x86_64-2.6.36-gentoo-r8

title Gentoo Linux x86_64-3.16.5-gentoo-r8
root (hd0,0)
kernel /boot/vmlinuz-3.16.5-gentoo root=/dev/sda1

systemd化していく


make.confのUSEフラグへsystemdを追加
...
USE="mmx sse sse2 systemd -doc -X -qt -qt2 -qt3 -at4 -gtk -gtk2 -gtk3 -kde -gnome"
...
vkarimakubo ~ # emerge -pv systemd

 * IMPORTANT: config file '/etc/portage/repos.conf/gentoo.conf' needs updating.
 * See the CONFIGURATION FILES section of the emerge
 * man page to learn how to update config files.

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-util/gperf-3.0.4  961 kB
[ebuild  N     ] sys-libs/libseccomp-2.1.1  USE="-static-libs" 111 kB
[ebuild     U  ] sys-devel/automake-wrapper-9 [7] 0 kB
[ebuild     U  ] sys-apps/kmod-18-r1 [13-r1] USE="tools zlib -debug -doc -lzma -python% -static-libs" PYTHON_TARGETS="python2_7%* python3_3%* (-python3_2) -python3_4%" 1,440 kB
[ebuild  NS    ] app-text/docbook-xml-dtd-4.4-r2:4.4 [4.3-r1:4.3] 94 kB
[ebuild  NS    ] app-text/docbook-xml-dtd-4.2-r2:4.2 [4.3-r1:4.3] 77 kB
[ebuild     U  ] sys-kernel/linux-headers-3.13 [2.6.39] 3,606 kB
[ebuild  N     ] dev-perl/XML-Parser-2.410.0-r2  233 kB
[ebuild  NS    ] sys-devel/automake-1.13.4:1.13 [1.11.1:1.11, 1.12.6:1.12] 1,416 kB
[ebuild  N     ] app-text/xmlto-0.0.25  USE="-latex" 114 kB
[ebuild     U  ] sys-apps/attr-2.4.47-r1 [2.4.46] USE="nls -static-libs" ABI_X86="(64%*) (-32) (-x32)" 336 kB
[ebuild  N     ] dev-util/intltool-0.50.2-r1  186 kB
[ebuild  N     ] sys-libs/libcap-2.22-r2  USE="pam" ABI_X86="(64) (-32) (-x32)" 59 kB
[ebuild  N     ] sys-apps/systemd-215-r3:0/2  USE="acl firmware-loader kmod pam seccomp -audit -cryptsetup -doc -elfutils -gcrypt -gudev -http -introspection (-kdbus) -lzma -policykit -python -qrcode (-selinux) (-ssl) {-test} -vanilla" ABI_X86="(64) (-32) (-x32)" PYTHON_SINGLE_TARGET="python2_7 (-python3_2) -python3_3 -python3_4" PYTHON_TARGETS="python2_7 python3_3 (-python3_2) -python3_4" 2,821 kB
[ebuild  N     ] sys-apps/gentoo-systemd-integration-4  52 kB
[ebuild  N     ] sys-apps/dbus-1.8.8  USE="systemd -X -debug -doc (-selinux) -static-libs {-test}" ABI_X86="(64) (-32) (-x32)" 1,822 kB
[ebuild     U  ] virtual/udev-215 [197-r3] USE="systemd%* (-gudev%) (-hwdb%) (-introspection%) (-keymap%) (-kmod%*) (-selinux%) (-static-libs%)" 0 kB
[ebuild  N     ] sys-apps/hwids-20141010  USE="net pci udev usb" 1,640 kB
[blocks B      ] sys-fs/udev ("sys-fs/udev" is blocking sys-apps/gentoo-systemd-integration-4, sys-apps/systemd-215-r3)
[blocks B      ] =sys-apps/systemd-208:0 required by (virtual/udev-215::gentoo, ebuild scheduled for merge)
    sys-apps/systemd:0= required by (sys-apps/dbus-1.8.8::gentoo, ebuild scheduled for merge)
    systemd
    >=sys-apps/systemd-207 required by (sys-apps/gentoo-systemd-integration-4::gentoo, ebuild scheduled for merge)

  (sys-apps/kmod-18-r1::gentoo, ebuild scheduled for merge) pulled in by
    sys-apps/kmod required by @selected
    sys-apps/kmod[tools] required by (virtual/modutils-0::gentoo, installed)
    >=sys-apps/kmod-15:0= required by (sys-apps/systemd-215-r3::gentoo, ebuild scheduled for merge)
    >=sys-apps/kmod-13 required by (sys-fs/udev-204::gentoo, installed)


For more information about Blocked Packages, please refer to the following
section of the Gentoo Linux x86 Handbook (architecture is irrelevant):

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?full=1#blocked

 * IMPORTANT: 17 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.

vkarimakubo ~ #

openrcとかudevまわりで、インストール順などで文句を言われるのでそれぞれで対応する、意外と焦るメッセージとか出してくるので何とか耐える 面倒なので一時的にudevなどを削除する、ここで再起動すると悲惨な事になるので注意。 面倒なのでこうしてます、起動しなくなる可能性がございますのでパッケージの削除は計画的に... (笑)
vkarimakubo ~ # emerge -C sys-fs/udev
 * This action can remove important packages! In order to be safer, use
 * `emerge -pv --depclean ` to check for reverse dependencies before
 * removing packages.


!!! 'sys-fs/udev' (virtual/dev-manager) is part of your system profile.
!!! Unmerging it may be damaging to your system.

>>> Waiting 10 seconds before starting...
>>> (Control-C to abort)...
Press Ctrl-C to Stop in: 10 9 8 7 6 5 4 3 2 1

 sys-fs/udev
    selected: 204
   protected: none
     omitted: none

All selected packages: sys-fs/udev-204

>>> 'Selected' packages are slated for removal.
>>> 'Protected' and 'omitted' packages will not be removed.

>>> Waiting 5 seconds before starting...
>>> (Control-C to abort)...
>>> Unmerging in: 5 4 3 2 1
>>> Unmerging (1 of 1) sys-fs/udev-204...
<<< !needed  sym /lib64/libkmod.so.2
<<< !needed  obj /lib64/libkmod.so.2.2.3

 * GNU info directory index is up-to-date.

 * IMPORTANT: 3 config files in '/etc' need updating.
 * See the CONFIGURATION FILES section of the emerge
 * man page to learn how to update config files.

 * IMPORTANT: 17 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.

vkarimakubo ~ #
* ちなみにその他一時削除したパッケージは... あぶない!
vkarimakubo ~ # emerge -C sys-apps/kmod virtual/modutils
これでsystemをビルドする
vkarimakubo ~ # emerge systemd

* grubの設定

再起動する前に、grub.confのカーネルパラメータを若干修正する、「init=/usr/lib/systemd/systemd」を追加
# This is a sample grub.conf for use with Genkernel, per the Gentoo handbook
# http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=10#doc_chap2
# If you are not using Genkernel and you need help creating this file, you
# should consult the handbook. Alternatively, consult the grub.conf.sample that
# is included with the Grub documentation.

default 0
timeout 30
splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title Gentoo Linux x86_64-2.6.36-gentoo-r8
root (hd0,0)
kernel /boot/kernel-genkernel-x86_64-2.6.36-gentoo-r8 root=/dev/ram0 real_root=/dev/sda1
initrd /boot/initramfs-genkernel-x86_64-2.6.36-gentoo-r8

title Gentoo Linux x86_64-3.16.5-gentoo-r8
root (hd0,0)
kernel /boot/vmlinuz-3.16.5-gentoo root=/dev/sda1 init=/usr/lib/systemd/systemd
# vim:ft=conf:

iproute2をいれておく


ifconfigでもいいのですがipコマンドなどを後で利用するので入れておく
vkarimakubo ~ # emerge -pv sys-apps/iproute2

 * IMPORTANT: config file '/etc/portage/repos.conf/gentoo.conf' needs updating.
 * See the CONFIGURATION FILES section of the emerge
 * man page to learn how to update config files.

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] net-firewall/iptables-1.4.21-r1  USE="ipv6 -netlink -static-libs" 535 kB
[ebuild  N     ] sys-apps/iproute2-3.8.0  USE="berkdb iptables ipv6 -atm -minimal" 399 kB

Total: 2 packages (2 new), Size of downloads: 933 kB

 * IMPORTANT: 20 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.

vkarimakubo ~ # emerge sys-apps/iproute2
rebootする
vkarimakubo ~ # reboot

ネットワークを設定する


とりあえず手動で設定しておく
vkarimakubo ~ # ip link set dev enp2s1 up
vkarimakubo ~ # ip addr add 192.168.254.77/24 broadcast 192.168.254.255 dev enp2s1
vkarimakubo ~ # ip route add default via 192.168.254.1
とりあえず必要なものをsystemd対応にしておく
vkarimakubo ~ # emerge net-misc/openssh
vkarimakubo ~ # emerge app-admin/syslog-ng
vkarimakubo ~ # systemctl enable sshd
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib64/systemd/system/sshd.service.
vkarimakubo ~ # systemctl start sshd
vkarimakubo ~ #  systemctl enable syslog-ng
Created symlink from /etc/systemd/system/syslog.service to /usr/lib64/systemd/system/syslog-ng.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/syslog-ng.service to /usr/lib64/systemd/system/syslog-ng.service.
vkarimakubo ~ #  systemctl start syslog-ng

起動時にネットワークIPが有効になるように設定


systemdのUNITを作成
* network@.serviceファイル
[Unit]
Description=Network connect (%i)
Wants=Network.target
Before=Network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network@%i

ExecStart=/bin/ip link set dev %i up
ExecStart=/bin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev %i
ExecStart=/bin/sh -c 'test -n ${gateway} && /bin/ip route add default via ${gateway}'

ExecStop=/bin/ip addr flush dev %i
ExecStop=/bin/ip link set dev %i down

[Install]
WantedBy=multi-user.target

* network@enp2s1ファイル 「enp2s1」の部分は実際のデバイス名にしてください
address=192.168.254.77
netmask=24
broadcast=192.168.254.255
gateway=192.168.254.1

* IP有効化
vkarimakubo ~ # systemctl enable network@enp2s1
vkarimakubo ~ # systemctl start network@enp2s1

その他の設定

* ロケールとキーボード設定
vkarimakubo ~ # localectl set-locale LANG=ja_JP.utf-8
vkarimakubo ~ # localectl set-keymap jp106
vkarimakubo ~ # localectl
   System Locale: LANG=ja_JP.utf-8
       VC Keymap: jp106
      X11 Layout: jp
       X11 Model: jp106
     X11 Options: terminate:ctrl_alt_bksp
vkarimakubo ~ # 
* ホスト名設定
vkarimakubo ~ # hostnamectl set-hostname vkari
とりあえずここでreboot
vkarimakubo ~ # reboot
こんな感じでsystemdへ移行できます、結構面倒くさい、なので素直にRedhatとかCentOSとかを使いましょう。笑...

0 件のコメント:

コメントを投稿