Автоматическая установка


wget http://pxeserver/images/gentoo/one.html 
mv one.html install.sh
chmod +x install.sh
./install.sh

Файл: one.html

#!/bin/bash

drive="/dev/sda"
stagefile="stage3-amd64-20140904.tar.bz2"

# Destroy all data
sgdisk --zap-all ${drive}
dd if=/dev/zero of=${drive} bs=256k

vgname="server_vg"

# GPT
sgdisk --clear ${drive}

sgdisk --new=1::+2M --typecode=1:EF02 ${drive}
sgdisk --new=2::+512M --typecode=2:8300 ${drive}
sgdisk --new=3::`sgdisk -E ${drive}` --typecode=3:8e00 ${drive}

pvcreate ${drive}3

vgcreate ${vgname} ${drive}3

lvcreate -C y -L 4G ${vgname} -n swap0
lvcreate -l +100%FREE ${vgname} -n root0

mkfs.ext2 ${drive}2
mkfs.ext4 /dev/${vgname}/root0

mount /dev/${vgname}/root0 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount ${drive}2 /mnt/gentoo/boot

cd /mnt/gentoo

wget http://mirror.yandex.ru/gentoo-distfiles/releases/amd64/current-iso/${stagefile}
wget http://mirror.yandex.ru/gentoo-distfiles/snapshots/portage-latest.tar.bz2

tar xvjpf ${stagefile}

echo "/dev/sda2                         /boot   ext2    noauto,noatime  1       2" > /mnt/gentoo/etc/fstab
echo "/dev/mapper/"${vgname}"-root0     /       ext4    noatime         0       1" >> /mnt/gentoo/etc/fstab
echo "/dev/mapper/"${vgname}"-swap0     none    swap    sw              0       0" >> /mnt/gentoo/etc/fstab

cat >> /mnt/gentoo/etc/portage/make.conf << EOF
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-O2 -march=native -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j4"
GENTOO_MIRRORS="http://mirror.yandex.ru/gentoo-distfiles/"
SYNC="rsync://rsync2.ru.gentoo.org/gentoo-portage"
# USE="udev bindist mmx sse sse2 sse3 bash-completion gtk qt4 kde dvd alsa cdr unicode -ipv6 truetype bzip2 X nls cups dbus policykit pulseaudio icu gstreamer ncurses alsa ssl bluetooth threads ffmpeg python pcre samba server opengl utils opengl vnc usb doc java"
USE="udev -X -gtk -gnome -kde -qt3 -qt4 bindist mmx sse sse2 sse3 unicode -ipv6 bzip2 nls ssl threads python pcre utils subversion git wget cryptsetup"
# ACCEPT_KEYWORDS="~amd64"
LINGUAS="ru"
PYTHON_TARGETS="python2_7 python3_3"
# GRUB
GRUB_PLATFORMS="pc"
EOF

cat >> /mnt/gentoo/etc/locale.gen << EOF
ru_RU.UTF-8 UTF-8
en_US.UTF-8 UTF-8
EOF

cp -L /etc/resolv.conf /mnt/gentoo/etc/

mount -t proc proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev

wget http://pxeserver/images/gentoo/two.html
mv two.html two.sh
chmod +x two.sh

chroot /mnt/gentoo /two.sh

Файл: two.html

#!/bin/bash

set -e
set -x

env-update && source /etc/profile

emerge --sync

# eselect profile set 6

echo "Europe/Moscow" > /etc/timezone

emerge --config sys-libs/timezone-data

locale-gen

emerge -v gentoo-sources genkernel
emerge -v sys-fs/lvm2 sys-fs/mdadm sys-fs/cryptsetup python
emerge -v sys-apps/busybox app-shells/bash app-shells/tcsh

genkernel --dmraid --lvm --luks --splash=emergence all

emerge -v udev syslog-ng
emerge -v Locale-gettext
emerge -v grub sys-boot/os-prober
emerge -v dhcpcd pam vixie-cron
emerge -v pwgen

rc-update add udev boot
rc-update add syslog-ng default
rc-update add vixie-cron default
rc-update add lvm boot
rc-update add sshd default

##
# GRUB2
##
# LVM
echo "GRUB_PRELOAD_MODULES=lvm" >> /etc/default/grub
echo 'GRUB_CMDLINE_LINUX="dolvm"' >> /etc/default/grub
# LUKS
echo "GRUB_CRYPTODISK_ENABLE=y" >> /etc/default/grub
# grub2-mkconfig -o /boot/grub/grub.cfg
grub2-install --target=i386-pc --recheck --modules="configfile linux search_fs_uuid luks lvm ext2 part_gpt" /dev/sda
#for dev in a b ; do
#       grub2-install --modules="configfile linux crypto search_fs_uuid luks lvm" --recheck /dev/sd${dev}
#done
grub2-mkconfig -o /boot/grub/grub.cfg

# Root password
echo "root:root" | chpasswd