ESXi上で仮想マシンテンプレートの構築(その8 デプロイの仕方)

デプロイの仕方

新規VMの作成

vSphere Clientから新規VMを作成する。ゲストOSとして「その他の2.6.x Linux (32ビット)」を選択し、新規仮想ディスクを作成する。あとの設定は、適当で良い。まだ起動はしない。

LFS環境のコピー

ホストして一旦他のVMを使用して、LFS環境を新VMにコピーする (前回記事で作成したlfs_template.20130429.tar.xzにアクセス出来る必要がある。)ここでは、LFSのコンパイルに使用したUbuntu 12.04LTS Server 32bitを使用する。

ホストVMを停止し、上記の新規VMで作成した仮想HDDを追加する。ホストVMを起動し、新規HDDが追加されたデバイスファイル名をチェックする。今回は/dev/sdcとして認識された(/dev/sdbにはLFSを構築したHDDが割り当てられているため。)

まず、パーティションを作成する。

sudo fdisk /dev/sdc

/dev/sdc1として”/”にマウントする基本パーティションを、/dev/sdc2としてswapパーティションを作成する(ただし、VMにメモリを十分に割り当てておけば、Swapは無くても動作する)。

次にフォーマットする。

sudo mkfs.ext3 /dev/sdc1 &&
sudo mkswap /dev/sdc2

そして、適当なディレクトリにマウントする(ここでは、/mnt/newhddを使用。)

sudo mkdir /mnt/newhdd &&
sudo mount /dev/sdc1 /mnt/newhdd

lfs_template.20130429.tar.xzの内容を新HDDに展開する。ここでは、ホームディレクトリにコピーされてあると仮定する。

cd /mnt/newhdd &&
sudo tar Jxfv ~/lfs_template.svn20130429.tar.xz &&
sudo sed -i -e "s%/mnt/lfs%/mnt/newhdd%g" /mnt/newhdd/root/chroot.sh

Grubのインストール

新規HDDのMBRにGRUBをインストールする。

sudo /mnt/newhdd/root/chroot.sh

でchroot環境に入った上で、

grub-install /dev/sdc

を実行する(/dev/sdc等のデバイスファイル名はホスト環境と同一。)

環境設定

/etc/fstabの設定

(Swapパーティションを使用する場合、)/etc/fstabのスワップの設定に関する行をコメントアウトする。

/dev/sda2     swap         swap     pri=1               0     0

IPアドレス・ホスト名の設定

DHCPの場合

/etc/sysconfig/networkと/etc/hostsに新しいホスト名を書き込む。

固定IPの場合

/etc/sysconfig/networkに新しいホスト名を書き込む。

/etc/hostsにホスト名とIPアドレスを設定。例えば下記のようになる。

# Begin /etc/hosts

127.0.0.1 localhost
192.168.0.XX newvm.example.net newvm

# End /etc/hosts

/etc/resolv.confを適切に設定する。

/etc/sysconfig/ifconfig.eth0を下記のように設定する。

ONBOOT=yes
IFACE=eth0
SERVICE=ipv4-static
IP=192.168.0.XX
GATEWAY=192.168.0.1
PREFIX=24
BROADCAST=192.168.0.255

Homeのマウント

Homeをマウントする場合は、下記を設定する(ファイルサーバーがセットアップできていることが前提)。

cd ~ &&
tar jxf ~admin/src/blfs-bootscripts-20130324.tar.bz2 &&
cd blfs-bootscripts-20130324 &&
sudo make install-nfs-client &&
sudo make install-netfs &&
cd ../ &&
rm -rf blfs-bootscripts-20130314

/etc/fstabに下記の行を追加する、

192.168.0.11:/home  /home   nfs      rw,nfsvers=3,_netdev,rsize=8192,wsize=8192 0 0

ユーザを作成する。

sudo groupadd -g 1000 users &&
sudo useradd -u 1000 -d /home/username -g users -s /bin/bash username &&
sudo passwd username

