CrashPlanバックアップ用のVMの構築

paradiseがNFSでシェアしている/homeをクラウドにバックアップ。
CrashPlanのサービスを使用。

バックアップ専用VMのインストール

Ubuntu Server 14.04 LTS (64bit)で新規VMをデプロイ。ホスト名をpompeiiにする。
adminというユーザー名が作成できないので、一旦別の名前 (ここではpompeiiadmin)で作成して、後から変更の予定。
基本的に最小構成で、OpenSSH Serverのみインストール。

pompeiiadminでログインし、下記を実行。新規ユーザーpompeiiを作成。

sudo groupadd -g 1100 admin &&
sudo mkdir /opt/home &&
sudo useradd -d /opt/home/admin -m -g admin -u 1100 -s /bin/bash &&
sudo usermod -G adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare admin &&
sudo passwd admin

adminでログインし直し、下記を実行。pompeiiadminを削除。

sudo userdel pompeiiadmin &&
sudo rm -rf /home/pompeiiadmin

IPの固定化。/etc/network/interfacesを下記のように編集。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.12
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 192.168.0.1

NFSで/homeのマウント。

sudo apt-get install nfs-common

で、nfs関連プログラムをインストールし、/etc/fstabに下記の行を追加

192.168.0.11:/home	/home	nfs	rw,nfsvers=3	0	0

CrashPlanをインストール。

wget http://download2.us.code42.com/installs/linux/install/CrashPlan/CrashPlan_3.7.0_Linux.tgz &&
tar zxf CrashPlan_3.7.0_Linux.tgz &&
cd CrashPlan-install &&
sudo ./install.sh &&
cd ../ &&
rm -rf CrashPlan-install

基本的に全てデフォルトの設定でOK

Macから設定が出来るように設定変更。

sudo cp /usr/local/crashplan/conf/my.service.xml{,bak} &&
sudo sed -i -e 's%<serviceHost>127.0.0.1</serviceHost>%<serviceHost>0.0.0.0</serviceHost>%g' /usr/local/crashplan/conf/my.service.xml &&
sudo /etc/init.d/crashplan restart

Macの設定

MacにもCrashPlanをインストール。
/Applications/CrashPlan.app/Contents/Resources/Java/conf/ui.propertiesで、

serviceHost=192.168.0.12

を設定し、GUIでpompeiiに繋げるようにする。

GUI上から、/home全体をバックアップするように設定。

RAID5の再構築

作業日: 6 Apr., 2015

スペアを含めて4台のHDDで構成していたRAID5だが、HDDが2つ壊れてしまったので、新しいHDDを買ってRAID5を再構成。
その内にRAID5の容量拡張もしたいので、一旦緊急避難的に1台だけ追加。

準備

まず、壊れたHDDを取り除いて、新しいHDDをセットし、PCを起動。

cat /proc/mdstat

md127 : active raid5 sdc1[1] sdb1[3]
      3907023872 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]

のように表示され、U_となっていることから、RAID5がDegradedとなっていることがわかる。

新HDDのパーティショニング

sudo fdisk -l

で、新しいHDDは、/dev/sdaと認識されていることがわかった。
下記のような表示。

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/sda doesn't contain a valid partition table

ちなみに、そのカウンターパートのHDDは、/dev/sdb、/dev/sdcとして認識され、

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
81 heads, 63 sectors/track, 765633 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907029167  1953513560   fd  Linux raid autodetect

及び、

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
81 heads, 63 sectors/track, 765633 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x56697a44

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  3907029167  1953513560   fd  Linux raid autodetect

のようになっている。

今回は、両方のHDDのセクター数は同じであるため、

sudo fidsk /dev/sde

で全域を使って基本パーティションを作成し、ディスクラベルをfd Linux raid autodetectに設定。

sudo fdisk -l

の表示は、

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
81 heads, 63 sectors/track, 765633 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x25f3cca8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048  3907029167  1953513560   fd  Linux raid autodetect

のようになる。

RAID5の再構築

RAID5に新しいディスクを追加する。RAID5は/dev/md/datastoreとして設定されているので、

sudo mdadm --manage /dev/md/datastore --add /dev/sda1

を実行。
ちなみに、RAIDのパスは、/etc/mdadm/mdadm.confに書かれている。別に、/proc/mdstatの/mdev/md127を使っても良い。

後は、

sudo cat /proc/mdstat

で進捗状況を確認。

途中では、

md127 : active raid5 sda1[4] sdc1[1] sdb1[3]
      3907023872 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
      [>....................]  recovery =  0.0% (645720/1953511936) finish=1108.9min speed=29350K/sec

みたいになるが、終了すると

XXXX

のようになる。

RAID5にスペアディスク追加

作業日: 2 May., 2014

2GB×3で運用していたRAID5にHDDをホットスペアで1台追加。
(その内に2GB×4のRAID5に拡張するつもりだったが、結局やらずじまい)

準備

2GBのHDDを購入して、追加。
/dev/sdaとして認識され、fdisk -lでは下記のようになる。

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sda doesn't contain a valid partition table

新HDDのパーティショニング

sudo fdisk /dev/sda

で、ディスク全体でパーティションタイプがfd Linux autodetectのパーティションを作成

ホットスペアとしてディスクを追加

下記コマンドでホットスペアとして追加。

sudo mdadm --manage /dev/md/datastore --add /dev/sda1
cat /proc/mdstat

で状況を確認すると、

md127 : active raid5 sda1[4](S) sdd1[1] sdc1[3] sdb1[0]
      3907023872 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

のようになる。
sda[4](S)となっているのが、ホットスペアのディスク。

状況を詳細に確認するために、

sudo mdadm --misc --detail /dev/md/datastore

を実行すると、

