ESXi上で仮想マシンテンプレートの構築(その7 仕上げ)

最後に仕上げの環境設定と、簡単にデプロイするための準備を行う。

ユーザーの作成

ユーザーadminを作成する。これはどのVMでも必ず存在するユーザーで、しかもそのVMのローカルの/etc/passwdに記録される。またホームディレクトリは、/home以外の場所に作られるようにする。VMがどんな状態でも必ずログインできて、各VM固有の環境設定をできるユーザにする。

sudo mkdir /opt/home &&
sudo groupadd -g 1100 admin &&
sudo useradd -m -u 1100 -d /opt/home/admin -g admin -s /bin/bash admin &&
sudo usermod -G wheel admin &&
sudo passwd admin

ホームは/opt/home/adminにした。

~admin/.bash_profileに下記の2行を追加する。

append /sbin
append /usr/sbin

sudo時にわざわざ絶対パスを指定しなくて良いようにするため。

BLFSのソースコードの待避

chroot環境の外から実行する。

sudo cp -R /mnt/lfs/root/src-blfs /tmp/src-blfs-lfs-svn20120821 &&
cd /tmp && tar Jcf ~/src-blfs-lfs-svn20120821.tar.xz src-blfs-lfs-svn20120821 &&
cd ~ && scp src-blfs-lfs-svn20120821.tar.xz 192.168.0.11:~ &&
sudo rm -rf /mnt/lfs/root/src-blfs /tmp/src-blfs-lfs-svn20120821

仮想マシンをテンプレートとして保存

chroot環境の外から実行する。

