├── README.md ├── LICENSE.txt └── gentoo-quick-installer.sh /README.md: -------------------------------------------------------------------------------- 1 | # gentoo-quick-installer 2 | 3 | ## About 4 | 5 | This is a quick installer script that can be used to bootstrap amd64 Gentoo Linux quickly. 6 | 7 | Script has been tested on VirtualBox. Other platforms could require additional manual tunining. 8 | 9 | Anyway, it is simple, minimalistic, easy to read and easy to tune for your needs 10 | 11 | Read more: http://www.artembutusov.com/gentoo-linux-quick-installer-script/ 12 | 13 | ## Contribution 14 | 15 | For almost any change please consider doing a few tests below. 16 | 17 | Images should be bootable and should allow to login using root password-auth or password-less auth via SSH. 18 | 19 | ```shell 20 | # livecd kernel with root password 21 | USE_LIVECD_KERNEL=1 ROOT_PASSWORD=Gentoo123 ./gentoo-quick-installer.sh 22 | 23 | # Compiled kernel with ssh public key 24 | USE_LIVECD_KERNEL=0 SSH_PUBLIC_KEY=$(cat id_rsa.pub) ./gentoo-quick-installer.sh 25 | ``` 26 | 27 | ## Copyright 28 | 29 | gentoo-vbox-builder is licensed under the MIT. 30 | 31 | A copy of this license is included in the file LICENSE.txt 32 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Artem Butusov 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /gentoo-quick-installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ## 4 | # GENTOO QUICK INSTALLER 5 | # 6 | # Read more: http://www.artembutusov.com/gentoo-linux-quick-installer-script/ 7 | # 8 | # Usage: 9 | # 10 | # export OPTION1=VALUE1 11 | # export OPTION2=VALUE2 12 | # ./gentoo-quick-installer.sh 13 | # 14 | # Options: 15 | # 16 | # USE_LIVECD_KERNEL - 1 to use livecd kernel (saves time) or 0 to build kernel (takes time) 17 | # SSH_PUBLIC_KEY - ssh public key, pass contents of `cat ~/.ssh/id_rsa.pub` for example 18 | # ROOT_PASSWORD - root password, only SSH key-based authentication will work if not set 19 | ## 20 | 21 | set -e 22 | 23 | GENTOO_MIRROR="http://distfiles.gentoo.org" 24 | 25 | GENTOO_ARCH="amd64" 26 | GENTOO_STAGE3="amd64" 27 | 28 | TARGET_DISK=/dev/sda 29 | 30 | TARGET_BOOT_SIZE=100M 31 | TARGET_SWAP_SIZE=1G 32 | 33 | GRUB_PLATFORMS=pc 34 | 35 | USE_LIVECD_KERNEL=${USE_LIVECD_KERNEL:-1} 36 | 37 | SSH_PUBLIC_KEY=${SSH_PUBLIC_KEY:-} 38 | ROOT_PASSWORD=${ROOT_PASSWORD:-} 39 | 40 | echo "### Checking configuration..." 41 | 42 | if [ -z "$SSH_PUBLIC_KEY" ] && [ -z "$ROOT_PASSWORD" ]; then 43 | echo "SSH_PUBLIC_KEY or ROOT_PASSWORD must be set to continue" 44 | exit 1 45 | fi 46 | 47 | echo "### Setting time..." 48 | 49 | ntpd -gq 50 | 51 | echo "### Creating partitions..." 52 | 53 | sfdisk ${TARGET_DISK} << END 54 | size=$TARGET_BOOT_SIZE,bootable 55 | size=$TARGET_SWAP_SIZE 56 | ; 57 | END 58 | 59 | echo "### Formatting partitions..." 60 | 61 | yes | mkfs.ext4 ${TARGET_DISK}1 62 | yes | mkswap ${TARGET_DISK}2 63 | yes | mkfs.ext4 ${TARGET_DISK}3 64 | 65 | echo "### Labeling partitions..." 66 | 67 | e2label ${TARGET_DISK}1 boot 68 | swaplabel ${TARGET_DISK}2 -L swap 69 | e2label ${TARGET_DISK}3 root 70 | 71 | echo "### Mounting partitions..." 72 | 73 | swapon ${TARGET_DISK}2 74 | 75 | mkdir -p /mnt/gentoo 76 | mount ${TARGET_DISK}3 /mnt/gentoo 77 | 78 | mkdir -p /mnt/gentoo/boot 79 | mount ${TARGET_DISK}1 /mnt/gentoo/boot 80 | 81 | echo "### Setting work directory..." 82 | 83 | cd /mnt/gentoo 84 | 85 | echo "### Installing stage3..." 86 | 87 | STAGE3_PATH_URL="$GENTOO_MIRROR/releases/$GENTOO_ARCH/autobuilds/latest-stage3-$GENTOO_STAGE3.txt" 88 | STAGE3_PATH=$(curl -s "$STAGE3_PATH_URL" | grep -v "^#" | cut -d" " -f1) 89 | STAGE3_URL="$GENTOO_MIRROR/releases/$GENTOO_ARCH/autobuilds/$STAGE3_PATH" 90 | 91 | wget "$STAGE3_URL" 92 | 93 | tar xvpf "$(basename "$STAGE3_URL")" --xattrs-include='*.*' --numeric-owner 94 | 95 | rm -fv "$(basename "$STAGE3_URL")" 96 | 97 | if [ "$USE_LIVECD_KERNEL" != 0 ]; then 98 | echo "### Installing LiveCD kernel..." 99 | 100 | LIVECD_KERNEL_VERSION=$(cut -d " " -f 3 < /proc/version) 101 | 102 | cp -v "/mnt/cdrom/boot/gentoo" "/mnt/gentoo/boot/vmlinuz-$LIVECD_KERNEL_VERSION" 103 | cp -v "/mnt/cdrom/boot/gentoo.igz" "/mnt/gentoo/boot/initramfs-$LIVECD_KERNEL_VERSION.img" 104 | cp -vR "/lib/modules/$LIVECD_KERNEL_VERSION" "/mnt/gentoo/lib/modules/" 105 | fi 106 | 107 | echo "### Installing kernel configuration..." 108 | 109 | mkdir -p /mnt/gentoo/etc/kernels 110 | cp -v /etc/kernels/* /mnt/gentoo/etc/kernels 111 | 112 | echo "### Copying network options..." 113 | 114 | cp -v /etc/resolv.conf /mnt/gentoo/etc/ 115 | 116 | echo "### Configuring fstab..." 117 | 118 | cat >> /mnt/gentoo/etc/fstab << END 119 | 120 | # added by gentoo installer 121 | LABEL=boot /boot ext4 noauto,noatime 1 2 122 | LABEL=swap none swap sw 0 0 123 | LABEL=root / ext4 noatime 0 1 124 | END 125 | 126 | echo "### Mounting proc/sys/dev..." 127 | 128 | mount -t proc none /mnt/gentoo/proc 129 | mount -t sysfs none /mnt/gentoo/sys 130 | mount -o bind /dev /mnt/gentoo/dev 131 | mount -o bind /dev/pts /mnt/gentoo/dev/pts 132 | mount -o bind /dev/shm /mnt/gentoo/dev/shm 133 | 134 | echo "### Changing root..." 135 | 136 | chroot /mnt/gentoo /bin/bash -s << END 137 | #!/bin/bash 138 | 139 | set -e 140 | 141 | echo "### Upading configuration..." 142 | 143 | env-update 144 | source /etc/profile 145 | 146 | echo "### Installing portage..." 147 | 148 | mkdir -p /etc/portage/repos.conf 149 | cp -f /usr/share/portage/config/repos.conf /etc/portage/repos.conf/gentoo.conf 150 | emerge-webrsync 151 | 152 | echo "### Installing kernel sources..." 153 | 154 | emerge sys-kernel/gentoo-sources 155 | 156 | if [ "$USE_LIVECD_KERNEL" = 0 ]; then 157 | echo "### Installing kernel..." 158 | 159 | echo "sys-kernel/genkernel -firmware" > /etc/portage/package.use/genkernel 160 | echo "sys-apps/util-linux static-libs" >> /etc/portage/package.use/genkernel 161 | 162 | emerge sys-kernel/genkernel 163 | 164 | genkernel all --kernel-config=$(find /etc/kernels -type f -iname 'kernel-config-*' | head -n 1) 165 | fi 166 | 167 | echo "### Installing bootloader..." 168 | 169 | emerge grub 170 | 171 | cat >> /etc/portage/make.conf << IEND 172 | 173 | # added by gentoo installer 174 | GRUB_PLATFORMS="$GRUB_PLATFORMS" 175 | IEND 176 | 177 | cat >> /etc/default/grub << IEND 178 | 179 | # added by gentoo installer 180 | GRUB_CMDLINE_LINUX="net.ifnames=0" 181 | GRUB_DEFAULT=0 182 | GRUB_TIMEOUT=0 183 | IEND 184 | 185 | grub-install ${TARGET_DISK} 186 | grub-mkconfig -o /boot/grub/grub.cfg 187 | 188 | echo "### Configuring network..." 189 | 190 | ln -s /etc/init.d/net.lo /etc/init.d/net.eth0 191 | rc-update add net.eth0 default 192 | 193 | if [ -z "$ROOT_PASSWORD" ]; then 194 | echo "### Removing root password..." 195 | passwd -d -l root 196 | else 197 | echo "### Configuring root password..." 198 | echo "root:$ROOT_PASSWORD" | chpasswd 199 | fi 200 | 201 | if [ -n "$SSH_PUBLIC_KEY" ]; then 202 | echo "### Configuring SSH..." 203 | 204 | rc-update add sshd default 205 | 206 | mkdir /root/.ssh 207 | touch /root/.ssh/authorized_keys 208 | chmod 750 /root/.ssh 209 | chmod 640 /root/.ssh/authorized_keys 210 | echo "$SSH_PUBLIC_KEY" > /root/.ssh/authorized_keys 211 | fi 212 | END 213 | 214 | echo "### Rebooting..." 215 | 216 | reboot 217 | --------------------------------------------------------------------------------