/dev/md/datastore:
        Version : 1.2
  Creation Time : Tue Mar 13 00:10:46 2012
     Raid Level : raid5
     Array Size : 3907023872 (3726.03 GiB 4000.79 GB)
  Used Dev Size : 1953511936 (1863.01 GiB 2000.40 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Fri May  2 14:47:56 2014
          State : clean
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 512K

           Name : domino:datastore  (local to host domino)
           UUID : ae189551:89069074:6d0d79a4:e0c921a6
         Events : 126

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       49        1      active sync   /dev/sdd1
       3       8       33        2      active sync   /dev/sdc1

       4       8        1        -      spare   /dev/sda1

のようになる。

(未実行)領域の拡張

もし、領域を拡張したい場合は、下記のように実行。(やってないけど)

sudo mdadm --grow /dev/md/datastore --raid-disks=4

iSCSIサーバーのソフトウェアRAID再構築

作業日: 12 Apr., 2014

RAID1を構成するHDDの一つが壊れたので、新しいHDDを買ってRAID1を再構成。

準備

まず、壊れたHDDを取り除いて、新しいHDDをセットし、PCを起動。

cat /proc/mdstat

md126 : active raid1 sdd1[0]
      312569040 blocks super 1.2 [2/1] [U_]

のように表示され、U_となっていることから、RAID1がDegradedとなっていることがわかる。

新HDDのパーティショニング

sudo fdisk -l

で、新しいHDDは、/dev/sdeと認識されていることがわかった。
下記のような表示。

Disk /dev/sde: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/sde doesn't contain a valid partition table

ちなみに、そのカウンターパートのHDDは、/dev/sddとして認識され、

Disk /dev/sdd: 320.1 GB, 320072933376 bytes
81 heads, 63 sectors/track, 122504 cylinders, total 625142448 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8d0ff01f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048   625142447   312570200   fd  Linux raid autodetect

のようになっている。

今回は、両方のHDDのセクター数は同じであるため、

sudo fidsk /dev/sde

で全域を使って基本パーティションを作成し、ディスクラベルをfd Linux raid autodetectに設定。セクター数が違う場合は、RAIDに使用するパーティションのセクター数を元々ある方と一致させる。違っていても、よりサイズが大きい場合はRAIDは作れるけど容量が無駄になる。

RAIDの再構築

RAID1に新しいディスクを追加する。RAID1は/dev/md/vmstoreとして設定されているので、

sudo mdadm --manage /dev/md/vmstore --add /dev/sde1

を実行。
ちなみに、RAID1のパスは、/etc/mdadm/mdadm.confに書かれている。別に、/proc/mdstatの/mdev/md126を使っても良い。

後は、

sudo cat /proc/mdstat

で進捗状況を確認。

途中では、

md126 : active raid1 sde1[2] sdd1[0]
      312569040 blocks super 1.2 [2/1] [U_]
      [>....................]  recovery =  0.8% (2603712/312569040) finish=71.1min speed=72620K/sec

みたいになるが、終了すると

md126 : active raid1 sde1[2] sdd1[0]
      312569040 blocks super 1.2 [2/2] [UU]

のようになる。320GB程度なので、1~2時間で終了。

OpenVPNサーバーの構築 (Linode)

vpn接続用のサブドメインとして、vpn.example.netを使用するので、DNSの設定をしておく。

まず、依存関係のあるlzo-2.06をインストール。BLFSより。

cd ~/src &&
wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz &&
tar zxf lzo-2.06.tar.gz &&
cd lzo-2.06 &&
./configure --prefix=/usr                    \
            --enable-shared                  \
            --disable-static                 \
            --docdir=/usr/share/doc/lzo-2.06 &&
make &&
make check &&
sudo make install &&
cd ../ &&
rm -rf lzo-2.06

最後にOpenVPNサーバーをインストール。

cd ~/src &&
wget http://swupdate.openvpn.org/community/releases/openvpn-2.3.2.tar.gz &&
tar zxf openvpn-2.3.2.tar.gz &&
cd openvpn-2.3.2 &&
./configure --prefix=/usr \
            --sysconfdir=/etc \
            --localstatedir=/var \
            --libexecdir=/usr/lib \
            --docdir=/usr/share/doc/openvpn-2.3.2 &&
make &&
sudo make install &&
sudo cp -R sample /usr/share/doc/openvpn-2.3.2 &&
sudo mkdir /etc/openvpn &&
sudo cp sample/sample-config-files/server.conf /etc/openvpn &&
cd ../ &&
rm -rf openvpn-2.3.2

OpenVPNサーバー用のSSL認証を取得する。SSL認証局から公開認証と秘密鍵を取得する。下記はStartSSLを想定。

sudo mkdir -p /etc/ssl/openvpn/{private,certs}

公開認証を/etc/ssl/openvpn/certs/cert.pemに、秘密鍵を/etc/ssl/openvpn/private/key.pemとして保存する。

sudo openssl rsa -in /etc/ssl/openvpn/private/key.pem \
                 -out /etc/ssl/openvpn/private/key.nopass.pem &&
sudo chmod 400 /etc/ssl/openvpn/certs/cert.pem /etc/ssl/openvpn/private/key{,.nopass}.pem &&
sudo wget -P /etc/ssl/openvpn/certs https://www.startssl.com/certs/sub.class1.server.ca.pem &&
sudo wget -P /etc/ssl/openvpn/certs https://www.startssl.com/certs/ca.pem &&
sudo sh -c "cat /etc/ssl/openvpn/certs/sub.class1.server.ca.pem >> /etc/ssl/openvpn/certs/ca.pem" &&
sudo rm /etc/ssl/openvpn/certs/sub.class1.server.ca.pem &&
sudo chmod 400 /etc/ssl/openvpn/certs/ca.pem &&
sudo openssl dhparam -out /etc/ssl/openvpn/dh2048.pem 2048 &&

OpenVPNの設定

sudo emacs /etc/openvpn/server.conf

下記の行を書き換える。

ca /etc/ssl/openvpn/certs/ca.pem
cert /etc/ssl/openvpn/certs/cert.pem
key /etc/ssl/openvpn/private/key.nopass.pem
dh /etc/ssl/openvpn/dh2048.pem

下記の行をコメントアウト。

push "redirect-gateway def1 bypass-dhcp"
duplicate-cn
user nobody
group nogroup

下記の行を追加。

script-security 2
client-cert-not-required
username-as-common-name
plugin /usr/lib/openvpn/plugins/openvpn-plugin-auth-pam.so login

次に、VPN接続してきたクライアントが、VPNサーバー経由でインターネットアクセスできるようにするため、iptablesをインストール。

cd ~/src &&
wget http://www.netfilter.org/projects/iptables/files/iptables-1.4.21.tar.bz2 &&
tar jxf iptables-1.4.21.tar.bz2 &&
cd iptables-1.4.21 &&
./configure --prefix=/usr                \
            --sbindir=/sbin              \
            --with-xtlibdir=/lib/xtables \
            --enable-libipq &&
make &&
sudo make install &&
sudo ln -sfv ../../sbin/xtables-multi /usr/bin/iptables-xml &&
for file in ip4tc ip6tc ipq iptc xtables
do
  sudo mv -v /usr/lib/lib${file}.so.* /lib &&
  sudo ln -sfv ../../lib/$(readlink /usr/lib/lib${file}.so) /usr/lib/lib${file}.so
done &&
cd ../ &&
rm -rf iptables-1.4.21 &&
wget http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20131023.tar.bz2 &&
tar jxf blfs-bootscripts-20131023.tar.bz2 &&
cd blfs-bootscripts-20131023 &&
sudo make install-iptables &&
cd ../ &&
rm -rf blfs-bootscripts-20131023

iptablesの起動スクリプトは最新のLFS用で、Linodeの LFSでは動かないので、修正。
. /lib/lsb/init-functions

. /etc/sysconfig/rc
. ${rc_functions}

sys_info_msgを
boot_mesgに

iptablesの設定ファイルを作成

sh -c 'cat > /etc/rc.d/rc.iptables << EOF
# Enable packet forwarding
sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

# OpenVPN
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT

# Allow TUN interface connections to OpenVPN server
iptables -A INPUT -i tun+ -j ACCEPT

# Allow TUN interface connections to be forwarded through other interfaces
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT

# NAT the VPN client traffic to the internet
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
EOF' &&
sudo chmod +x /etc/rc.d/rc.iptables

起動スクリプトの作成

sudo sh -c 'cat > /etc/rc.d/init.d/openvpn << EOF
#!/bin/sh
########################################################################
# Begin \$rc_base/init.d/openvpn
#
# Description : OpenVPN init script
#
# Authors     : Hiromasa Fujihara
#
# Version     : 00.01
#
# Notes       :
#
########################################################################

. /etc/sysconfig/rc
. \${rc_functions}

case "\${1}" in
        start)
                boot_mesg "Starting OpenVPN Server..."
                /usr/sbin/openvpn --config /etc/openvpn/server.conf --daemon
                evaluate_retval
                ;;

        stop)
                boot_mesg "Stopping OpenVPN Server..."
                killall openvpn
                evaluate_retval
                ;;

        restart)
                \${0} stop
                sleep 1
                \${0} start
                ;;

        *)
                echo "Usage: \${0} {start|stop|restart}"
                exit 1
                ;;