cd /mnt/lfs &&
sudo rm -rf /mnt/lfs/tmp/* &&
sudo tar Jcf /tmp/lfs_template.svn20120821.tar.xz * &&
scp /tmp/lfs_template.svn20120821.tar.xz 192.168.0.11:~ &&
cp /tmp/lfs_template.svn20120821.tar.xz ~ &&
sudo rm /tmp/lfs_template.svn20120821.tar.xz

ESXi上で仮想マシンテンプレートの構築(その6 その他のツール・ライブラリのインストール)

作業日: 2012/08/21
BLFS Version 2012-08-18

最後に、その他の雑多なプログラムのインストール。
chroot環境で実行する。
前回と同様で、仮にユーザ権限で実行した場合にsudoが必要なコマンドには、sudoをつけてある。

今回インストールするソフトウェアは、インストール順に下記の通り。

  1. Emacs
  2. screen
  3. tree
  4. nkf
  5. which
  6. parted
  7. libusb
  8. usbutils

Emacs-23.4

作業日時点の最新版は24.1だが、エラーでコンパイル出来なかったので一つ前のリリースである23.4を使用する。

cd /root/src-blfs &&
wget http://ftp.gnu.org/pub/gnu/emacs/emacs-23.4.tar.bz2 &&
tar jxf emacs-23.4.tar.bz2 &&
cd emacs-23.4 &&
./configure --prefix=/usr \
            --libexecdir=/usr/lib \
            --localstatedir=/var &&
make bootstrap &&
sudo make install &&
sudo chown -v -R root:root /usr/share/emacs/23.4 &&
cd ../ &&
rm -rf emacs-23.4

Screen-4.0.3

cd /root/src-blfs &&
wget http://ftp.uni-erlangen.de/pub/utilities/screen/screen-4.0.3.tar.gz &&
tar zxf screen-4.0.3.tar.gz &&
cd screen-4.0.3 &&
./configure --prefix=/usr \
            --with-socket-dir=/var/run/screen \
            --with-sys-screenrc=/etc/screenrc \
            --enable-pam &&
sed -i -e "s%/usr/local/etc/screenrc%/etc/screenrc%" {etc,doc}/* &&
make &&
sudo make install &&
sudo install -m 644 etc/etcscreenrc /etc/screenrc &&
cd ../ &&
rm -rf screen-4.0.3

tree-1.6.0

tree-1.6.0.tar.gzで検索して、探してくる

cd /root/src-blfs &&
wget http://fossies.org/linux/misc/tree-1.6.0.tgz &&
tar zxf tree-1.6.0.tgz &&
cd tree-1.6.0 &&
make prefix=/usr &&
sudo make prefix=/usr install &&
cd ../ &&
rm -rf tree-1.6.0

ついでにnkfをインストールする

nkf-2.1.2

cd /root/src-blfs &&
wget http://iij.dl.sourceforge.jp/nkf/53171/nkf-2.1.2.tar.gz &&
tar zxf nkf-2.1.2.tar.gz &&
cd nkf-2.1.2 &&
make prefix=/usr &&
sudo make prefix=/usr install &&
cd ../ &&
rm -rf nkf-2.1.2

which-2.20

cd /root/src-blfs &&
wget http://www.xs4all.nl/~carlo17/which/which-2.20.tar.gz &&
tar zxf which-2.20.tar.gz &&
cd which-2.20 &&
./configure --prefix=/usr &&
make &&
sudo make install &&
cd ../ &&
rm -rf which-2.20

Parted-3.1

cd /root/src-blfs &&
wget http://ftp.gnu.org/gnu/parted/parted-3.1.tar.xz &&
tar Jxf parted-3.1.tar.xz &&
cd parted-3.1 &&
./configure --prefix=/usr \
            --enable-device-mapper=no &&
make &&
make check

テストで1つ失敗するが、無視して続行。

sudo make install &&
cd ../ &&
rm -rf parted-3.1

libusb-1.0.9

USB Utils-006に必要。

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/libusb/libusb-1.0.9.tar.bz2 &&
tar jxf libusb-1.0.9.tar.bz2 &&
cd libusb-1.0.9 &&
./configure --prefix=/usr &&
make &&
sudo make install &&
cd ../ &&
rm -rf libusb-1.0.9

USB Utils-006

cd /root/src-blfs &&
wget http://ftp.kernel.org/pub/linux/utils/usb/usbutils/usbutils-006.tar.xz &&
tar Jxf usbutils-006.tar.xz &&
cd usbutils-006 &&
./configure --prefix=/usr \
            --datadir=/usr/share/misc \
            --disable-zlib &&
make &&
sudo make install &&
sudo mv -v /usr/sbin/update-usbids.sh /usr/sbin/update-usbids &&
cd .. &&
rm -rf usbutils-006

ESXi上で仮想マシンテンプレートの構築 (その5 ネットワークユーティリティのインストール)

作業日: 2012/08/21
BLFS Version 2012-08-18

今回は、ネットワーク関係のプログラムのインストール。
chroot環境でroot権限で実行するので本来は不要だが、仮にユーザ権限で実行した場合にsudoが必要なコマンドには、sudoをつけてある。

今回インストールするソフトウェアは、インストール順に下記の通り。

  1. rsync client
  2. Traceroute
  3. BIND Utilities
  4. Whois
  5. Net-tools
  6. ntp
  7. dhcpcd

rsync-3.0.9 client

cd /root/src-blfs &&
wget http://samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz &&
tar zxf rsync-3.0.9.tar.gz &&
cd rsync-3.0.9 &&
./configure --prefix=/usr &&
make &&
make check &&
sudo make install &&
cd ../ &&
rm -rf rsync-3.0.9

Traceroute-2.0.18

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/traceroute/traceroute-2.0.18.tar.gz &&
tar zxf traceroute-2.0.18.tar.gz &&
cd traceroute-2.0.18 &&
make &&
sudo make prefix=/usr install &&
cd ../ &&
rm -rf traceroute-2.0.18

BIND Utilities-9.9.1-P2

BLFSのダウンロード先からはダウンロードできなかったので注意。

cd /root/src-blfs &&
wget http://ftp.isc.org/isc/bind9/cur/9.9/bind-9.9.1-P2.tar.gz &&
tar zxf bind-9.9.1-P2.tar.gz &&
cd bind-9.9.1-P2 &&
./configure --prefix=/usr &&
make -C lib/dns &&
make -C lib/isc &&
make -C lib/bind9 &&
make -C lib/isccfg &&
make -C lib/lwres &&
make -C bin/dig &&
sudo make -C bin/dig install &&
cd ../ &&
rm -rf bind-9.9.1-P2

Whois 5.0.18

cd /root/src-blfs &&
wget http://ftp.debian.org/debian/pool/main/w/whois/whois_5.0.18.tar.xz &&
tar Jxf whois_5.0.18.tar.xz &&
cd whois-5.0.18 &&
make &&
make pos &&
sudo make prefix=/usr install-whois &&
sudo make prefix=/usr install-mkpasswd &&
sudo make prefix=/usr install-pos &&
cd ../ &&
rm -rf whois-5.0.18

Net-tools-CVS_20101030

cd /root/src-blfs &&
wget http://anduin.linuxfromscratch.org/sources/BLFS/svn/n/net-tools-CVS_20101030.tar.gz &&
tar zxf net-tools-CVS_20101030.tar.gz &&
cd net-tools-CVS_20101030 &&
sed -i -e '/Token/s/y$/n/' config.in &&
yes "" | make config                 &&
make &&
sudo make update &&
cd ../ &&
rm -rf net-tools-CVS_20101030

ntp-4.2.6p4

cd /root/src-blfs &&
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p4.tar.gz &&
tar zxf ntp-4.2.6p4.tar.gz &&
cd ntp-4.2.6p4 &&
./configure --prefix=/usr --sysconfdir=/etc \
            --with-binsubdir=sbin &&
make &&
make check &&
sudo make install &&
sudo install -v -m755 -d /usr/share/doc/ntp-4.2.6p4 &&
sudo cp -v -R html/* /usr/share/doc/ntp-4.2.6p4/ &&
cd ../ &&
rm -rf ntp-4.2.6p4
sudo sh -c '
cat > /etc/ntp.conf << "EOF"
# Africa
server tock.nml.csir.co.za

# Asia
server 0.asia.pool.ntp.org

# Australia
server 0.oceania.pool.ntp.org

# Europe
server 0.europe.pool.ntp.org

# North America
server 0.north-america.pool.ntp.org

# South America
server 2.south-america.pool.ntp.org

driftfile /var/cache/ntp.drift
pidfile   /var/run/ntpd.pid
EOF'
tar jxf blfs-bootscripts-20120814.tar.bz2 &&
cd blfs-bootscripts-20120814 &&
sudo make install-ntpd &&
cd ../ &&
rm -rf blfs-bootscripts-20120814 &&
sudo ln -v -sf ../init.d/setclock /etc/rc.d/rc0.d/K46setclock &&
sudo ln -v -sf ../init.d/setclock /etc/rc.d/rc6.d/K46setclock

dhcpcd

cd /root/src-blfs &&
wget http://roy.marples.name/downloads/dhcpcd/dhcpcd-5.6.1.tar.bz2 &&
tar jxf dhcpcd-5.6.1.tar.bz2 &&
cd dhcpcd-5.6.1 &&
./configure --libexecdir=/lib/dhcpcd \
            --dbdir=/run             \
            --sysconfdir=/etc &&
make &&
make install &&
sed -i "s;/var/lib;/run;g" dhcpcd-hooks/50-dhcpcd-compat &&
install -v -m 644 dhcpcd-hooks/50-dhcpcd-compat /lib/dhcpcd/dhcpcd-hooks/ &&
cd ../ &&
rm -rf dhcpcd-5.6.1
tar jxf blfs-bootscripts-20120814.tar.bz2 &&
cd blfs-bootscripts-20120814 &&
make install-service-dhcpcd &&
cd ../ &&
rm -rf blfs-bootscripts-20120814
cat > /etc/sysconfig/ifconfig.eth0 << "EOF"
ONBOOT="yes"
IFACE="eth0"
SERVICE="dhcpcd"
DHCP_START=""
DHCP_STOP="-k"
EOF

ESXi上で仮想マシンテンプレートの構築 (その4 システムツールのインストール)

作業日: 2012/08/21
BLFS Version 2012-08-18

今回の記事から3回に分けて、どんな用途のシステムにおいても必要な基本的なソフトウェアをインストールしていく。
まず、今回は、システムツールのインストール。

今回インストールするソフトウェアは、インストール順に下記の通り。

  1. OpenSSL
    • SSLプロトコルのオープンソース実装。OpenSSHに必須で、WgetをHTTPSに対応させるために必要。
  2. Wget
    • HTTPやHTTPSからファイルをダウンロードするソフトウェア。今回HTTPSに対応させるために再コンパイル。
  3. pkg-config
    • ライブラリのインストール場所等を管理するプログラム。さしあたって必要なパッケージは無いが、早めにインストールしておいた方がスムーズ。
  4. libtirpc
    • RPCを実装したライブラリ。Linux-PAMのコンパイルに必要。その他、後で出てくるrpcbindやNFS Utilitiesのコンパイルでも必要。
  5. Linux-PAM
    • Linuxの認証を集中管理するパッケージ。OpenSSHや、Sudo、Screen、Shadow等が必要とする。
  6. OpenSSH
    • SSHのサーバとクライアントのオープンソース実装。
  7. Sudo
    • 一般ユーザがroot権限で実行するためのソフトウェア。
  8. Shadow
    • ログイン等の基本的な認証プログラム。ALFSで既にインストールされているが、今回Linux-PAMに対応させるために再コンパイル。
  9. Fcron
    • 定期的にコマンドを実行するためのプログラム。
  10. popt
    • コマンドラインオプションをパースするためのライブラリ。logrorateのコンパイルに必要。
  11. logrotate
    • ログを定期的にローテーションさせるためのプログラム。
  12. Heirloom mailx
    • メールを送信するためのプログラム。logrorateがログをメールで送信する際に必要。
  13. rpcbind
    • Portmapの代替品で、NFSに必要。
  14. NFS Utilities
    • NFSをマウントしたりサーバーとしてエクスポートするために必要なプログラム群。

OpenSSL-1.0.1c

cd /root/src-blfs &&
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz &&
wget http://www.linuxfromscratch.org/patches/blfs/svn/openssl-1.0.1c-fix_manpages-1.patch &&
tar zxf openssl-1.0.1c.tar.gz &&
cd openssl-1.0.1c &&
patch -Np1 -i ../openssl-1.0.1c-fix_manpages-1.patch &&
./config --prefix=/usr zlib-dynamic --openssldir=/etc/ssl shared &&
make &&
make test &&
make MANDIR=/usr/share/man install                &&
install -v -d -m755 /usr/share/doc/openssl-1.0.1c &&
cp -v -r doc/{HOWTO,README,*.{txt,html,gif}}      \
    /usr/share/doc/openssl-1.0.1c &&
cd ../ &&
rm -rf openssl-1.0.1c

Wget-1.14

Wgetは既にダウンロード済み。

cd /root/src-blfs &&
tar Jxf wget-1.14.tar.xz &&
cd wget-1.14 &&
./configure --prefix=/usr     \
            --sysconfdir=/etc \
            --with-ssl=openssl &&
make &&
make check &&
make install &&
cd ../ &&
rm -rf wget-1.14

pkg-config-0.27

cd /root/src-blfs &&
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.27.tar.gz &&
tar zxf pkg-config-0.27.tar.gz &&
cd pkg-config-0.27 &&
./configure --prefix=/usr \
            --docdir=/usr/share/doc/pkg-config-0.27 \
            --with-internal-glib &&
make &&
make check &&
make install &&
cd ../ &&
rm -rf pkg-config-0.27

libtirpc

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/project/libtirpc/libtirpc/0.2.2/libtirpc-0.2.2.tar.bz2 &&
wget http://www.linuxfromscratch.org/patches/blfs/svn/libtirpc-0.2.2-remove-nis-2.patch &&
tar jxf libtirpc-0.2.2.tar.bz2 &&
cd libtirpc-0.2.2 &&
patch -Np1 -i ../libtirpc-0.2.2-remove-nis-2.patch &&
autoreconf &&
./configure --prefix=/usr CFLAGS="-fPIC" &&
make &&
make install &&
mv -v /usr/lib/libtirpc.so.* /lib &&
ln -sfv ../../lib/libtirpc.so.1.0.10 /usr/lib/libtirpc.so &&
cd ../ &&
rm -rf libtirpc-0.2.2

Linux-PAM-1.1.5

cd /root/src-blfs &&
wget --no-check-certificate \
     https://fedorahosted.org/releases/l/i/linux-pam/Linux-PAM-1.1.5.tar.bz2 &&
cat > Linux-PAM-1.1.5-getrlim.patch << "EOF" &&
*** Linux-PAM-1.1.5/modules/pam_unix/pam_unix_acct.c.bak        2012-08-21 11:53:57.000000000 +0900
--- Linux-PAM-1.1.5/modules/pam_unix/pam_unix_acct.c    2012-08-21 11:54:50.000000000 +0900
***************
*** 48,53 ****
--- 48,56 ----
  #include <errno.h>
  #include <sys/wait.h>

+ #include <sys/time.h>
+ #include <sys/resource.h>
+
  #include <security/_pam_macros.h>

  /* indicate that the following groups are defined */
