mac:gitをインストールしてgithubを使う

homebrewからgitをインストールする

brew install git

gitHubに登録する公開鍵を作る

cd ~/.ssh
ssh-keygen github_rsa
cat github_rsa

ここで表示した文字列でGithibのアカウント設定から公開鍵の登録を行う。

git pushしたしたときに、自動的に公開鍵認証するように~/.ssh/configを編集する

Host github.com
  User git
  Port 22
  Hostname github.com
  IdentityFile ~/.ssh/github_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes

mac:Homebrewでパッケージ管理

macのパッケージ管理ソフトといえばmacPortsやFinkが有名ですが、ニュータイプはHomebrewを使うらしいので、私も乗り換えてみました。

HomeBrewのインストール方法

1.以下のコマンドを実行

ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"

2.Xcodeをインストールする

1、2の順番がおすすめとのことだったが、私は既にXcodeをインストールしていたので、手順1だけ実行した。

ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/Formula/...
/usr/local/Library/Homebrew/...
==> The following directories will be made group writable:
/usr/local/.
/usr/local/include
/usr/local/lib
/usr/local/lib/pkgconfig
==> The following directories will have their group set to staff:
/usr/local/.
/usr/local/include
/usr/local/lib
/usr/local/lib/pkgconfig

Press enter to continue ★ここでEnterを押す
==> /usr/bin/sudo /bin/chmod g+w /usr/local/. /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig
Password:
==> /usr/bin/sudo /usr/bin/chgrp staff /usr/local/. /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig
==> Downloading and Installing Homebrew...
==> Installation successful!

で、問題なく入ったようなので、Homebrewを使ってwgetをインストールしてみる。

$ brew install wget
Warning: It appears you have Macports or Fink installed
Software installed with other package managers causes known problems for
Homebrew. If formula fail to build uninstall Macports/Fink and reinstall any
affected formula.
==> Downloading http://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file src/openssl.c
==> ./configure --disable-debug --prefix=/usr/local/Cellar/wget/1.12 --disable-i
==> make install
/usr/local/Cellar/wget/1.12: 9 files, 760K, built in 21 seconds

wgetはちゃんと入ったが警告が気になるのでmacPortsをアンインストールすることにした。

macportsのアンインストール方法

まず、macportsで何のパッケージをインストールしているか確認する。

port installed

ここでリストされた内容を全てアンインストールする。
Homebrewで入れ直す必要もあるだろうから、それまでリストは保存しておく。
またデーモンで動作しているパッケージがあったら、デーモンを停止すること。

ディレクトリを削除する。

sudo port -f uninstall installed

sudo rm -rf /opt/local \
/Applications/MacPorts \
/Applications/DarwinPorts \
/Library/Tcl/macports1.0 \
/Library/Tcl/darwinports1.0 \
/Library/LaunchDaemons/org.macports.* \
/Library/StartupItems/DarwinPortsStartup \
/Library/Receipts/MacPorts*.pkg \
/Library/Receipts/DarwinPorts*.pkg

確認のためもう一度wgetを入れてみると今度は警告なしでインストールできた。

brew remove wget  ★パッケージを削除するコマンドremove
Uninstalling /usr/local/Cellar/wget/1.12...
brew install wget  ★再インストール
==> Downloading http://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2
File already downloaded and cached to /Users/nakau/Library/Caches/Homebrew
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file src/openssl.c
==> ./configure --disable-debug --prefix=/usr/local/Cellar/wget/1.12 --disable-i
==> make install
/usr/local/Cellar/wget/1.12: 9 files, 760K, built in 17 seconds

Linux From Scratch:5.9~ 一時的環境の構築

特に問題なくインストールできたものは実行手順を割愛し、結果だけを記録する。

Binutils-2.20 – 2回め
問題なし

GCC-4.4.3 – 2回め
問題なし

Tcl-8.5.8
問題なし

Expect-5.43.0
ソースを解凍しようとしたところ、ot in gzip formatのエラー。

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error exit delayed from previous errors

wgetで取得しようとしたファイルがリンク切れになっていて、ダウンロード先のHTMLファイルを~.tar.gzというファイル名で保存していたのが原因だった。
SourceForgeからソースをダウンロードして解決した。

wget http://sourceforge.jp/projects/sfnet_buluoos/downloads/0.1/src/expect-5.43.0.tar.gz/
tar zxfv expect-5.44.1.15.tar.gz

あとは手順どおりにインストールできた。

DejaGNU-1.4.4
LFS-BOOKの手順どおり./configure したあとにmake installしたら、make checkでエラーになった。
以下の手順でmake checkがとおった。

./configure –prefix=/tools
make
make install
make check

Ncurses-5.7
問題なし

Bash-4.1
問題なし

Bzip2-1.0.5
問題なし

Coreutils-8.4
makeで以下のエラーが出た。

dd.c:492:16: warning: missing terminating ” character
dd.c:500:1: warning: missing terminating ” character
In file included from /tools/include/asm/ioctl.h:1,
from /tools/include/linux/ioctl.h:4,
from /tools/include/asm-generic/ioctls.h:4,
from /tools/include/asm/ioctls.h:1,
from /tools/include/bits/ioctls.h:24,
from /tools/include/sys/ioctl.h:27,
from /tools/include/sys/mtio.h:27,
from dd.c:1238:
/tools/include/asm-generic/ioctl.h:96:1: error: unterminated argument list invoking macro “fputs”

coreutilsのsrc/dd.cをviで開いて492行目を修正した。

