Last active
November 7, 2024 12:06
-
-
Save maxux/3a30133f18c72f15254bcdbbf2d97d6d to your computer and use it in GitHub Desktop.
Gentoo Base Install Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
gentoo="/home/gentoo" | |
mirror="https://ftp.belnet.be/pub/rsync.gentoo.org/gentoo/releases/amd64/autobuilds" | |
latest=$(curl -s ${mirror}/latest-stage3-amd64-openrc.txt | grep openrc | awk '{ print $1 }') | |
baselat=$(basename $latest) | |
mkdir -p ${gentoo} | |
cd ${gentoo} | |
wget ${mirror}/${latest} -O ${baselat} | |
tar xpvf ${baselat} --xattrs-include='*.*' --numeric-owner | |
rm -f ${baselat} | |
makeconf="${gentoo}/etc/portage/make.conf" | |
cpucount=$(($(grep -c MHz /proc/cpuinfo) + 1)) | |
cat << EOF >> ${makeconf} | |
USE="bindist syslog -multilib -X -gnome -kde iproute2 btrfs lzma -cups" | |
LINGUAS="en" | |
L10N="en" | |
GENTOO_MIRRORS="http://gentoo.mirrors.ovh.net/gentoo-distfiles/" | |
PORTAGE_NICENESS="19" | |
ACCEPT_LICENSE="linux-fw-redistributable" | |
MAKEOPTS="-j${cpucount}" | |
EOF | |
mkdir -p ${gentoo}/etc/portage/repos.conf | |
cp ${gentoo}/usr/share/portage/config/repos.conf ${gentoo}/etc/portage/repos.conf/gentoo.conf | |
# set resolver for the chroot | |
cp -L /etc/resolv.conf ${gentoo}/etc/ | |
mount --types proc /proc ${gentoo}/proc | |
mount --rbind /sys ${gentoo}/sys | |
mount --rbind /dev ${gentoo}/dev | |
mount --bind /run ${gentoo}/run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
disk="/dev/vda" | |
gentoo="/mnt/gentoo" | |
mirror="https://ftp.belnet.be/pub/rsync.gentoo.org/gentoo/releases/amd64/autobuilds" | |
# create partitions | |
parted ${disk} mklabel msdos | |
parted -a optimal ${disk} mkpart primary 0% 768MB | |
parted -a optimal ${disk} mkpart primary 768MB 40GB | |
parted -a optimal ${disk} mkpart primary 41GB 80GB | |
parted ${disk} set 1 boot on | |
partprobe ${disk} | |
# create and mount filesystem | |
mkfs.ext2 ${disk}1 | |
mkfs.ext4 ${disk}2 | |
mkfs.ext4 ${disk}3 | |
mount ${disk}2 ${gentoo} | |
mkdir ${gentoo}/boot | |
mkdir ${gentoo}/home | |
mount ${disk}1 ${gentoo}/boot | |
mount ${disk}3 ${gentoo}/home | |
# synchronize time | |
chronyd -q | |
# fetch latest stage3 version | |
latest=$(curl -s ${mirror}/latest-stage3-amd64-openrc.txt | grep openrc | awk '{ print $1 }') | |
baselat=$(basename $latest) | |
cd ${gentoo} | |
# download and extract stage3 on the root filesystem | |
wget ${mirror}/${latest} -O ${baselat} | |
tar xpvf ${baselat} --xattrs-include='*.*' --numeric-owner | |
rm -f ${baselat} | |
makeconf="${gentoo}/etc/portage/make.conf" | |
cpucount=$(($(grep -c MHz /proc/cpuinfo) + 1)) | |
# customize make.conf with minimal features | |
cat << EOF >> ${makeconf} | |
USE="bindist syslog -multilib -X -gnome -kde iproute2 btrfs lzma -cups" | |
LINGUAS="en" | |
L10N="en" | |
GENTOO_MIRRORS="http://gentoo.mirrors.ovh.net/gentoo-distfiles/" | |
PORTAGE_NICENESS="19" | |
ACCEPT_LICENSE="linux-fw-redistributable" | |
ACCEPT_KEYWORDS="~amd64" | |
MAKEOPTS="-j${cpucount}" | |
EOF | |
# configure original gentoo repository | |
mkdir -p ${gentoo}/etc/portage/repos.conf | |
cp ${gentoo}/usr/share/portage/config/repos.conf ${gentoo}/etc/portage/repos.conf/gentoo.conf | |
# set resolver for the chroot | |
cp -L /etc/resolv.conf ${gentoo}/etc/ | |
# mount base system from host | |
mount --types proc /proc ${gentoo}/proc | |
mount --rbind /sys ${gentoo}/sys | |
mount --rbind /dev ${gentoo}/dev | |
mount --bind /run ${gentoo}/run | |
# download next script | |
gist="3a30133f18c72f15254bcdbbf2d97d6d" | |
wget -O ${gentoo}/tmp/gentoo-chroot.sh https://gist.githubusercontent.com/maxux/${gist}/raw/gentoo-chroot.sh | |
# chroot ${gentoo} /bin/bash | |
# chroot ${gentoo} /bin/bash /tmp/gentoo-chroot.sh | |
## Execute next script (gentoo-chroot) inside the chroot | |
exit 1 | |
umount ${gentoo}/boot | |
umount ${gentoo}/home | |
umount ${gentoo}/proc | |
umount ${gentoo}/run | |
umount --recursive ${gentoo}/dev | |
umount --recursive ${gentoo}/sys | |
umount ${gentoo} | |
# reboot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source /etc/profile | |
# make visual difference with host prompt | |
export PS1="(chroot) ${PS1}" | |
# fast way to fetch portage tree | |
emerge-webrsync | |
# clean up a bit release news | |
eselect news read > /dev/null | |
# choose no-multilib profile, pure 64 bits environment | |
eselect profile set default/linux/amd64/17.1/no-multilib | |
# set single locale | |
sed -i "s/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen | |
# set timezone | |
echo "Europe/Brussels" > /etc/timezone | |
emerge --config sys-libs/timezone-data | |
# upgrade system to 'unstable' (upgrade packages) | |
emerge -DuNv world | |
# reload environment | |
telinit u | |
hash -r | |
# apply locale change | |
eselect locale set en_US.utf8 | |
env-update | |
source /etc/profile | |
export PS1="(chroot) ${PS1}" | |
# install some tools | |
emerge -v gentoolkit | |
# fetching latest kernel 6.1 release available and downloading it | |
krnl=$(equery list -po sys-kernel/vanilla-sources | awk '{ print $1 }' | grep sources-6.1) | |
version=${krnl:27} | |
emerge -v =${krnl} | |
# configuring kernel | |
cd /usr/src | |
ln -s linux-${version} linux | |
cd linux | |
wget http://home.maxux.net/temp/jan-config.gz | |
zcat jan-config.gz > .config | |
yes "" | make config | |
# reload makeopts set earlier | |
eval $(grep MAKEOP /etc/portage/make.conf) | |
make $MAKEOPTS | |
make install | |
make modules_install | |
cd /boot | |
ln -s vmlinuz-${version} vmlinuz | |
ln -s initramfs-${version}.img initramfs | |
# install firmwares | |
emerge -v sys-kernel/linux-firmware | |
# initramfs tools | |
emerge -v dracut sys-apps/nvme-cli | |
dracut --kver ${version} | |
# installing bootloader | |
emerge -v syslinux | |
echo >> /etc/fstab | |
grep ' / ' /proc/mounts | sed "s/ /\t/g" >> /etc/fstab | |
grep ' /boot ' /proc/mounts | sed "s/ /\t/g" >> /etc/fstab | |
grep ' /home' /proc/mounts | sed "s/ /\t/g" >> /etc/fstab | |
rootpart=$(grep ' / ' /proc/mounts | awk '{ print $1 }') | |
rootdisk=/dev/$(lsblk -ndo pkname $(grep ' / ' /proc/mounts | awk '{ print $1 }')) | |
# install bootsector | |
dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/mbr.bin of=${rootdisk} | |
# install bootloader | |
mkdir /boot/extlinux | |
extlinux --install /boot/extlinux | |
cd /usr/share/syslinux | |
cp menu.c32 memdisk libcom32.c32 libutil.c32 /boot/extlinux/ | |
cat << EOF > /boot/extlinux/extlinux.conf | |
DEFAULT gentoo | |
LABEL gentoo | |
LINUX /vmlinuz | |
INITRD /initramfs | |
APPEND root=${rootpart} | |
EOF | |
# installing basic management | |
emerge -v chrony cronie netifrc syslog-ng | |
# setting up root password | |
echo "root:root" | chpasswd | |
# Missing: /etc/hosts | |
# Missing: /etc/conf.d/net (for custom network) | |
# Missing: /etc/hostname and /etc/conf.d/hostname | |
# setup ssh | |
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config | |
# enable services on boot time | |
rc-update add sshd default | |
rc-update add dhcpcd default | |
rc-update add chronyd default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
disk="/dev/sda" | |
partid="1" | |
boot="${disk}${partid}" | |
# Partition Type: ef (EFI System) | |
emerge -va dosfstools syslinux efibootmgr | |
mkfs.vfat ${boot} | |
mount ${boot} /boot | |
mkdir /boot/EFI | |
cp -rv /usr/share/syslinux/efi64 /boot/EFI/syslinux | |
efibootmgr --create --disk ${disk} --part ${partid} --loader /EFI/syslinux/syslinux.efi --label "SYSLINUX" --unicode | |
cat << EOF > /boot/EFI/syslinux/syslinux.cfg | |
DEFAULT gentoo | |
LABEL gentoo | |
LINUX /vmlinuz | |
APPEND root=/dev/sda2 | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment