gentoo 構築
http://www.gentoo.org/doc/ja/handbook/handbook-x86.xml?part=1 ここを見れば大体大丈夫
手順1
ディスクの準備
fdiskでパーティションを切る。
sda1 /boot mkfs.ext2 sda2 swap mkswap sda3 / mk.ext4
マウントする。
mkdir /mnt/gentoo mount /dev/sda3 /mnt/gentoo mkdir /mnt/gentoo/boot mount /dev/sda1 /mnt/gentoo/boot
手順2
DLする。 http://ftp.jaist.ac.jp/pub/Linux/Gentoo/releases/x86/current-stage3/ http://ftp.jaist.ac.jp/pub/Linux/Gentoo/snapshots/
展開するときにstage3にはパーミッションを保持するように...
cd /mnt/gentoo tar xjfvp stage3.tar.bz tar xjfv portage.tar.bz -C usr
vi etc/make.conf
CFLAGS="-march=native -O2 -fomit-frame-pointer -pipe" CXXFLAGS="${CFLAGS}" CHOST="i686-pc-linux-gnu" #64bitの時は上を消して下を使う #CHOST="x86_64-pc-linux-gnu" MAKEOPTS="-j4" #コア数X2程度
======= 余談 =======
"-march=native" は gcc-4.2 から導入された gcc がCPUを自動判定して、CPU用の最適化オプションをつけてくれもの
http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/i386-and-x86_002d64-Options.html#index-march-1395
細かい設定はここにある
#!/bin/sh CC="gcc" OPT="-march=native" NATIVE=$(echo | ${CC} -E -v ${OPT} - 2>&1 | grep cc1) NOARCH=$(echo | ${CC} -E -v - 2>&1 | grep cc1) for native in ${NATIVE} ; do FOUND=0 for noarch in ${NOARCH} ; do if [ "${native}" = "${noarch}" -a "${native}" != "${OPT}" ] ; then FOUND=1 break fi done if [ ${FOUND} -eq 0 ] ; then echo -n "${native} " fi done echo
(引用:http://d.hatena.ne.jp/tmatsuu/20090110/1231557035)
こちらの方のスクリプトでnativeの設定を展開できるらしい。
nativeにしてあとで展開しちゃえばおkってことですね。
======= 余談終了 =======
gentooのミラー先指定
mirrorselect -i -o >> /mnt/gentoo/etc/make.conf mirrorselect -i -r -o >> /mnt/gentoo/etc/make.conf
しかし、できない環境(Gentoo公式じゃないLiveCDからの構築等)もあるよね。
vi etc/make.conf GENTOO_MIRRORS="http://ftp.jaist.ac.jp/pub/Linux/Gentoo" SYNC="rsync://ftp.jaist.ac.jp/pub/Linux/Gentoo-portage"
追記する
chrootの前設定
cp -L /etc/resolv.conf /mnt/gentoo/etc/ mount -t proc none /mnt/gentoo/proc mount --rbind /dev /mnt/gentoo/dev chroot /mnt/gentoo /bin/bash env-update # Regenerating /etc/ld.so.cache... source /etc/profile emerge --sync eselect profile list eselect profile set 3
USEフラグをつける。インストールしたいパッケージを記入、いらないのにマイナスをつける。
less /usr/portage/profiles/use.desc nano -w /etc/make.conf USE="-gtk -gnome qt4 kde dvd alsa cdr" //正直いまは設定しないでもいい
nano -w /etc/locale.gen locale-gen cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
Kernel
『注意』
共にKernelの設定をするときに最適化を重視するべきなのでMenuconfig時に
Processor type and features ---> Processor family(適切なCoreを選択すること!!!)
通常
emerge gentoo-sources cd /usr/src/linux/ make menuconfig make make modules_install cp arch/i386/boot/bzImage /boot/kernel-2.6.34-gentoo-r1
モジュール設定&必要アプリインストール
emerge syslog-ng vixie-cron vim mlocate rc-update add syslog-ng default rc-update add vixie-cron default find /lib/modules/<kernel version>/ -type f -iname '*.o' -or -iname '*.ko' >> /etc/make.conf vi /etc/make.conf :% s/^\/.*\//modules="/g :% s/.ko$/"/g
初期設定類
vi /etc/fstab /dev/sda1 /boot ext2 defaults 1 2 /dev/sda3 / ext4 noatime 0 1 /dev/SWAP none swap sw 0 0 /dev/cdrom /mnt/cdrom auto noauto,ro 0 0
詳細については http://www.gentoo.org/doc/ja/handbook/handbook-amd64.xml?part=1&chap=8
vi /etc/conf.d/hostname hostname="tux"
vi /etc/conf.d/net config_eth0="192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255" routes_eth0="default via 192.168.0.1"
または
config_eth0="dhcp"
但しDHCPを使う場合は
emerge dhcpcd
cd /etc/init.d ln -s net.lo net.eth0 rc-update add net.eth0 default
vi /etc/conf.d/keymaps vi /etc/conf.d/hwclock passwd
Grub
emerge grub vi /boot/grub/menu.lst default 0 timeout 30 splashimage=(hd0,0)/boot/grub/splash.xpm.gz title Gentoo Linux root (hd0,0) kernel /boot/kernel-genkernel-x86_64-3.7.10-gentoo root=/dev/ram0 real_root=/dev/sda3 initrd /boot/initramfs-genkernel-x86_64-3.7.10-gentoo
grep -v rootfs /proc/mounts > /etc/mtab grub-install --no-floppy /dev/sda
Portageについて
http://www.gentoo.org/doc/ja/handbook/handbook-x86.xml?part=2&chap=1
http://www.gentoo.org/doc/ja/portage-manual.xml
http://www.gentoo.org/doc/ja/portage-user.xml
バラバラなのがナンセンスに感じる.
しかしその分詳しく載ってるのでGood
システム等の更新
(すべて-pをつけて実行前に確認を行うことが望ましい.) システムのみを更新する場合は
emerge -u system
システムを含むソフトウェアやライブラリを更新する場合は
emerge -u world
システムを依存関係を含めて更新する
emerge --update --deep world
システムの全てを更新する (これはコンパイルとビルドの間には必要ではあるものの、 インストールが終わってしまえばもう必要ないようなパッケージを含めて(ビルド依存:build dependencies)更新する)
emerge --update --deep --with-bdeps=y world
USEフラグを変更したならば,適応するように再コンパイルする必要が出てくるかもしれません! その場合には--newuseを追加しましょう!
--newuse
完全な更新の実行(しかし大変時間がかかり,安定した今の環境とはかけ離れる可能性もあります.バックアップ推奨)
emerge --update --deep --newuse --with-bdeps=y world
便利なコマンド
検索する,ライセンスを確認する
emerge --search gcc
実行前に実験する(-pでも可)
emerge --pretend <任意でoption> <パッケージ名>
使えるUSEフラグを調べる(--verbose)
emerge -pv gentoo-sources
変更情報取得
emerge -pl mozilla
アンインストール
emerge --unmerge gnumeric
sshについて
Config上Password認証がNOになっているので注意 また,一般ユーザーからsuでrootには標準ではなれない.
vi /etc/ssh/sshd_config PasswordAuthentication yes PermitRootLogin no
vi /etc/group wheel:x:10:root,USERIDを追記
Gentooを使った自作LiveDVDの作り方
http://en.gentoo-wiki.com/wiki/Build_Your_Own_LiveCD_or_LiveDVD
英語だけどどうせコマンドばかりなので特に訳す必要はない.
しかしまとめておきたいのでここに記載する.
初期設定
emerge squashfs-tools cdrtools export LIVECD=~/livecd export TARGET=${LIVECD}/target export TARGET_SOURCE=${TARGET}/files/source export SOURCE=${LIVECD}/source mkdir -p ${LIVECD}/source cd ${LIVECD} wget stage portage cd ${LIVECD}/source tar -xvjpf ${LIVECD}/stage3-*.tar.bz2 tar -xvjpf ${LIVECD}/portage-latest.tar.bz2 -C usr
基本システムのインストール開始
cd ${LIVECD}/source mkdir proc dev sys mount --bind /proc proc mount --bind /dev dev mount --bind /sys sys mkdir -p usr/portage/distfiles mount --bind /usr/portage/distfiles usr/portage/distfiles cp /etc/resolv.conf ${LIVECD}/source/etc cp /etc/make.conf ${LIVECD}/source/etc chroot . /bin/bash --login # now we are in the chrooted environment env-update && source /etc/profile passwd
nano /etc/make.conf CFLAGS="-march=pentium4 -O2 -fomit-frame-pointer -pipe" CXXFLAGS="${CFLAGS}" CHOST="i686-pc-linux-gnu" MAKEOPTS="-j96" GENTOO_MIRRORS="ftp://ftp.iij.ad.jp/pub/linux/gentoo/ http://ftp.iij.ad.jp/pub/linux/gentoo/ http://ftp.jaist.ac.jp/pub/Linux/Gentoo/ ftp://ftp.jaist.ac.jp/pub/Linux/Gentoo/" SYNC="rsync://rsync3.jp.gentoo.org/gentoo-portage" USE="-X -doc" emerge -1 gcc emerge -1 glibc emerge -e world --exclude glibc --exclude gcc ln -sf /usr/share/zoneinfo/file> /etc/localtime emerge memtest86+ localepurge genkernel gentoolkit dmraid livecd-tools vim emerge <required packages, as you like, e.g. logger udev eix gentoolkit> rc-update add <applications that need to be started upon system start-up> default emerge scripts emerge mingetty
vi /etc/fstab /dev/loop0 / squashfs defaults 0 0 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0
Kernel
emerge gentoo-sources genkernel cd /usr/src/linux [make allmodconfig] OR genkernel --menuconfig all してSaveしてCTL+C(.configを作っちゃえ)
必要最低限な設定
General setup ---> <*> Initial RAM filesystem and RAM disk (initramfs/initrd) support File systems ---> <*> Ext3 journalling file system support <*> Reiserfs support <*> JFS filesystem support <*> XFS filesystem support Miscellaneous filesystems ---> <*> SquashFS 4.0 - Squashed file system support CD-ROM/DVD Filesystems ---> <*> ISO 9660 CDROM file system support Pseudo filesystems ---> [*] Virtual memory file system support (former shm fs) Device Drivers ---> Block devices ---> <*> Loopback device support <*> RAM block device support (16) Default number of RAM disks (9000) Default RAM disk size (kbytes) ATA/ATAPI/MFM/RLL support ---> <*> Include IDE/ATAPI CDROM support
genkernel initramfs genkernel all --no-splash --no-clean --menuconfig cp /boot/initramfs-genkernel-x86-2.6.37-gentoo-r4 /boot/initrd cp /boot/kernel-genkernel-x86-2.6.37-gentoo-r4 /boot/vmlinuz
補足設定
emerge app-admin/localepurge
vi /etc/locale.nopurge MANDELETE SHOWFREEDSPACE VERBOSE en en_US.UTF-8
localepurge makewhatis -u find / -type l ! -xtype f ! -xtype d -ok rm -f {} \; find / -type f -xdev -name ".keep" -print -exec rm {} \; emerge mlocate cat /proc/mounts > /etc/mtab updatedb
grub
emerge grub
vi /boot/grub/menu.lst default 0 timeout 7 splashimage=/boot/grub/splash.xpm.gz title=LiveCD kernel /boot/vmlinuz real_root=/dev/loop0 looptype=squashfs loop=/livecd.squashfs vga=ask initrd udev nodevfs cdroot dodmraid initrd /boot/initrd title=LiveCD NO-FB kernel /boot/vmlinuz real_root=/dev/loop0 looptype=squashfs loop=/livecd.squashfs initrd udev nodevfs cdroot dodmraid initrd /boot/initrd title=Memtest86+ kernel /boot/memtest86plus/memtest.bin
rm /boot/grub/menu.lst cp /boot/grub/grub.conf /boot/grub/menu.lst
最終処理
exit # Now outside the chroot, put the environment back cd ${LIVECD}/source umount sys proc dev usr/portage/distfiles env-update source /etc/profile mkdir -p ${LIVECD}/target/files/source rsync --delete-after --archive --hard-links --quiet ${LIVECD}/source/boot ${LIVECD}/target/ rsync --delete-after --archive --hard-links ${LIVECD}/source/ ${LIVECD}/target/files/source cd ${TARGET_SOURCE} rm -rf var/tmp/* rm -rf var/run/* rm -rf var/lock/* rm -rf var/cache/* mkdir -p var/lock/subsys mkdir -p var/cache/edb/deb mkdir var/cache/hald rm -rf var/db rm -rf tmp/* rm -f etc/mtab touch etc/mtab rm -rf usr/portage rm -rf etc/portage rm -rf usr/share/doc rm root/.bash_history rm root/.zcompdump rm -rf var/log mkdir var/log rm etc/make.profile rm -rf root/.ccache rm -rf root/.mc rm -rf initrd rm before-build
squashfsとisoの生成
cd ${LIVECD}/target/files rm -f ${LIVECD}/target/livecd.squashfs mksquashfs source ${LIVECD}/target/livecd.squashfs touch ${LIVECD}/target/livecd cd ${LIVECD} mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \ -iso-level 4 -hide-rr-moved -c boot.catalog \ -o ${LIVECD}/livecd.iso -x files ${LIVECD}/target
余談
UnixBenchを同じ環境のCentOS6とGentooで比べてみた.
様々な部分で最適化を行っているのでGentooなのが有利なのは目に見えているがその差を理解してくれない方がいるので参考にどうぞ.
Gentoo
======================================================================== BYTE UNIX Benchmarks (Version 5.1.3) System: gentoo-star-light: GNU/Linux OS: GNU/Linux -- 3.7.10-gentoo -- #1 SMP Thu Mar 7 16:43:32 JST 2013 Machine: x86_64 (GenuineIntel) Language: en_US.utf8 (charmap="ANSI_X3.4-1968", collate="ANSI_X3.4-1968") CPU 0: Intel(R) Xeon(TM) CPU 3.60GHz (7200.4 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET CPU 1: Intel(R) Xeon(TM) CPU 3.60GHz (7200.5 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET CPU 2: Intel(R) Xeon(TM) CPU 3.60GHz (7200.4 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET CPU 3: Intel(R) Xeon(TM) CPU 3.60GHz (7200.5 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSENTER/SYSEXIT, SYSCALL/SYSRET 03:42:03 up 8:46, 3 users, load average: 0.16, 0.07, 0.06; runlevel 3
1Coreスコア
Dhrystone 2 using register variables | 11155981.0 lps |
Double-Precision Whetstone | 2419.3 MWIPS |
Execl Throughput | 2391.9 lps |
File Copy 1024 bufsize 2000 maxblocks | 342485.7 KBps |
File Copy 256 bufsize 500 maxblocks | 110770.1 KBps |
File Copy 4096 bufsize 8000 maxblocks | 679330.9 KBps |
Pipe Throughput | 670167.7 lps |
Pipe-based Context Switching | 64684.7 lps |
Process Creation | 5676.1 lps |
Shell Scripts (1 concurrent) | 3790.4 lpm |
Shell Scripts (8 concurrent) | 957.7 lpm |
System Call Overhead | 1052794.7 lps |
4Coreスコア
Dhrystone 2 using register variables | 22177107.3 lps |
Double-Precision Whetstone | 4935.4 MWIPS |
Execl Throughput | 5283.2 lps |
File Copy 1024 bufsize 2000 maxblocks | 163593.1 KBps |
File Copy 256 bufsize 500 maxblocks | 58558.8 KBps |
File Copy 4096 bufsize 8000 maxblocks | 472802.1 KBps |
Pipe Throughput | 1512293.4 lps |
Pipe-based Context Switching | 192500.9 lps |
Process Creation | 14334.5 lps |
Shell Scripts (1 concurrent) | 7276.2 lpm |
Shell Scripts (8 concurrent) | 976.5 lpm |
System Call Overhead | 2883056.5 lps |
CentOS6
======================================================================== BYTE UNIX Benchmarks (Version 5.1.3) System: andromeda: GNU/Linux OS: GNU/Linux -- 2.6.32-279.14.1.el6.x86_64 -- #1 SMP Tue Nov 6 23:43:09 UTC 2012 Machine: x86_64 (x86_64) Language: en_US.utf8 (charmap="UTF-8", collate="UTF-8") CPU 0: Intel(R) Xeon(TM) CPU 3.60GHz (7200.2 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSCALL/SYSRET CPU 1: Intel(R) Xeon(TM) CPU 3.60GHz (7199.0 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSCALL/SYSRET CPU 2: Intel(R) Xeon(TM) CPU 3.60GHz (7200.2 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSCALL/SYSRET CPU 3: Intel(R) Xeon(TM) CPU 3.60GHz (7199.0 bogomips) Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSCALL/SYSRET 03:04:48 up 52 days, 8:39, 1 user, load average: 1.07, 1.02, 1.00; runlevel 3
1Core
Dhrystone 2 using register variables | 10561349.1 lps |
Double-Precision Whetstone | 1883.7 MWIPS |
Execl Throughput | 2385.3 lps |
File Copy 1024 bufsize 2000 maxblocks | 370558.2 KBps |
File Copy 256 bufsize 500 maxblocks | 122804.2 KBps |
File Copy 4096 bufsize 8000 maxblocks | 680746.1 KBps |
Pipe Throughput | 907149.0 lps |
Pipe-based Context Switching | 61452.0 lps |
Process Creation | 5936.9 lps |
Shell Scripts (1 concurrent) | 3217.5 lpm |
Shell Scripts (8 concurrent) | 704.0 lpm |
System Call Overhead | 1034585.9 lps |
4Core
Dhrystone 2 using register variables | 18700298.7 lps |
Double-Precision Whetstone | 5269.4 MWIPS |
Execl Throughput | 4205.6 lps |
File Copy 1024 bufsize 2000 maxblocks | 274687.3 KBps |
File Copy 256 bufsize 500 maxblocks | 81241.3 KBps |
File Copy 4096 bufsize 8000 maxblocks | 659998.0 KBps |
Pipe Throughput | 1809128.8 lps |
Pipe-based Context Switching | 186382.6 lps |
Process Creation | 9241.7 lps |
Shell Scripts (1 concurrent) | 5203.4 lpm |
Shell Scripts (8 concurrent) | 800.2 lpm |
System Call Overhead | 2366560.0 lps |
比較
項目 | スコア(CentOS) | スコア(Gentoo) | 勝敗 |
Dhrystone 2 using register variable | 18700298.7 lps | 22177107.3 lps | gentoo |
Double-Precision Whetstone | 5269.4 MWIPS | 4935.4 MWIPS | centos |
Execl Throughput | 4205.6 lps | 5283.2 lps | gentoo |
File Copy 1024 bufsize 2000 maxblocks | 274687.3 KBps | 163593.1 KBps | centos |
File Copy 256 bufsize 500 maxblocks | 81241.3 KBps | 58558.8 KBps | centos |
File Copy 4096 bufsize 8000 maxblocks | 659998.0 KBps | 472802.1 KBps | centos |
Pipe Throughput | 1809128.8 lps | 1512293.4 lps | centos |
Pipe-based Context Switching | 186382.6 lps | 192500.9 lps | gentoo |
Process Creation | 9241.7 lps | 14334.5 lps | gentoo |
Shell Scripts (1 concurrent) | 5203.4 lpm | 7276.2 lpm | gentoo |
Shell Scripts (8 concurrent) | 800.2 lpm | 976.5 lpm | gentoo |
System Call Overhead | 2366560.0 lps | 2883056.5 lps | gentoo |
これを誤差と考えるかどうかは人次第かと思う. Gentooが適当なKernelの構築なのでDiskの速度に問題がある感じがするので今後改善すべきか?