将来的には、NISとかLDAPで一元管理したいが、当面は各VMに同じIDでユーザを作成することで対応。

新VMでの起動

chroot環境を抜けて、ホストVMをシャットダウンする。

cd ~ &&
sudo umount /dev/sdc1 &&
sudo rmdir /mnt/newhdd &&
sudo halt

ホストVMから、新HDDを取り外し(仮想HDDファイル自体を削除しないように注意)、新VMを起動する。adminユーザーでログインできる事を確認する。

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

作業日: 30 Apr., 2013

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

ユーザーの作成

ユーザー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-bootscriptは今後もよく使うので、adminのホームに保管しておく。

sudo -u admin mkdir ~admin/src &&
sudo -u admin wget --directory-prefix=~admin/src \

http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20130324.tar.bz2

BLFSのソースコードの待避

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

sudo cp -R /mnt/lfs/root/src-blfs /tmp/src-blfs-lfs-svn20130427 &&
cd /tmp && tar Jcf ~/src-blfs-lfs-svn20130427.tar.xz src-blfs-lfs-svn20130427 &&
cd ~ && scp src-blfs-lfs-svn20130427.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.svn20130429.tar.xz * &&
scp /tmp/lfs_template.svn20130429.tar.xz 192.168.0.11:~ &&
cp /tmp/lfs_template.svn20130429.tar.xz ~ &&
sudo rm /tmp/lfs_template.svn20130429.tar.xz

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

作業日: 2012/03/30
BLFS Version 2013-04-27

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

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

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

Emacs-24.2

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

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 --no-check-certificate \
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 ネットワークユーティリティのインストール)

作業日: 30 Apr., 2013
BLFS Version 2013-04-27

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

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

  1. rsync client
  2. Traceroute
  3. BIND Utilities
  4. Whois
  5. Net-tools
  6. attr
  7. libcap2
  8. ntp
  9. 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.19

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

BIND Utilities-9.9.2-P2

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

cd /root/src-blfs &&
wget http://ftp.isc.org/isc/bind9/cur/9.9/bind-9.9.2-P2.tar.gz &&
tar zxf bind-9.9.2-P2.tar.gz &&
cd bind-9.9.2-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.2-P2

Whois 5.0.24

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

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 &&
sed -i -e '/HAVE_HWSTRIP/s/y$/n/' config.in &&
yes "" | make config                 &&
make &&
make update &&
cd ../ &&
rm -rf net-tools-CVS_20101030

attr-2.4.46

cd /root/src-blfs &&
wget http://download.savannah.gnu.org/releases/attr/attr-2.4.46.src.tar.gz &&
tar zxf attr-2.4.46.src.tar.gz &&
cd attr-2.4.46 &&
sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in &&
INSTALL_USER=root  \
INSTALL_GROUP=root \
./configure --prefix=/usr --libdir=/lib --libexecdir=/usr/lib &&
make &&
make tests root-tests ext-tests

テストは失敗するけど気にせずに続行。

sudo make install install-dev install-lib &&
sudo chmod -v 0755 /lib/libattr.so.1.1.0           &&
sudo rm -v /lib/libattr.{a,la,so}                  &&
sudo sed -i 's@/lib@/usr/lib@' /usr/lib/libattr.la &&
sudo ln -sfv ../../lib/libattr.so.1 /usr/lib/libattr.so

libcap2-2.22

cd /root/src-blfs &&
wget http://ftp.de.debian.org/debian/pool/main/libc/libcap2/libcap2_2.22.orig.tar.gz &&
tar zxf libcap2_2.22.orig.tar.gz &&
cd libcap-2.22 &&
make &&
sudo make RAISE_SETFCAP=no install &&
cd ../ &&
rm -rf libcap-2.22

ntp-4.2.6p5

cd /root/src-blfs &&
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.6p5.tar.gz &&
tar zxf ntp-4.2.6p5.tar.gz &&
cd ntp-4.2.6p5 &&
groupadd -g 87 ntp &&
useradd -c "Network Time Protocol" -d /var/lib/ntp -u 87 \
        -g ntp -s /bin/false ntp &&
./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.6p5 &&
sudo cp -v -R html/* /usr/share/doc/ntp-4.2.6p5/ &&
cd ../ &&
rm -rf ntp-4.2.6p5
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-20130324.tar.bz2 &&
cd blfs-bootscripts-20130324 &&
sudo make install-ntpd &&
cd ../ &&
rm -rf blfs-bootscripts-20130324 &&
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-5.6.7

cd /root/src-blfs &&
wget http://roy.marples.name/downloads/dhcpcd/dhcpcd-5.6.7.tar.bz2 &&
tar jxf dhcpcd-5.6.7.tar.bz2 &&
cd dhcpcd-5.6.7 &&
./configure --libexecdir=/lib/dhcpcd \
            --dbdir=/run             \
            --sysconfdir=/etc &&
make &&
sudo make install &&
sudo sed -i "s;/var/lib;/run;g" dhcpcd-hooks/50-dhcpcd-compat &&
sudo install -v -m 644 dhcpcd-hooks/50-dhcpcd-compat /lib/dhcpcd/dhcpcd-hooks/ &&
cd ../ &&
rm -rf dhcpcd-5.6.7
tar jxf blfs-bootscripts-20130324.tar.bz2 &&
cd blfs-bootscripts-20130324 &&
sudo make install-service-dhcpcd &&
cd ../ &&
rm -rf blfs-bootscripts-20130324
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.1e

cd /root/src-blfs &&
wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz &&
wget http://www.linuxfromscratch.org/patches/blfs/svn/openssl-1.0.1e-fix_manpages-1.patch &&
tar zxf openssl-1.0.1e.tar.gz &&
cd openssl-1.0.1e &&
patch -Np1 -i ../openssl-1.0.1e-fix_manpages-1.patch &&
./config --prefix=/usr zlib-dynamic --openssldir=/etc/ssl shared &&
make &&
make test &&
make MANDIR=/usr/share/man install                &&
install -dv -m755 /usr/share/doc/openssl-1.0.1e &&
cp -vfr doc/* /usr/share/doc/openssl-1.0.1e &&
cd ../ &&
rm -rf openssl-1.0.1e

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.28

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

libtirpc-0.2.3

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/project/libtirpc/libtirpc/0.2.3/libtirpc-0.2.3.tar.bz2 &&
wget http://www.linuxfromscratch.org/patches/blfs/svn/libtirpc-0.2.3-remove_nis-1.patch &&
tar jxf libtirpc-0.2.3.tar.bz2 &&
cd libtirpc-0.2.3 &&
patch -Np1 -i ../libtirpc-0.2.3-remove_nis-1.patch &&
sed "s@AM_CONFIG_HEADER@AC_CONFIG_HEADERS@g" -i configure.ac &&
autoreconf -fi &&
./configure --prefix=/usr --sysconfdir=/etc 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.3

Linux-PAM-1.1.6

cd /root/src-blfs &&
wget --no-check-certificate \
     https://fedorahosted.org/releases/l/i/linux-pam/Linux-PAM-1.1.6.tar.bz2 &&
tar jxf Linux-PAM-1.1.6.tar.bz2 &&
cd Linux-PAM-1.1.6 &&
./configure --prefix=/usr \
            --sysconfdir=/etc \
            --docdir=/usr/share/doc/Linux-PAM-1.1.6 \
            --disable-nis &&
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 /sbin/unix_chkpwd &&
cd ../ &&
rm -rf Linux-PAM-1.1.6

PAMの設定ファイルの作成

install -v -m755 -d /etc/pam.d &&
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.2p1

cd /root/src-blfs &&
wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-6.2p1.tar.gz &&
tar zxf openssh-6.2p1.tar.gz &&
cd openssh-6.2p1 &&
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 &&
./configure --prefix=/usr \
            --sysconfdir=/etc/ssh \
            --datadir=/usr/share/sshd \
            --with-md5-passwords \
            --with-privsep-path=/var/lib/sshd \
            --with-pam &&
make &&
install -v scp /usr/sbin
make tests &&
make install &&
install -v -m755 -d /usr/share/doc/openssh-6.2p1 &&
install -v -m644 INSTALL LICENCE OVERVIEW README* \
    /usr/share/doc/openssh-6.2p1 &&
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.2p1
tar jxf blfs-bootscripts-20130324.tar.bz2 &&
cd blfs-bootscripts-20130324 &&
make install-sshd &&
cd ../ &&
rm -rf blfs-bootscripts-20130324

Sudo-1.8.6p3

cd /root/src-blfs &&
wget http://www.sudo.ws/sudo/dist/sudo-1.8.6p3.tar.gz &&
tar zxf sudo-1.8.6p3.tar.gz &&
cd sudo-1.8.6p3 &&
./configure --prefix=/usr \
            --libexecdir=/usr/lib/sudo \
            --docdir=/usr/share/doc/sudo-1.8.6p3 \
            --with-all-insults \
            --with-env-editor \
            --with-pam \
            --without-sendmail &&
make &&
make install &&
cd ../ &&
rm -rf sudo-1.8.6p3 &&
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.1.2

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

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

# End fcron addition
EOF
/etc/rc.d/init.d/sysklogd reload &&
groupadd -g 22 fcron &&
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.1.2
tar jxf blfs-bootscripts-20130324.tar.bz2 &&
cd blfs-bootscripts-20130324 &&
make install-fcron &&
cd ../ &&
rm -rf blfs-bootscripts-20130324

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

作業日時点での最新版は3.8.3だが、make testが正常に動かなかったので、古い3.8.2を使用した。

cd /root/src-blfs &&
wget http://pkgs.fedoraproject.org/repo/pkgs/logrotate/logrotate-3.8.2.tar.gz/ddd4dcf28c38b3ac6bc6ff4e0148308a/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 &&
make PREFIX=/usr UCBINSTALL=/usr/bin/install install &&
ln -v -sf mailx /usr/bin/mail &&
ln -v -sf mailx /usr/bin/nail &&
install -v -m755 -d /usr/share/doc/mailx-12.4 &&
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-20130324.tar.bz2 &&
cd blfs-bootscripts-20130324 &&
sudo make install-rpcbind &&
cd ../ &&
rm -rf blfs-bootscripts-20130324

NFS Utilities-1.2.7

cd /root/src-blfs &&
wget http://downloads.sourceforge.net/nfs/nfs-utils-1.2.7.tar.bz2 &&
tar jxf nfs-utils-1.2.7.tar.bz2 &&
cd nfs-utils-1.2.7 &&
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.7

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

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

作業日: 30 Apr., 2013
BLFS Version: 2013-04-27

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-20130324.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-20130329)
\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-20130324.tar.bz2 &&
cd blfs-bootscripts-20130324 &&
make install-random &&
cd ../ &&
rm -rf blfs-bootscripts-20130324

ESXi上で仮想マシンテンプレートの構築 (その2 カーネルのコンパイルとGrubのインストール)

作業日: 30 Apr. 2013

本記事の以下の作業は、chroot環境で実行する。chroot環境で無い場合は、

sudo /mnt/lfs/chroot.sh

を実行する。

Linuxカーネルのコンパイル

まずは、コンパイルの準備。

cd /sources &&
tar Jxf linux-3.5.2.tar.xz &&
cd linux-3.5.2 &&
make mrproper &&
make defconfig

make defconfig で一般的なカーネルの設定を呼び出す。

次に、設定を編集する。

make LANG=C LC_ALL= menuconfig

ALFSの時と同様に、文字列が入力できない場合で、文字列の入力が必要な場合は、コンソールから実行するか、設定ファイルをテキストエディタで編集する。

Enable loadable module support
を無効に

Processor type and features -> Processor family
は、環境に合わせて、設定する。
Core 2/Newer Xeon

VMwareでは、SCSIは、
LSI Logic /Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI
として認識されている。
Device Drivers -> Fusion MPT device support を有効にする。
展開して、
Fusion MPT ScsiHost drivers for SPI
Fusion MPT ScsiHost drivers for FC
Fusion MPT ScsiHost drivers for SAS
Fusion MPT misc device (ioctl) driver
の4つを有効にする。

VMwareでは、NICは、
AMD PCnet32 PCI
として認識されている。
Device Drivers -> Network device support -> Ethernet driver support ->
AMD PCnet32 PCI support
有効にする。
ついでに、
Device Drivers -> Network device support -> VMware VMXNET3 ethernet driver
も有効にした。

Device Drivers —>
Generic Driver Options —>
Maintain a devtmpfs filesystem to mount at /dev
を有効に

File system —> Second extended fs support
File system —> Ext3 journalling file system support
を有効にする。さらに出てくる子要素を全て有効にする。

File systems —>
Network File Systems:
NFS Client support 
とその子要素の適当なものが選択されていることを確認する。
File systems —>
Network File Systems:
NFS server support —>
NFS server support for NFS version 3 —>
NFS server support for the NFSv3 ACL protocol extension
NFS server support for NFS version 4 (EXPERIMENTAL)
を有効にする。

File systems —>
Kernel automounter version 4 support (also supports v3)
が選択されていることを確認する
File systems —>
Network File Systems —>
CIFS support
を有効にする。子要素はチェックしない。

コンパイルの実行。

make &&
cp -v arch/x86/boot/bzImage /boot/vmlinuz-3.8.10 &&
cp -v System.map /boot/System.map-3.8.10 &&
cp -v .config /boot/config-3.8.10 &&
install -d /usr/share/doc/linux-3.8.10 &&
cp -r Documentation/* /usr/share/doc/linux-3.8.10 &&
cd ../ &&
rm -rf linux-3.8.10

コンパイルしたカーネルや設定ファイルのバックアップを作成する。

mkdir /boot/backup-3.8.10-`date +%Y%m%d` &&
cp /boot/{vmlinuz-3.8.10,System.map-3.8.10,config-3.8.10} /boot/backup-3.8.10-`date +%Y%m%d`

GRUBのセットアップ

8.4. Using GRUB to Set Up the Boot Process に従って、GRUBをセットアップする。

grub-install /dev/sdb &&
cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5

insmod ext2
set root=(hd0,1)

menuentry "GNU/Linux, Linux 3.8.10" {
        linux /boot/vmlinuz-3.8.10 root=/dev/sda1 ro
}
EOF

起動の確認

この時点で、起動可能なことを確認する。
ESXi側でHDDが無いVMを作成し、LFS用の仮想HDDをコピーし、マウントする。正常にVMが起動すればOK。

後始末

9.1. The End に従って、LFSのバージョンをメモしておく。

echo "SVN-20130429 jhalfs" > /etc/lfs-release

rootパスワードを作成

passwd

ここまで実行

ALFS構築用のソースファイルをバックアップする。ソースファイルは、ファイルサーバーのどこかに置いてあればよく、個別のVMに保存する必要は無い。chroot環境の外から

cp -R /mnt/lfs/sources ~/src-lfs-svn20130429 &&
cd ~ && tar Jcf src-lfs-svn20130429.tar.xz src-lfs-svn20130429 &&
scp src-lfs-svn20130429.tar.xz 192.168.0.11:~

最後にLFS環境構築用の一時ファイルを削除する。chroot環境の外から

sudo rm -rf /mnt/lfs/{jhalfs,sources,src-lfs,tools}

ESXi上で仮想マシンテンプレートの構築 (その1 ALFSの実行)

作業日 2013/04/29

ESXi上で動かす仮想マシンのテンプレートを作成する。
手順としては、ALFSを利用してLFSシステムをセットアップした後、どのような用途の仮想マシンでも必要と思われるパッケージをインストールする。
今回の記事では、ALFSを実行し、設定ファイルの一部を編集するまで。

ホストとなるLinuxディストリビューションのインストール

LFSのセットアップには、ホストとなるLinuxシステムが必要である。
今回は、Ubuntu 12.04LTS Server 32bitを使用する。

まず、ESXi上にホストとなる仮想マシンを作成する。
仮想ディスクを2つ割り当て、片方はホストUbuntuのインストールに使用し、もう片方にLFSをセットアップする。
仮想デバイスノードに関しては、Utuntu用仮想ディスクは”SCSI (0:0)”を、LFS用仮想ディスクは”SCSI (0:1)”を設定。
今回、ディスクサイズは8GBをThin Provisionで割り当てた。
実際に仮想マシンとして動作させる時には、ファイルをコピーして使用するので、ここでのディスクサイズは何でも良い。
ただ、あまり小さいとLFSのセットアップ中にいっぱいになる。2GBだとだめだった

Ubuntuのインストールは、”OpenSSH Server”を選択する。
タイムゾーンは日本を選択した方が無難。

セットアップ後、IPアドレスを確認し、SSHで接続する。
以後は、SSH越しに操作。

ALFSの実行準備

まず、ALFSの実行に必要なパッケージをインストールする。

sudo apt-get -y install build-essential bison gawk texinfo subversion libncurses-dev libxml2-utils libxml2-dev xsltproc

次に、LFSをセットアップする仮想ディスクを準備する。

sudo fdisk -l

でLFS用仮想ディスクが割り当てられたデバイスファイル名を確認する。
今回は、/dev/sdbだった。

sudo fdisk /dev/sdb

全域を使ってプライマリパーティションを作成する。
そして、フォーマットとマウント。

sudo mkfs.ext3 /dev/sdb1 &&
sudo mkdir /mnt/lfs &&
sudo mount /dev/sdb1 /mnt/lfs &&
sudo chmod 777 /mnt/lfs

マウントは、ホスト仮想マシンを再起動すると解除されるので、その都度

sudo mount /dev/sdb1 /mnt/lfs &&

を実行する必要がある。

JHALFSをダウンロード。リリース版は古すぎて最新のLFSには対応していないので、SVNを使用して開発版をダウンロードする。

cd ~ &&
svn co svn://svn.linuxfromscratch.org/ALFS/jhalfs/trunk jhalfs

ALFSの実行

mkdir /tmp/src-lfs &&
cd ~/jhalfs &&
make

makeを実行すると、カーネルのコンパイル時のような設定エディタが出てくる。内容を下記のように編集する。Poderosa等、一部のターミナルからだとキーボードから文字列が入力できない場合がある。その場合、コンソールからログインして操作するか、configファイルを後でテキストエディタで編集する。

BOOK Settings —> Release はSVNのまま
General Settings —> Build Directory を /mnt/lfs に
General Settings —> Retrieve source files をオンに
General Settings —> Package Archive Directoryを /tmp/src-lfs に設定
General Settings —> Retry on ‘connection refused’ failure をオンに

Build Settings —> Tests level を All final system testsuites に
Build Settings —> Create a log of installed files for each package をオンに
Build Settings —> DO NOT use/display progress_bar をオンに(screenではうまく表示されないので)
Build Settings —> TimeZone を Asia/Tokyo に
Build Settings —> Language を ja_JP.UTF-8 に
Build Settings —> Groff page size を A4 に

設定をセーブし、確認画面でyを押すと、LFS Bookのダウンロードと、ソースのダウンロードを開始する。ここで、ダウンロードされないパッケージがあった場合は、ダウンロード先のサーバーが落ちている場合等なので、時間をおいてやり直すか、手動で別のサーバーからダウンロードして/tmp/src-lfsにコピーする。

記録を残しておくために、実行したLFS Book自体もダウンロードしておく。

svn co svn://svn.linuxfromscratch.org/LFS/trunk/BOOK/ ~/LFS-SVN-20130429

そして、ALFSを実行する。screen上でやった方が無難。

cd /mnt/lfs/jhalfs &&
make

実行中は、何回かsudo用のパスワードを入力する必要がある。

ALFSの後始末と基本的な設定

chroot環境に入るためのスクリプトを作成する。

sudo sh -c "
cat > /mnt/lfs/root/chroot.sh << "EOF"
#!/bin/bash
mount -v --bind /dev /mnt/lfs/dev
mount -vt devpts devpts /mnt/lfs/dev/pts
mount -vt tmpfs shm /mnt/lfs/dev/shm
mount -vt proc proc /mnt/lfs/proc
mount -vt sysfs sysfs /mnt/lfs/sys
chroot /mnt/lfs /usr/bin/env -i \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \
    /bin/bash --login +h
umount /mnt/lfs/sys
umount /mnt/lfs/proc
umount /mnt/lfs/dev/shm
umount /mnt/lfs/dev/pts
umount /mnt/lfs/dev
EOF" &&
sudo chmod +x /mnt/lfs/root/chroot.sh

以後、chroot環境に入るときは、

sudo /mnt/lfs/root/chroot.sh

を実行する。本記事の以後の操作は、全てchroot環境で実行する。

基本的な環境設定

これらの設定は、新しいLFS仮想マシンを起動した後、使用したい環境に合わせて再設定する。ここでは、とりあえず問題なく起動できる状態にすることを目指している。

7.2.2. Creating Network Interface Configuration Files は、IPアドレス等のNICの設定だが、これは後ほどDHCPクライアントをインストールする際に設定するので今回はスキップ。

Udevの新しいバージョンでは、NICをeth0みたいな名前ではなく、enp2s0みたいな名前に勝手に変えてしまう。それを避けるために下記を実行。

ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules

詳しくは、下記URLを参照。
http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames

7.2.3. Creating the /etc/resolv.conf Fileも、DHCPクライアントが自動的に作成するので本来は不要だが、chroot環境でwgetを実行するために当面必要なので作成する。

cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf

nameserver 192.168.0.1

# End /etc/resolv.conf
EOF

7.3. Customizing the /etc/hosts File に従って、/etc/hostsを作成する。

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

127.0.0.1 localhost newvm.example.net newvm

# End /etc/hosts
EOF

IPアドレスはDHCPで取得するので/etc/hostsにはIPアドレスは書かない。

7.8. Configuring the system hostnameに従って、ホスト名を設定。

echo "HOSTNAME=newvm" > /etc/sysconfig/network

8.2. Creating the /etc/fstab Fileに従って、/etc/fstabを作成。

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

# file system  mount-point  type     options             dump  fsck
#                                                              order

/dev/sda1      /            ext3     defaults            1     1
#/dev/sda2     swap         swap     pri=1               0     0
proc           /proc        proc     nosuid,noexec,nodev 0     0
sysfs          /sys         sysfs    nosuid,noexec,nodev 0     0
devpts         /dev/pts     devpts   gid=5,mode=620      0     0
tmpfs          /run         tmpfs    defaults            0     0
devtmpfs       /dev         devtmpfs mode=0755,nosuid    0     0

# End /etc/fstab
EOF

LFS用のディスクが/dev/sda1に割り当てられていることを仮定している。ESXiの設定で、仮想デバイスノードをSCSI (0:0)に設定すると、/dev/sdaになるはずである。