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になるはずである。

iSCSIサーバーのインストール (その4)

作業日: 28 Apr., 2013

VMを格納するデータストアとして暫定的に500GBの3.5インチハードディスクを使用していたが、ようやく320GBの2.5インチHDD×2のRAID1に置き換える。

準備

ベイの数や電源ケーブルの問題で、一旦RAID5を構成していたHDDを全部取り外し、新しい320GB 2.5インチHDD×2をセット。
このとき古い500GBの3.5インチHDDは付けたまま。
iSCSIサーバの電源を入れ、新しいHDDのデバイスファイル名をチェックする。

sudo fdisk -l

今回は、/dev/sdaと/dev/sdbに新HDDが、/dev/sdcに旧HDDが認識されていることがわかる。

次に、新HDDにパーティションを作成する。

sudo fdisk /dev/sda &&
sudo fdisk /dev/sdb

それぞれディスク全域を使用して基本パーティションを1つ作成し、ディスクIDを0xfd (Linux raid auto detect) に設定する。

RAIDの作成

2つのディスクを使用してRAID1を作成する、

sudo mdadm --create /dev/md/vmstore2 --level=1 --raid-devices=2 \
           /dev/sda1 /dev/sdb1

RAIDデバイスのデバイスファイルを固定化するため、UUIDで設定ファイルを作成する。

sudo sh -c "mdadm --detail --scan

で新しいRAIDのUUIDをチェックして、下記のように/etc/mdadm/mdadm.confを書き足す。

ARRAY /dev/md/vmstore2 metadata=1.2 UUID=f5dce1a3:574ba56b:47fd07a0:0f9be0b4

一旦/dev/md/vmtore2というデバイスファイル名で作成して、現在の/dev/md/vmstoreの内容をコピーした後、/dev/md/vmstoreに名前を変更する。

iSCSI用の設定を追加

新しいRAIDをiSCSIのターゲットとして設定する(同様に一旦vmstore2として作成する。)

sudo sh -c "
cat > /etc/tgt/targets.conf << EOF
<target iqn.2013-04.net.example.domino:vmstore2>
    backing-store /dev/md/vmstore2
</target>
EOF"

再起動

RAIDの同期に時間が掛かるので、下記コマンドで様子を見ながら終わるまで待つ。

cat /proc/mdstat

忘れないようにinitramを更新した後、再起動。

sudo update-initramfs -u &&
sudo reboot

再起動後、状態を確認

cat /proc/mdstat &&
sudo tgtadm --lld iscsi --op show --mode target

データのコピー

データストアのファイルフォーマットはESXi独自なので、一度ESXiでマウントしてからデータをコピーする。

vSphere Clientで、「構成」->「ストレージ」->「ストレージの追加…」から、新しく設定したvmstore2を選択してデータストアとして追加する。データストア名もvmstore2にする。

vSphare Client上で、データストアを右クリックして出てくる「データストアの参照」からファイルを移動することも出来るが、時間がかかる場合に不安点なので、ssh上で実行する。
sshでESXiにログインし、/vmfs/volumes/vmstore、から/vmfs/volumes/vmstore2にデータをコピーする。
nohupを使うと良い。
/vmfs/volumes/vmstore2に置かれたディレクトリは適当にリネームしておく。

VMの起動の確認

適当なVMがvmstore2から起動できるか確認する(ただし、iSCSIターゲットをRawディスクとしてマウントしているVMは、後回しにした方が良い。)

データストアブラウザ上で、適当なVMの仮想マシンファイル(.vmx)を右クリックして、インベントリに追加を選ぶ。
起動すると、仮想マシンの位置が変わっているという警告がでるが、”I moved it”か”I copied it” を選んで、無事に起動できることを確認する。

RAIDとiSCSIの設定を変更

用済みの500GB 3.5インチHDDを取り外し、2.5インチHDDのRAID1をvmstoreという名前で使用するように設定を変更する。

ESXiサーバとiSCSIサーバをシャットダウンする。
500GBのHDDを外して、RAID5を構成する2TB HDD×3を装着した上で、iSCSIサーバを起動。

まず、/etc/mdadm/mdadm.confを編集して、旧vmstoreに関する行を消し、vmstore2をvmstoreに変更する。
ちなみに消した行は

ARRAY /dev/md/vmstore metadata=1.2 UUID=493e9bab:bf4f4d93:13ae5ef2:1f277881

でファイルは、

ARRAY /dev/md/datastore metadata=1.2 UUID=ae189551:89069074:6d0d79a4:e0c921a6
ARRAY /dev/md/vmstore metadata=1.2 UUID=f5dce1a3:574ba56b:47fd07a0:0f9be0b4

のようになった。

さらに、/etc/tgt/targets.confを編集して、同様に旧vmstoreに関するエントリを消して、vmstore2をvmstoreに変える。

忘れずにinitramを更新して再起動する。

sudo update-initramfs -u &&
sudo reboot

ESXiサーバを起動すると、iSCSIの名前が変わりデータストアを認識できないと言われる。
「構成」->「ストレージ」->「ストレージの追加…」でvmstoreをデータストアとして追加する。
このとき、「既存の署名を保持」を選択すれば良い。決して再フォーマットしないこと、

残りのVMを上と同様の手順で再設定する。
ここで、iSCSIターゲットをRAWディスクとしてマウントしている仮想マシンは、一旦古いHDDの設定を削除して、再追加しないと起動できなかった。おそらく、iSCSIターゲットの名前を変更したためだと思われる(example.netになっていたのを正しいドメイン名に変更した。)

ESXi5.1へのアップデート

作業日: 29 Apr., 2013

ESXiの5.1がだいぶ前に登場していたようなので、5.0からアップデートする。

パッチのダウンロード

下記URLからパッチをダウンロード
http://www.vmware.com/patchmgr/findPatch.portal
適当に検索して、ESXi510-201303001.zipをダウンロード

ESXiのアップデート

まず、vSphere Clientから、全てのVM停止した後にメンテナンスモードに切り替える。ダウンロードしたファイルをvSphere Clientから適当な場所にアップロードする。

次に、sshでESXiにログインし、パッチファイルが置いてあるディレクトリで下記コマンドを実行。

esxcli software vib install -d ./ESXi510-201303001.zip

本来は、installではなくupdateのはずだがなぜか依存関係のエラーが出たので、installにした。再起動しろと言われるので、言われたとおりにESXiサーバを再起動する。

vSphere Clientのアップデート

vSphere Clientから繋ごうとすると、vSphere Clientをアップデートするように言われるので、指示に従ってアップデートする。

最後に、メンテナンスモードを解除して、VMを再起動する。

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