修正前)      fputs (_("^
修正後)      fputs (_("

Diffutils-2.8.1
問題なし

Findutils-4.4.2
問題なし

Gawk-3.1.7
問題なし

Gettext-0.17
問題なし
※Gettext-0.17/gettext-toolsディレクトリの下でインストールを行うこと

Grep-2.5.4
問題なし

Gzip-1.4
問題なし

M4-1.4.13
問題なし

Make-3.81

/mnt/lfs/sources/patch-2.6.1/src/patch.c:1542: warning: the use of `mktemp’ is dangerous, better use `mkstemp’

というウォーニングが出たけどインストールはできたみたい。

Patch-2.6.1
問題なし?

Perl-5.10.1
問題なし

Sed-4.2.1
問題なし

Tar-1.22
問題なし

Texinfo-4.13a
問題なし

所有者の変更
以下のコマンドはrootユーザで実行すること

chown -R root:root $LFS/tools

Linux From Scratch:5.8 ツールチェーンの調整

これ以降にインストールするツール類は/mnt/lfs以下にインストールしたCコンパイラでコンパイルする。
そのためにスペックファイルを編集する。
以下のコマンドはスペックファイルをダンプしてリンカの参照パスを置き換えている。

SPECS=`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/specs
$LFS_TGT-gcc -dumpspecs | sed
  -e 's@/lib(64)?/ld@/tools&@g'
  -e "/^*cpp:$/{n;s,$, -isystem /tools/include,}" > $SPECS
echo "New specs file is: $SPECS"
unset SPECS

Linux From Scratch:gcc、glibcインストール

以降はLFS-BOOKに書いてあるとおりパッケージをインストールするだけなので、特に問題なくインストールできたものは実行手順を割愛し、結果だけを記録する。

Binutils-2.20 – 1回め
問題なし

GCC-4.4.3 – 1回め
問題なし

Linux-2.6.32.8 API ヘッダ
問題なし

Glibc-2.11.1
makeでこんなエラーがでた。

make[1]: *** No rule to make target `/mnt/lfs/sources/glibc-build/Versions.all’, needed by

`/mnt/lfs/sources/glibc-build/abi-versions.h’. Stop.
make[1]: Leaving directory `/mnt/lfs/sources/glibc-2.11.1′
make: *** [all] Error 2

そしてmakeの途中ではこんなメッセージがでている。

mawk: scripts/gen-sorted.awk: line 19: regular expression compile failed (bad class — [], [^]
or [)
/[^
mawk: scripts/gen-sorted.awk: line 19: syntax error at or near ]
mawk: scripts/gen-sorted.awk: line 19: runaway regular expression /, “”, subd …

インターネットで検索したら、「mawkではなく、gawkを使いなさい」とあったのでgawkをインストールした。

sudo apt-get install gawk
・・・
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Couldn’t find package gawk

パッケージが見つからないというエラーがでたので、パッケージをupdateする

sudo apt-get update

このあと、もう一度このコマンドを実行してgawkをインストールすると、今度は成功。

sudo apt-get install gawk

つづけて、make clean && make install を実行したら、さっきと同じエラーがでた。
./configureからやりなおしたら、今度は違うエラーがでた。

make[1]: *** [/mnt/lfs/sources/glibc-build/libc.so] Error 1
make[1]: Leaving directory `/mnt/lfs/sources/glibc-2.11.1′
make: *** [all] Error 2
lfs@ubuntu-vm:/mnt/lfs/sources/glibc-build$
lfs@ubuntu-vm:/mnt/lfs/sources/glibc-build$
lfs@ubuntu-vm:/mnt/lfs/sources/glibc-build$ uname -a
Linux ubuntu-vm 2.6.24-18-generic #1 SMP Wed May 28 20:27:26 UTC 2008 i686 GNU/Linux

これは途中でCFLAGの設定をしていなかったのが原因だった。
x86系CPUをマシンでは以下のコマンド実行が必須です。

case `uname -m` in
  i?86) echo "CFLAGS += -march=i486 -mtune=native" > configparms ;;
esac

もういちどmake。次はこんなエラー

/mnt/lfs/tools/bin/../lib/gcc/i686-lfs-linux-gnu/4.4.3/../../../../i686-lfs-linux-gnu/bin/ld:

cannot find -lgcc_eh
collect2: ld returned 1 exit status
make[2]: *** [/mnt/lfs/sources/glibc-build/iconv/iconvconfig] Error 1
make[2]: Leaving directory `/mnt/lfs/sources/glibc-2.11.1/iconv’
make[1]: *** [iconv/others] Error 2
make[1]: Leaving directory `/mnt/lfs/sources/glibc-2.11.1′
make: *** [all] Error 2

lgccが見つからない?
これもlfs-supportのメールアーカイブを検索して解決法を見つけました。
libgcc.a へのシンボリックリンクを作成すれば解決するとのこと。
すなわち、LFS-BOOKの”5.5. GCC-4.4.3 – Pass 1”最後に書いてあるコマンドを実行する。

ln -vs libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name |
    sed 's/libgcc/&_eh/'`

これで今度こそmakeできました。

Linux From Scratch:最初のパッケージインストール

いよいよLSF-BOOK第5章の本編であるパッケージインストールにとりかかる。

はじめにインストールするパッケージはBinutils-2.20である。

Binutilsをインストールすることによってリンカやアセンブラが使用可になる。

また初めにインストールするこのパッケージのインストール時間を計測することで、今後の作業時間を見積もることができる。

LFS-BOOKにはBinutils(1回目)の作業時間を1SBUとして、そのほかのパッケージインストールにかかる時間の目安が記載されている。

今後インストールするパッケージのインストール時間をbinutils-2.20のインストール時間を元に予測することができるので、最初のインストールは時間を計りながら行う。

tar jxfv binutils-2.20.tar.bz2
cd binutils-2.20
mkdir -v ../binutils-build
cd ../binutils-build

※通常パッケージのインストールは configure, make, make installで行う。
今回は時間を計るためにtimeコマンドとあわせて実行している。

time ../binutils-2.20/configure
    --target=$LFS_TGT --prefix=/tools
    --disable-nls --disable-werror
・・・
configure: creating ./config.status
config.status: creating Makefile

real	0m8.396s
user	0m1.792s
sys	0m5.624s

./configure問題なし。続いてmake

time make
・・・
make[4]: Leaving directory `/mnt/lfs/sources/binutils-build/ld'
make[3]: Leaving directory `/mnt/lfs/sources/binutils-build/ld'
make[2]: Leaving directory `/mnt/lfs/sources/binutils-build/ld'
make[1]: Nothing to be done for `all-target'.
make[1]: Leaving directory `/mnt/lfs/sources/binutils-build'

real	6m39.115s
user	3m7.888s
sys	2m14.172s

makeも問題なし。

time make install
・・・
make[3]: Entering directory `/mnt/lfs/sources/binutils-2.20/libiberty/testsuite'
make[3]: Nothing to be done for `install'.
make[3]: Leaving directory `/mnt/lfs/sources/binutils-2.20/libiberty/testsuite'
make[2]: Leaving directory `/mnt/lfs/sources/binutils-2.20/libiberty'
make[1]: Nothing to be done for `install-target'.
make[1]: Leaving directory `/mnt/lfs/sources/binutils-2.20'

real	0m15.395s
user	0m2.124s
sys	0m5.416s

以上でbinutilsのインストールが完了。
今回binutilsのインストールにかかった時間はおよそ7分。
これがこの環境での1SDUになる。

Linux From Scratch:環境設定

いまはlfsユーザでログインしている。
これからlfsユーザでパッケージのビルドを行うが、その前にlfsユーザの環境を整える必要がある。

この作業はホストシステムの環境や設定がビルド内容に影響を与えないようにするためである。
まず、lfsユーザが使用するシェルを/bin/bashに固定する設定を~/.bash_profileに記述する。

cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='u:w$ ' /bin/bash
EOF

このあと起動するシェルはbashとなる。
bash起動時に実行される.bashrcファイルに以下の設定を記述する。

~/.bashrc
cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
EOF

これらは今後使用する環境変数と、ホスト環境の設定によって動作が変わることを防ぐための設定である。

sourceコマンドで設定を即座に反映する。

source ~/.bash_profile

以上の設定を行った後、この環境にはこれだけの環境変数が設定されている。

lfs@ubuntu-vm:~$ env
SHELL=/bin/bash
TERM=xterm
LC_ALL=POSIX
USER=lfs
LFS=/mnt/lfs
MAIL=/var/mail/lfs
PATH=/tools/bin:/bin:/usr/bin
PWD=/home/lfs
LANG=ja_JP.UTF-8
LFS_TGT=i686-lfs-linux-gnu
SHLVL=1
HOME=/home/lfs
LOGNAME=lfs
_=/usr/bin/env

Linux From Scratch:パッケージインストールの準備

まず、パッケージをダウンロードする。
必要なパッケージのリストがここにあるので、wgetで一気に取得する。
ダウンロードする場所は$LFS/sourcesにする。

sudo mkdir -v $LFS/sources
cd $LFS/sources
wget http://www.linux.or.jp/JF/JFdocs/LFS-BOOK/wget-list.txt
wget -N -i wget-list.txt

パッケージは全て$LFS/toolsにインストールするので、そのためにディレクトリを作成する。

sudo mkdir -v $LFS/tools

次にホストシステムの/toolsにシンボリックリンクを作成する

ln -sv $LFS/tools /

これで、ホストシステムの/tools = LFSの/tools(/mnt/lfs/tools)になった。

$LFSには/mnt/lfsというパスが設定されていなければならない。
常にこの環境変数があるように、~/.bashrcに以下のように書いておくこと。

export LFS=/mnt/lfs

ご操作によってシステムを破壊してしまわないために、パッケージビルド作業は一般ユーザで行うのがよい。
LFS-BOOKの手順にならってlfsユーザ、lsfグループを作成する。

sudo groupadd lfs
sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs

次に、パスワードを任意のパスワードに変更する。

sudo passwd lfs

パッケージのインストール先とダウンロードしたソースをlfsユーザで操作できるようにファイルの所有権を変更する。

sudo chown -v lfs $LFS/tools
sudo chown -v lfs $LFS/sources

以降の作業はlfsユーザで行うので、lfsユーザに切り替える。

su -lfs

Linux From Scratch:ファイルシステムをマウント

作成したファイルシステムをLFS環境用として/mnt/lfsにマウントする。
ルート領域は/mnt/lfs、ブート領域は/mnt/lfs/bootにマウントした。
スワップ領域はswaponコマンドで有効にする。

$ export LFS=/mnt/lfs
$ sudo mkdir -pv $LFS
mkdir: created directory `/mnt/lfs'
$ sudo mount -v -t ext3 /dev/sdb3 $LFS
/dev/sdb3 on /mnt/lfs type ext3 (rw)
$ sudo mkdir -v $LFS/boot
mkdir: created directory `/mnt/lfs/boot'
$ sudo mount -v -t ext3 /dev/sdb1 $LFS/boot
/dev/sdb1 on /mnt/lfs/boot type ext3 (rw)
$ sudo swapon /dev/sdb2
$ df
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/sda1             19891060   2242116  16646492  12% /
varrun                  257788       104    257684   1% /var/run
varlock                 257788         0    257788   0% /var/lock
udev                    257788        60    257728   1% /dev
devshm                  257788        12    257776   1% /dev/shm
lrm                     257788     38176    219612  15% /lib/modules/2.6.24-18-generic/volatile
/dev/sdb3              9794044    152908   9147540   2% /mnt/lfs
/dev/sdb1               101086      5664     90203   6% /mnt/lfs/boot

Linux From Scratch:新しいパーティションを生成

新しく追加したハードディスク/dev/sdbにパーティションを追加する。
パーティションの作成はfdiskコマンドで対話的に行う。
w(書き込み)を実行しない限りは何度でもパテーションを切りなおせる。

$ sudo fdisk /dev/sdb
デバイスは正常な DOS 領域テーブルも、Sun, SGI や OSF ディスクラベルも
含んでいません
Building a new DOS disklabel with disk identifier 0xa8c00198.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

このディスクのシリンダ数は 1305 に設定されています。
間違いではないのですが、1024 を超えているため、以下の場合
に問題を生じうる事を確認しましょう:
1) ブート時に実行するソフトウェア (例. バージョンが古い LILO)
2) 別の OS のブートやパーティション作成ソフト
   (例. DOS FDISK, OS/2 FDISK)
警告: 領域テーブル 4 の不正なフラグ 0x0000 は w(書き込み)によって
正常になります

コマンド (m でヘルプ): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes
Disk identifier: 0x8b69762a

デバイス Boot      Start         End      Blocks   Id  System

コマンド (m でヘルプ): n
コマンドアクション
   e   拡張
   p   基本領域 (1-4)
p
領域番号 (1-4): 1
最初 シリンダ (1-1305, default 1): 1
終点 シリンダ または +サイズ または +サイズM または +サイズK (1-1305, default 1305): +100M

コマンド (m でヘルプ): n
コマンドアクション
   e   拡張
   p   基本領域 (1-4)
p
領域番号 (1-4): 2
最初 シリンダ (14-1305, default 14): 14
終点 シリンダ または +サイズ または +サイズM または +サイズK (14-1305, default 1305): +512M

コマンド (m でヘルプ): n
コマンドアクション
   e   拡張
   p   基本領域 (1-4)
p
領域番号 (1-4): 3
最初 シリンダ (77-1305, default 77): 77
終点 シリンダ または +サイズ または +サイズM または +サイズK (77-1305, default 1305): 1305

コマンド (m でヘルプ): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = シリンダ数 of 16065 * 512 = 8225280 bytes
Disk identifier: 0xc4a5459c

デバイス Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          13      104391   83  Linux
/dev/sdb2              14          76      506047+  83  Linux
/dev/sdb3              77        1305     9871942+  83  Linux

コマンド (m でヘルプ): w
領域テーブルは交換されました!

ioctl() を呼び出して領域テーブルを再読込みします。
ディスクを同期させます。

次にパーティションにファイルシステムを作成する。
ファイルシステムの作成はmke2fsコマンドを使う。
-jを指定してext3 のファイルシステムを作成する。

$ sudo mke2fs -jv /dev/sdb1
mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
26104 inodes, 104388 blocks
5219 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

$ sudo mkswap /dev/sdb2
Setting up swapspace version 1, size = 518184 kB
no label, UUID=3e1db6f5-0177-4765-8d06-66486ec91980

$ sudo mke2fs -jv /dev/sdb3
mke2fs 1.40.8 (13-Mar-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
617728 inodes, 2467985 blocks
123399 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2529165312
76 block groups
32768 blocks per group, 32768 fragments per group
8128 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.