Skip to content
This repository
branch: master
file 141 lines (104 sloc) 4.56 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
#
# Boot Linux Live CD with ZFS support
# The Funtoo variant of System Rescue CD is highly recommended:
# http://ftp.osuosl.org/pub/funtoo/distfiles/sysresccd/
#

# Create pool
zpool create -f -o ashift=12 -o cachefile=/tmp/zpool.cache -O normalization=formD -m none -R /mnt/gentoo rpool /dev/sda

# Create rootfs
zfs create -o mountpoint=none rpool/ROOT
zfs create -o mountpoint=/ rpool/ROOT/gentoo

# Create home directories
zfs create -o mountpoint=/home rpool/HOME
zfs create -o mountpoint=/root rpool/HOME/root

# Create portage directories
zfs create -o mountpoint=none -o setuid=off rpool/GENTOO
zfs create -o mountpoint=/usr/portage -o atime=off rpool/GENTOO/portage
zfs create -o mountpoint=/usr/portage/distfiles rpool/GENTOO/distfiles

# Create portage build directory
zfs create -o mountpoint=/var/tmp/portage -o compression=lz4 -o sync=disabled rpool/GENTOO/build-dir

# Create optional packages directory
zfs create -o mountpoint=/usr/portage/packages rpool/GENTOO/packages

# Create optional ccache directory
zfs create -o mountpoint=/var/tmp/ccache -o compression=lz4 rpool/GENTOO/ccache

# Set bootfs
zpool set bootfs=rpool/ROOT/gentoo rpool

# Download stage3
wget 'ftp://gentoo.osuosl.org/pub/gentoo/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-[0-9]*.tar.bz2

# Extract stage3
tar -xvjpf stage3-amd64-*.tar.bz2 -C /mnt/gentoo

# Copy zpool.cache into chroot
mkdir -p /mnt/gentoo/etc/zfs
cp /tmp/zpool.cache /mnt/gentoo/etc/zfs/zpool.cache

# Copy resolv.conf into chroot
cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

# Mount filesystems
mount -t proc none /mnt/gentoo/proc
mount --rbind /dev /mnt/gentoo/dev
mount --rbind /sys /mnt/gentoo/sys

# chroot
chroot /mnt/gentoo /bin/bash
env-update; source /etc/profile; export PS1="(chroot) $PS1"; cd

# Get portage snapshot (use OSUOSL mirror because it is usually fast)
env GENTOO_MIRRORS="http://gentoo.osuosl.org" emerge-webrsync

# Install genkernel
emerge sys-kernel/genkernel

# Install sources
emerge sys-kernel/gentoo-sources

# Build initial kernel (required for checks in sys-kernel/spl and sys-fs/zfs)
# FIXME: Make genkernel support modules_prepare
genkernel kernel --no-clean --no-mountboot

# Install ZFS
echo "sys-kernel/spl ~amd64" >> /etc/portage/package.accept_keywords
echo "sys-fs/zfs-kmod ~amd64" >> /etc/portage/package.accept_keywords
echo "sys-fs/zfs ~amd64" >> /etc/portage/package.accept_keywords
emerge sys-fs/zfs

# Add zfs to boot runlevel
rc-update add zfs boot

# Install gptfdisk
emerge sys-apps/gptfdisk

# Make BIOS Boot Partition (make certain /dev/sda is your actual block device!)
sgdisk --new=2:48:2047 --typecode=2:EF02 --change-name=2:"BIOS boot partition" /dev/sda

# Flush the page cache to ensure GRUB2 sees the latest disk content
echo 1 > /proc/sys/vm/drop_caches

# Install GRUB2
echo "sys-boot/grub:2 libzfs" >> /etc/portage/package.use
echo "sys-boot/grub:2 ~amd64" >> /etc/portage/package.accept_keywords
emerge sys-boot/grub:2
touch /etc/mtab
grub2-install /dev/sda

# We must create an empty configuration file so genkernel fines the right one.
touch /boot/grub/grub.cfg

# Build kernel and initramfs
genkernel all --no-clean --no-mountboot --zfs --bootloader=grub2 --callback="emerge @module-rebuild"

# Comment the BOOT, ROOT and SWAP lines in /etc/fstab
sed -i -e "s/\(.*\)\/\(BOOT\|ROOT\|SWAP\)\(.*\)/\#\1\/\2\3/g" /etc/fstab

#
# Follow chapters 8 through 12 of Gentoo Handboook: http://www.gentoo.org/doc/en/handbook/
#

# Make recovery snapshot after booting into new install
zfs snapshot rpool/ROOT/gentoo@install

# Additional tips

# ARC tuning - You can configure the RAM that ARC uses in bytes
echo options zfs zfs_arc_max=536870912 >> /etc/modprobe.d/zfs.conf

# Set portage niceness to minimize potential for updates to cause lag
echo PORTAGE_NICENESS=19 >> /etc/make.conf

# Set portage to compile in a CGROUP to minimize lag
cat << END > /usr/local/sbin/portage-cgroup
#!/bin/sh
# $1 must be the portage PID

cgroup=$(mktemp -d --tmpdir=/sys/fs/cgroup/cpu portage-XXXX) &&
echo $1 > "${cgroup}/tasks" &&
echo 1 > "${cgroup}/notify_on_release"
echo 256 > "${cgroup}/cpu.shares"
END
chmod u+x /usr/local/sbin/portage-cgroup
echo 'PORTAGE_IONICE_COMMAND="/usr/local/sbin/portage-cgroup \${PID}"' >> /etc/make.conf

# Swap support
zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -b 4K -V 8G rpool/swap
mkswap -f /dev/zvol/rpool/swap
zfs snapshot rpool/swap@install
# Edit fstab to use swap here

#
# Note: Integrate `zfs create -o mountpoint=/home/user rpool/HOME/user` into procedure
#
Something went wrong with that request. Please try again.