Debian Liveで軽量なレスキューメディアを作ってみる
サーバーに対して、外部メディアから OS を起動して何らかのメンテナンスをしたいというシチュエーションはよくありますよね。例えばディスクを完全に消去したい場合だとか、設定間違って起動しなくなったので復旧したいとか*1、故障したサーバーからデータを救出したいとか。Knoppix や Xubuntu を使うのもいいのですが、データセンターにあるサーバーに、リモート KVM 越しに起動メディアをマウントして起動するような場合、これらの OS は少々使い勝手がよくありません。デカいので起動に時間もかかりますし、そもそも GUI は不要ですし。
そんなわけで軽量なレスキューメディアが欲しくなりました。そういったディストリも世の中にはあるようですが、せっかくなので live-build を使って Debian をカスタマイズしてみようかと。
Ubuntu 12.04 上で Ubuntu 12.04 をビルドする
live-build は Debian だけでなく、Ubuntu もビルドすることができます。なのでまずは常用している Ubuntu 12.04 上で Ubuntu 12.04 のライブイメージを作成してみることにします。
基本的な使い方。まず以下のパッケージをインストール。
$ sudo apt-get install live-boot live-build live-config
そしたら、ワーキングディレクトリを掘って、config & build。
$ mkdir live $ cd live $ lb config --mode "ubuntu" $ lb config -d "precise" $ lb config -p minimal $ lb config --parent-distribution "precise" $ lb config --parent-archive-areas "main universe" $ lb config --mirror-bootstrap "http://jp.archive.ubuntu.com/ubuntu/" $ lb config --mirror-chroot "http://jp.archive.ubuntu.com/ubuntu/" $ lb config --mirror-binary "http://jp.archive.ubuntu.com/ubuntu/" $ sudo lb build
が、途中でコケる。chroot 環境に live-config を入れようとして止まってるぽい? なんで?
P: Begin installing packages (live pass)... (...略...) The following NEW packages will be installed: casper debian-installer-launcher fontconfig-config iso-codes libexpat1 libfontconfig1 libfontenc1 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libice6 libllvm3.0 libsm6 libutempter0 libx11-6 libx11-data libx11-xcb1 libxau6 libxaw7 libxcb-glx0 libxcb-shape0 libxcb1 libxcomposite1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxft2 libxi6 libxinerama1 libxmu6 libxmuu1 libxpm4 libxrender1 libxt6 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 live-config live-config-upstart live-tools localechooser-data lzma psmisc ttf-dejavu-core uuid-runtime x11-common x11-utils xbitmaps xterm The following held packages will be changed: live-config 0 upgraded, 51 newly installed, 0 to remove and 0 not upgraded. Need to get 19.0 MB of archives. After this operation, 67.8 MB of additional disk space will be used. E: There are problems and -y was used without --force-yes P: Begin unmounting filesystems...
Debian squeeze 上で Debian squeeze をビルドする
どうも live-build 自体がバグってるようなので、そのへんは henrich 先生にお任せして、実績のある squeeze でビルドすることに。squeeze の実機や仮想マシン環境は手元にないので*2、pbuilder-dist で squeeze の chroot 環境を作った上でビルドしています。
$ sudo apt-get install ubuntu-dev-tools $ pbuilder-dist squeeze amd64 create $ pbuilder-dist squeeze amd64 login --save-after-login
lb config
lb config --mode "debian" lb config -d "squeeze" lb config -p minimal lb config --parent-distribution "squeeze" lb config --username future lb config --parent-archive-areas "main non-free contrib" lb config --mirror-bootstrap "http://ftp.jp.debian.org/debian/" lb config --mirror-chroot "http://ftp.jp.debian.org/debian/" lb config --mirror-binary "http://ftp.jp.debian.org/debian/" lb config --mirror-chroot-security "http://security.debian.org" lb config --mirror-binary-security "http://security.debian.org" lb config --mirror-chroot-volatile "http://ftp.jp.debian.org/debian/" lb config --mirror-debian-installer "http://ftp.jp.debian.org/debian/"
追加パッケージリスト
現行の live-build では、config/chroot_local-packageslists/custom.list のようなファイルにパッケージ名を列挙するだけで、パッケージをライブシステムに追加できます。今回追加したのは以下のパッケージ。
byobu bzip2 ca-certificates curl dnsutils dstat ftp isc-dhcp-client less lftp lsb-release lsof lsscsi net-tools nmap ntfs-3g ntpdate openssh-client openssl parted patch procps psmisc stress tcpdump tree unzip vim wget whois zsh
フック
フックを利用することで、ライブシステムに対して様々な調整を行うことができます。ここでは root ユーザーのパスワードと、OpenSSH サーバーのインストールを行っています。追加パッケージでインストールしないのは、SSH サーバーを自動起動しない設定にしたいから。
$ vi config/chroot_local-hooks/10-update_password.sh #!/bin/sh echo "I: update password" echo "root:(パスワード)" | chpasswd
$ vi config/chroot_local-hooks/20-openssh.sh #!/bin/sh echo "HOOK: ssh server" apt-get install --yes --force-yes -y openssh-server update-rc.d -f ssh remove
wget が消されるとかそんな
これでビルドを実行すれば ISO ファイルが作成されるのですが、動作を確認してみると何かおかしい。wget パッケージを入れたはずなのに、command not found になっちゃいます。はて? と clean --all してからもう一度ビルドしてログを確認してみます。すると
Selecting previously deselected package wget. Unpacking wget (from .../wget_1.12-2.1_amd64.deb) ...
パッケージは取ってきてる。
Setting up wget (1.12-2.1) ...
インストールされた。
P: Begin executing hooks... Reading package lists... Building dependency tree... Reading state information... The following packages will be REMOVED: wget* 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded. After this operation, 2421 kB disk space will be freed.
なぜかこの hook で削除候補に。
Removing wget ... Purging configuration files for wget ...
ふぁっく。わけがわからないよ。
起動したライブシステム上でインストールすることも可能だし、なんかがコンフリクトしてるとかじゃないとは思うんだけど、これなんだろう?