esac

# End $rc_base/init.d/openvpn
EOF' &&
sudo chmod +x /etc/rc.d/init.d/openvpn &&
sudo ln -s ../init.d/openvpn /etc/rc.d/rc1.d/K11openvpn &&
sudo ln -s ../init.d/openvpn /etc/rc.d/rc2.d/K11openvpn &&
sudo ln -s ../init.d/openvpn /etc/rc.d/rc3.d/S39openvpn &&
sudo ln -s ../init.d/openvpn /etc/rc.d/rc4.d/S39openvpn &&
sudo ln -s ../init.d/openvpn /etc/rc.d/rc5.d/S39openvpn &&
sudo ln -s ../init.d/openvpn /etc/rc.d/rc6.d/K11openvpn

クライアントからのアクセス
iOSからはOpenVPN Connect、MacからはTunnelblick、WindowsからはOpenVPN GUIで繋いだ。
他にもクライアントは色々ある模様。
設定ファイルとして下記のようなファイルを拡張子ovpnで作成し、クライアントソフトにインポートする。
iOSはメールの添付ファイルが手っ取り早い。
Tunnelblickはフォルダを作成し、フォルダ内にこのファイルを入れ、フォルダ名末尾に”.tblk”を付けると、ダブルクリックでインポートできる。

client
dev tun
proto udp
remote vpn.example.net 1194
resolv-retry infinite
nobind
persist-key
persist-tun
<ca>
-----BEGIN CERTIFICATE-----
(省略、上記/etc/ssl/openvpn/certs/ca.pemの内容)
-----END CERTIFICATE-----
</ca>
comp-lzo
verb 3
auth-user-pass

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の設定も必要になる。