EOF
tar jxf Linux-PAM-1.1.5.tar.bz2 &&
cd Linux-PAM-1.1.5 &&
patch -Np1 -i ../Linux-PAM-1.1.5-getrlim.patch &&
./configure --sbindir=/lib/security \
            --docdir=/usr/share/doc/Linux-PAM-1.1.5 \
            --disable-nis \
            --enable-read-both-confs &&
make &&
install -v -m755 -d /etc/pam.d &&
cat > /etc/pam.d/other << "EOF" &&
auth     required       pam_deny.so
account  required       pam_deny.so
password required       pam_deny.so
session  required       pam_deny.so
EOF
make check &&
rm -rfv /etc/pam.d/* &&
make install &&
chmod -v 4755 /lib/security/unix_chkpwd &&
mv -v /lib/security/pam_tally /sbin &&
cd ../ &&
rm -rf Linux-PAM-1.1.5

PAMの設定ファイルの作成

cat > /etc/pam.d/system-account << "EOF" &&
# Begin /etc/pam.d/system-account

account   required    pam_unix.so

# End /etc/pam.d/system-account
EOF

cat > /etc/pam.d/system-auth << "EOF" &&
# Begin /etc/pam.d/system-auth

auth      required    pam_unix.so

# End /etc/pam.d/system-auth
EOF

cat > /etc/pam.d/system-password << "EOF" &&
# Begin /etc/pam.d/system-password

# use sha512 hash for encryption, use shadow, and try to use any previously
# defined authentication token (chosen password) set by any prior module
password  required    pam_unix.so       sha512 shadow try_first_pass

# End /etc/pam.d/system-password
EOF

cat > /etc/pam.d/system-session << "EOF" &&
# Begin /etc/pam.d/system-session

session   required    pam_unix.so

# End /etc/pam.d/system-session
EOF

cat > /etc/pam.d/other << "EOF"
# Begin /etc/pam.d/other

auth        required        pam_warn.so
auth        required        pam_deny.so
account     required        pam_warn.so
account     required        pam_deny.so
password    required        pam_warn.so
password    required        pam_deny.so
session     required        pam_warn.so
session     required        pam_deny.so

# End /etc/pam.d/other
EOF

OpenSSH-6.0p1

cd /root/src-blfs &&
wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-6.0p1.tar.gz &&
tar zxf openssh-6.0p1.tar.gz &&
cd openssh-6.0p1 &&
install -v -m700 -d /var/lib/sshd &&
chown -v root:sys /var/lib/sshd &&
groupadd -g 50 sshd &&
useradd -c 'sshd PrivSep' -d /var/lib/sshd -g sshd \
        -s /bin/false -u 50 sshd &&
sed -i.bak '/K5LIBS=/s/ -ldes//' configure &&
./configure --prefix=/usr \
            --sysconfdir=/etc/ssh \
            --datadir=/usr/share/sshd \
            --with-md5-passwords \
            --with-privsep-path=/var/lib/sshd \
            --with-pam &&
make &&
make tests 2>&1 | tee check.log &&
grep FATAL check.log
scp: failed copy /bin/ls
cmp: /root/src-blfs/openssh-6.0p1/regress/ls.copy: そのようなファイルやディレクトリはありません
scp: corrupted copy of /bin/ls
test connection multiplexing: status 0
test connection multiplexing: status 1
test connection multiplexing: status 4
test connection multiplexing: status 5
test connection multiplexing: status 44
Master running (pid=19065)
Exit request sent.
failed connection multiplexing
make[1]: *** [t-exec] エラー 1
make[1]: ディレクトリ `/root/src-blfs/openssh-6.0p1/regress' から出ます
make: *** [tests] エラー 2

というエラーが出る。
どうやらテストプログラムに何らかの循環参照があるらしく、OpenSSHがインストールされていない環境では上記のようなエラーが出るようである。
いったんインストールした後テストをやり直すと上記のエラーは出なくなるので、無視して先に進む。

make install &&
install -v -m755 -d /usr/share/doc/openssh-6.0p1 &&
install -v -m644 INSTALL LICENCE OVERVIEW README* \
    /usr/share/doc/openssh-6.0p1 &&
echo "PermitRootLogin no" >> /etc/ssh/sshd_config &&
echo "USEPAM yes" >> /etc/ssh/sshd_config &&
cat > /etc/pam.d/sshd << "EOF" &&
# Begin /etc/pam.d/sshd

# Set failure delay before next prompt to 3 seconds
auth      optional    pam_faildelay.so  delay=3000000

# Check to make sure that the user is allowed to login
auth      requisite   pam_nologin.so

# Check to make sure that root is allowed to login
# Disabled by default. You will need to create /etc/securetty
# file for this module to function. See man 5 securetty.
#auth      required    pam_securetty.so

# Additional group memberships - disabled by default
#auth      optional    pam_group.so

# include the default auth settings
auth      include     system-auth

# check access for the user
account   required    pam_access.so

# include the default account settings
account   include     system-account

# Set default environment variables for the user
session   required    pam_env.so

# Set resource limits for the user
session   required    pam_limits.so

# Display date of last login - Disabled by default
#session   optional    pam_lastlog.so

# Display the message of the day - Disabled by default
#session   optional    pam_motd.so

# Check user's mail - Disabled by default
#session   optional    pam_mail.so      standard quiet

# include the default session and password settings
session   include     system-session
password  include     system-password

# End /etc/pam.d/sshd
EOF

chmod 644 /etc/pam.d/sshd &&
cd ../ &&
rm -rf openssh-6.0p1
tar jxf blfs-bootscripts-20120814.tar.bz2 &&
cd blfs-bootscripts-20120814 &&
make install-sshd &&
cd ../ &&
rm -rf blfs-bootscripts-20120814

Sudo-1.8.5p2

cd /root/src-blfs &&
wget http://www.sudo.ws/sudo/dist/sudo-1.8.5p2.tar.gz &&
tar zxf sudo-1.8.5p2.tar.gz &&
cd sudo-1.8.5p2 &&
./configure --prefix=/usr \
            --libexecdir=/usr/lib/sudo \
            --docdir=/usr/share/doc/sudo-1.8.5p2 \
            --with-all-insults \
            --with-env-editor \
            --without-sendmail &&
make &&
make install &&
cd ../ &&
rm -rf sudo-1.8.5p2 &&
cat > /etc/pam.d/sudo << "EOF" &&
# Begin /etc/pam.d/sudo

# include the default auth settings
auth      include     system-auth

# include the default account settings
account   include     system-account

# Set default environment variables for the service user
session   required    pam_env.so

# include system session defaults
session   include     system-session

# End /etc/pam.d/sudo
EOF
chmod 644 /etc/pam.d/sudo

visudoを使って、/etc/sudoersの下記をコメントアウト

%wheel ALL=(ALL) ALL

gid 90でwheelグループを追加

groupadd -g 90 wheel

ユーザをwheelグループに追加する場合は、

usermod -G wheel ユーザ名

のようにする。

Shadow-4.1.5.1

cd /root/src-blfs &&
wget http://pkg-shadow.alioth.debian.org/releases/shadow-4.1.5.1.tar.bz2 &&
tar jxf shadow-4.1.5.1.tar.bz2 &&
cd shadow-4.1.5.1 &&
sed -i 's/groups$(EXEEXT) //' src/Makefile.in &&
find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \; &&
sed -i -e 's/ ko//' -e 's/ zh_CN zh_TW//' man/Makefile.in &&
sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' \
       -e 's@/var/spool/mail@/var/mail@' etc/login.defs &&
sed -i -e 's@PATH=/sbin:/bin:/usr/sbin:/usr/bin@&:/usr/local/sbin:/usr/local/bin@' \
       -e 's@PATH=/bin:/usr/bin@&:/usr/local/bin@' etc/login.defs &&
./configure --prefix=/usr --sysconfdir=/etc &&
make &&
make install &&
mv -v /usr/bin/passwd /bin &&
cd ../ &&
rm -rf shadow-4.1.5.1
sed -i 's/yes/no/' /etc/default/useradd &&
install -v -m644 /etc/login.defs /etc/login.defs.orig &&
for FUNCTION in FAIL_DELAY LASTLOG_ENAB \
                FAILLOG_ENAB QUOTAS_ENAB \
                FTMP_FILE PASS_MIN_LEN \
                MAIL_CHECK_ENAB \
                OBSCURE_CHECKS_ENAB \
                PORTTIME_CHECKS_ENAB \
                CONSOLE MOTD_FILE \
                NOLOGINS_FILE ENV_HZ \
                SU_WHEEL_ONLY \
                CRACKLIB_DICTPATH \
                SYS_UID_MIN SYS_UID_MAX \
                SYS_GID_MIN SYS_GID_MAX \
                PASS_CHANGE_TRIES \
                PASS_ALWAYS_WARN \
                CHFN_AUTH ENVIRON_FILE
do
    sed -i "s/^${FUNCTION}/# &/" /etc/login.defs
done &&
cat > /etc/pam.d/login << "EOF" &&
# Begin /etc/pam.d/login

# Set failure delay before next prompt to 3 seconds
auth      optional    pam_faildelay.so  delay=3000000

# Check to make sure that the user is allowed to login
auth      requisite   pam_nologin.so

# Check to make sure that root is allowed to login
# Disabled by default. You will need to create /etc/securetty
# file for this module to function. See man 5 securetty.
#auth      required    pam_securetty.so

# Additional group memberships - disabled by default
#auth      optional    pam_group.so

# include the default auth settings
auth      include     system-auth

# check access for the user
account   required    pam_access.so

# include the default account settings
account   include     system-account

# Set default environment variables for the user
session   required    pam_env.so

# Set resource limits for the user
session   required    pam_limits.so

# Display date of last login - Disabled by default
#session   optional    pam_lastlog.so

# Display the message of the day - Disabled by default
#session   optional    pam_motd.so

# Check user's mail - Disabled by default
#session   optional    pam_mail.so      standard quiet

# include the default session and password settings
session   include     system-session
password  include     system-password

# End /etc/pam.d/login
EOF
cat > /etc/pam.d/passwd << "EOF" &&
# Begin /etc/pam.d/passwd

password  include     system-password

# End /etc/pam.d/passwd
EOF
cat > /etc/pam.d/su << "EOF" &&
# Begin /etc/pam.d/su

# always allow root
auth      sufficient  pam_rootok.so
auth      include     system-auth

# include the default account settings
account   include     system-account

# Set default environment variables for the service user
session   required    pam_env.so

# include system session defaults
session   include     system-session

# End /etc/pam.d/su
EOF
cat > /etc/pam.d/chage << "EOF" &&
#Begin /etc/pam.d/chage

# always allow root
auth      sufficient  pam_rootok.so

# include system defaults for auth account and session
auth      include     system-auth
account   include     system-account
session   include     system-session

# Always permit for authentication updates
password  required    pam_permit.so

# End /etc/pam.d/chage
EOF
for PROGRAM in chfn chgpasswd chpasswd chsh groupadd groupdel \
               groupmems groupmod newusers useradd userdel usermod
do
    install -v -m644 /etc/pam.d/chage /etc/pam.d/${PROGRAM}
    sed -i "s/chage/$PROGRAM/" /etc/pam.d/${PROGRAM}
done &&
if [ -f /etc/login.access ]; then
  mv -v /etc/login.access{,.NOUSE}
fi &&
if [ -f /etc/limits ]; then
  mv -v /etc/limits{,.NOUSE}
fi

Fcron-3.0.6

cd /root/src-blfs &&
wget http://fcron.free.fr/archives/fcron-3.0.6.src.tar.gz &&
tar zxf fcron-3.0.6.src.tar.gz &&
cd fcron-3.0.6 &&
cat >> /etc/syslog.conf << "EOF" &&
# Begin fcron addition to /etc/syslog.conf

cron.* -/var/log/cron.log

# End fcron addition
EOF
sudo /usr/sbin/groupadd -g 22 fcron &&
sudo /usr/sbin/useradd -d /dev/null -c "Fcron User" -g fcron -s /bin/false -u 22 fcron &&
./configure --prefix=/usr --sysconfdir=/etc \
    --localstatedir=/var --without-sendmail --with-boot-install=no &&
make &&
make install &&
cd ../ &&
rm -rf fcron-3.0.6
tar jxf blfs-bootscripts-20120814.tar.bz2 &&
cd blfs-bootscripts-20120814 &&
make install-fcron &&
cd ../ &&
rm -rf blfs-bootscripts-20120814

Popt-1.16

cd /root/src-blfs &&
wget http://rpm5.org/files/popt/popt-1.16.tar.gz &&
tar zxf popt-1.16.tar.gz &&
cd popt-1.16 &&
./configure --prefix=/usr &&
make &&
make check &&
make install &&
cd ../ &&
rm -rf popt-1.16

Logrotate-3.8.2

cd /root/src-blfs &&
wget http://fossies.org/unix/privat/logrotate-3.8.2.tar.gz &&
tar zxf logrotate-3.8.2.tar.gz &&
chown -R root:root logrotate-3.8.2 &&
cd logrotate-3.8.2 &&
sed -i 's%/bin/mail%/usr/bin/mail%' config.h &&
make &&
make test &&
sudo make install &&
cd ../ &&
rm -rf logrotate-3.8.2
mkdir /etc/logrotate.d &&
cat > /etc/logrotate.conf << "EOF"
# Begin of /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 10 weeks worth of backlogs
rotate 10

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

#
# Syslog
#
/var/log/auth.log /var/log/boot.log /var/log/cron.log /var/log/daemon.log
/var/log/kern.log /var/log/mail.log /var/log/sys.log /var/log/user.log {
    create 0644 root root
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

#
# wtmp
#
/var/log/wtmp {
    monthly
    create 0644 root root
    rotate 1
}

#
# btmp
#
/var/log/btmp {
    monthly
    create 0600 root root
    rotate 1
}
# End of /etc/logrotate.conf
EOF
fcrontab -e
SHELL=/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
HOME=/root

0 5 * * * /usr/sbin/logrotate /etc/logrotate.conf >& /dev/null

Heirloom mailx-12.4

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/heirloom/mailx-12.4.tar.bz2 &&
wget http://www.linuxfromscratch.org/patches/blfs/svn/mailx-12.4-openssl_1.0.0_build_fix-1.patch &&
tar jxf mailx-12.4.tar.bz2 &&
cd mailx-12.4 &&
patch -Np1 -i ../mailx-12.4-openssl_1.0.0_build_fix-1.patch &&
make SENDMAIL=/usr/sbin/sendmail &&
sudo make PREFIX=/usr UCBINSTALL=/usr/bin/install install &&
sudo ln -v -sf mailx /usr/bin/mail &&
sudo ln -v -sf mailx /usr/bin/nail &&
sudo install -v -m755 -d /usr/share/doc/mailx-12.4 &&
sudo install -v -m644 README mailx.1.html /usr/share/doc/mailx-12.4 &&
cd ../ &&
rm -rf mailx-12.4

rpcbind-0.2.0

NFS Utilitiesの実行時に必要。

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/rpcbind/rpcbind-0.2.0.tar.bz2 &&
tar jxf rpcbind-0.2.0.tar.bz2 &&
cd rpcbind-0.2.0 &&
sudo sed -i 's/^sunrpc/rpcbind/' /etc/services &&
./configure --prefix=/usr --bindir=/sbin &&
make &&
sudo make install &&
cd ../ &&
rm -rf rpcbind-0.2.0
tar jxf blfs-bootscripts-20120814.tar.bz2 &&
cd blfs-bootscripts-20120814 &&
sudo make install-rpcbind &&
cd ../ &&
rm -rf blfs-bootscripts-20120814

NFS Utilities-1.2.5

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/nfs/nfs-utils-1.2.5.tar.bz2 &&
tar jxf nfs-utils-1.2.5.tar.bz2 &&
cd nfs-utils-1.2.5 &&
LIBS=-lpthread ./configure --prefix=/usr          \
                           --sysconfdir=/etc      \
                           --without-tcp-wrappers \
                           --disable-nfsv4        \
                           --disable-nfsv41       \
                           --disable-gss &&
make &&
sudo make install &&
cd ../ &&
rm -rf nfs-utils-1.2.5

クライアントとして使うにせよ、サーバーとして使うにせよ、ブートスクリプト等のインストールが必要になる。これは実際に仮想マシンをデプロイしてから行う。また、クライアントの場合は、BLFSのConfiguring for Network Filesystemsの設定も必要になる。

cd nfs-utils-1.2.5

ESXi上で仮想マシンテンプレートの構築 (その3 BLFSの環境設定)

Version 2012-08-18

BLFSに書いてある環境設定を行う。

Wget

まず最初に、wgetをインストールする。wgetを最初にインストールしておかないと、chroot環境からパッケージがダウンロードできない。今回インストールするのはSSLに非対応なので、SSLをインストール後からコンパイルし直す。

chroot環境の外で

sudo mkdir /mnt/lfs/root/src-blfs &&
wget http://ftp.gnu.org/gnu/wget/wget-1.14.tar.xz &&
sudo mv wget-1.14.tar.xz /mnt/lfs/root/src-blfs

chroot環境で

cd /root/src-blfs &&
tar Jxf wget-1.14.tar.xz &&
cd wget-1.14 &&
./configure --prefix=/usr \
            --sysconfdir=/etc \
            --without-ssl &&
make &&
make check &&
make install &&
cd ../ &&
rm -rf wget-1.14

BLFS bootscriptsのダウンロード

後から何回も使用するので先にダウンロードしておく。

cd /root/src-blfs &&
wget http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20120814.tar.bz2

BLFSの環境設定

まず、Bashの起動時に実行されるスクリプト(bashrc等)をインストールする。BLFSの The Bash Shell Startup Filesに従う。

cat > /etc/profile << "EOF"
# Begin /etc/profile
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>
# modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>

# System wide environment variables and startup programs.

# System wide aliases and functions should go in /etc/bashrc.  Personal
# environment variables and startup programs should go into
# ~/.bash_profile.  Personal aliases and functions should go into
# ~/.bashrc.

# Functions to help us manage paths.  Second argument is the name of the
# path variable to be modified (default: PATH)
pathremove () {
        local IFS=':'
        local NEWPATH
        local DIR
        local PATHVARIABLE=${2:-PATH}
        for DIR in ${!PATHVARIABLE} ; do
                if [ "$DIR" != "$1" ] ; then
                  NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
                fi
        done
        export $PATHVARIABLE="$NEWPATH"
}

pathprepend () {
        pathremove $1 $2
        local PATHVARIABLE=${2:-PATH}
        export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}

pathappend () {
        pathremove $1 $2
        local PATHVARIABLE=${2:-PATH}
        export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}

# Set the initial path
export PATH=/bin:/usr/bin

if [ $EUID -eq 0 ] ; then
        pathappend /sbin:/usr/sbin
        unset HISTFILE
fi

# Setup some environment variables.
export HISTSIZE=1000
export HISTIGNORE="&:[bf]g:exit"

# Setup a red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
  PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
  PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi

for script in /etc/profile.d/*.sh ; do
        if [ -r $script ] ; then
                . $script
        fi
done

# Now to clean up
unset pathremove pathprepend pathappend

# End /etc/profile
EOF
install --directory --mode=0755 --owner=root --group=root /etc/profile.d
cat > /etc/profile.d/dircolors.sh << "EOF"
# Setup for /bin/ls to support color, the alias is in /etc/bashrc.
if [ -f "/etc/dircolors" ] ; then
        eval $(dircolors -b /etc/dircolors)

        if [ -f "$HOME/.dircolors" ] ; then
                eval $(dircolors -b $HOME/.dircolors)
        fi
fi
alias ls='ls --color=auto'
EOF

cat > /etc/profile.d/extrapaths.sh << "EOF"
if [ -d /usr/local/lib/pkgconfig ] ; then
        pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH
fi
if [ -d /usr/local/bin ]; then
        pathprepend /usr/local/bin
fi
if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then
        pathprepend /usr/local/sbin
fi

if [ -d ~/bin ]; then
        pathprepend ~/bin
fi
#if [ $EUID -gt 99 ]; then
#        pathappend .
#fi
EOF

cat > /etc/profile.d/readline.sh << "EOF"
# Setup the INPUTRC environment variable.
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
        INPUTRC=/etc/inputrc
fi
export INPUTRC
EOF

cat > /etc/profile.d/umask.sh << "EOF"
# By default we want the umask to get set.
if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
  umask 002
else
  umask 022
fi
EOF
cat > /etc/profile.d/i18n.sh << "EOF"
# Set up i18n variables
export LANG=ja_JP.UTF-8
EOF
cat > /etc/bashrc << "EOF"
# Begin /etc/bashrc
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>
# updated by Bruce Dubbs <bdubbs@linuxfromscratch.org>

# System wide aliases and functions.

# System wide environment variables and startup programs should go into
# /etc/profile.  Personal environment variables and startup programs
# should go into ~/.bash_profile.  Personal aliases and functions should
# go into ~/.bashrc

# Provides a colored /bin/ls command.  Used in conjunction with code in
# /etc/profile.

alias ls='ls --color=auto'

# Provides prompt for non-login shells, specifically shells started
# in the X environment. [Review the LFS archive thread titled
# PS1 Environment Variable for a great case study behind this script
# addendum.]

NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
  PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
  PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi

# End /etc/bashrc
EOF
install --directory --mode=0755 --owner=root --group=root /etc/skel
cat > /etc/skel/.bash_profile << "EOF"
# Begin ~/.bash_profile
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>
# updated by Bruce Dubbs <bdubbs@linuxfromscratch.org>

# Personal environment variables and startup programs.

# Personal aliases and functions should go in ~/.bashrc.  System wide
# environment variables and startup programs are in /etc/profile.
# System wide aliases and functions are in /etc/bashrc.

append () {
  # First remove the directory
  local IFS=':'
  local NEWPATH
  for DIR in $PATH; do
     if [ "$DIR" != "$1" ]; then
       NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
     fi
  done

  # Then append the directory
  export PATH=$NEWPATH:$1
}

if [ -f "$HOME/.bashrc" ] ; then
  source $HOME/.bashrc
fi

if [ -d "$HOME/bin" ] ; then
  append $HOME/bin
fi

unset append

# End ~/.bash_profile
EOF
cat > /etc/skel/.bashrc << "EOF"
# Begin ~/.bashrc
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>

# Personal aliases and functions.

# Personal environment variables and startup programs should go in
# ~/.bash_profile.  System wide environment variables and startup
# programs are in /etc/profile.  System wide aliases and functions are
# in /etc/bashrc.

if [ -f "/etc/bashrc" ] ; then
  source /etc/bashrc
fi

# End ~/.bashrc
EOF
cat > /etc/skel/.bash_logout << "EOF"
# Begin ~/.bash_logout
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>

# Personal items to perform on logout.

# End ~/.bash_logout
EOF
cp /etc/skel/.bash{rc,_profile,_logout} /root
dircolors -p > /etc/dircolors

次に、ログイン画面を/etc/issueでカスタマイズする。BLFSのCustomizing your Logon with /etc/issue に従う。

cat > /etc/issue << "EOF"
\n - GNU/Linux \r (LFS SVN-20120821)
\t
EOF

/etc/shellsを作成する。BLFSのThe /etc/shells Fileに従う。

cat > /etc/shells << "EOF"
# Begin /etc/shells

/bin/sh
/bin/bash

# End /etc/shells
EOF

乱数発生器のセットアップ。BLFSのRandom Number Generationに従う。

cd /root/src-blfs &&
tar jxf blfs-bootscripts-20120814.tar.bz2 &&
cd blfs-bootscripts-20120814 &&
make install-random &&
cd ../ &&
rm -rf blfs-bootscripts-20120814