-
-
Save ayoubelmhamdi/c93c07d0374f90d4104304c625229964 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Note: Still WIP | |
# | |
# Create a virtual machine, with 8GB + 4cpus. This such that compilation | |
# goes fast and you can pass for jobs (-j4) to make. | |
# | |
# | |
# Use any disk to boot. I used the archlinux boot disk because it works | |
# and it has the genfstab utility which makes it easy to create the mount table. | |
# | |
# For cases where VM is booting into high dpi display. | |
# Not needed if you scale the VM to 200% from the VirtualBox UI | |
# Set large font | |
setfont latarcyrheb-sun32 | |
# | |
# Set root password and start sshd to connect from | |
# terminal in host | |
# | |
passwd | |
systemctl start sshd | |
# | |
# Get VM ip address | |
# | |
ip a | |
# | |
# Now, from host connect via ssh to root@address returned above. | |
# Has the advantage that you can copy/paste commands into console. | |
# | |
# Sync clock | |
timedatectl set-ntp true | |
# | |
# Create 4 partitions: | |
# Create GRUB boot, boot, swap and root primary partitions | |
# For partitioning, follow instructions at | |
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks | |
# | |
parted -a optimal /dev/sda | |
# | |
# Formatting | |
# Boot partition as ext2 because we are doing BIOS boot | |
# so no UEFI / vfat needed. | |
# | |
mkfs.ext2 /dev/sda2 | |
# | |
# Format and mount the swap area | |
# | |
mkswap /dev/sda3 | |
swapon /dev/sda3 | |
# | |
# Create the btrfs partitions | |
# | |
mkfs.btrfs /dev/sda4 | |
# Create btrfs subvolumes | |
mkdir /mnt/gentoo | |
mount -t btrfs /dev/sda4 /mnt/gentoo | |
btrfs subvolume create /mnt/gentoo/@root | |
btrfs subvolume create /mnt/gentoo/@var | |
btrfs subvolume create /mnt/gentoo/@home | |
btrfs subvolume create /mnt/gentoo/@snapshots | |
# | |
# dismount btrfs | |
# | |
umount /mnt/gentoo | |
# | |
# Mount btrfs as subvolumes | |
# | |
mount -o subvol=@root /dev/sda4 /mnt/gentoo | |
mkdir /mnt/gentoo/{var,home,.snapshots} | |
mount -o subvol=@var /dev/sda4 /mnt/gentoo/var | |
mount -o subvol=@home /dev/sda4 /mnt/gentoo/home | |
mount -o subvol=@snapshots /dev/sda4 /mnt/gentoo/.snapshots | |
# | |
# Mount boot / EFI partition | |
# | |
mkdir -p /mnt/gentoo/boot | |
mount /dev/sda2 /mnt/gentoo/boot | |
# | |
# Let's use Arch's genfstab to generate the /etc/fstab | |
# | |
genfstab -L /mnt >> /mnt/gentoo/etc/fstab | |
# | |
# Pull the stage 3 tarball and install it | |
# | |
cd /mnt/gentoo | |
# | |
# Somehow, get the tarball to /mnt/gentoo | |
# | |
links https://www.gentoo.org/downloads/mirrors/ | |
# | |
# Unpack the tarball | |
# | |
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner | |
# | |
# Edit /etc/portage/make.conf and include COMMON_FLAGS="-march=native..." and | |
# MAKEOPTS="-j4" | |
# | |
nano /etc/portage/make.conf | |
# | |
# Copy dns info into root partition for chrooted network to function properly | |
# | |
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/ | |
# | |
# Preparing additional mounts for chroot | |
# | |
mount --types proc /proc /mnt/gentoo/proc | |
mount --rbind /sys /mnt/gentoo/sys | |
mount --rbind /dev /mnt/gentoo/dev | |
# | |
# chroot into the mounted area and continue in the | |
# disk. | |
# | |
chroot /mnt/gentoo /bin/bash | |
# | |
# Note that all the bash history from here is recorded in root user | |
# on root partition | |
# | |
source /etc/profile | |
export PS1="(chroot) $PS1" | |
# | |
# Installing a Gentoo ebuild repository snapshot from the web | |
# | |
emerge-webrsync | |
# | |
# Verify default profile | |
# | |
eselect profile list | |
emerge --ask --verbose --update --deep --newuse @world | |
ls /usr/share/zoneinfo/ | |
echo "US/Pacific" > /etc/timezone | |
emerge --config sys-libs/timezone-data | |
# | |
# Get a better editor. | |
# | |
emerge vim | |
# | |
# locale.gen only seemed to have C locale, so I had | |
# to add US utf-8 | |
# | |
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen | |
locale-gen | |
eselect locale list | |
eselect locale set 4 | |
. /etc/profile | |
# | |
# Reload environment | |
# | |
env-update && source /etc/profile && export PS1="(chroot) $PS1" | |
# | |
# Get kernel sources | |
# | |
emerge --ask sys-kernel/gentoo-sources | |
# | |
# This is only needed if I need to get some PCI dev data using lspci | |
# | |
emerge sys-apps/pciutils | |
lspci | |
# | |
# config + build kernel | |
# | |
cd /usr/src/linux | |
# | |
# Create a default /usr/src/linux/.config | |
# | |
make defconfig | |
# | |
# Tweak things. I only needed to add btrfs support | |
# | |
make menuconfig | |
time make -j4 | |
make modules_install | |
make install | |
# | |
# Generate initramfs because we have /var and /home mounted, so | |
# better have them available on boot, just in case. | |
# | |
etc-update | |
emerge --ask sys-kernel/genkernel | |
genkernel --install --kernel-config=/boot/config-5.4.92-gentoo initramfs | |
# | |
# Just look at the modules installed above. | |
# | |
find /lib/modules/5.4.92-gentoo/ -type f -iname '*.o' -or -iname '*.ko' | |
# | |
# Hostname for this machine | |
# | |
cat /etc/conf.d/hostname <<eof | |
# Set to the hostname of this machine | |
hostname="<your-machine-name>" | |
eof | |
# | |
# | |
emerge --ask --noreplace net-misc/netifrc | |
# | |
# obtain the name of the network interface | |
# | |
ip a | |
# | |
# Set the interface to work with dhcp | |
# | |
cat > /etc/conf.d/net <<eof | |
config_<your-nic>="dhcp" | |
eof | |
# | |
# Now we link the interface such that it boots | |
# | |
cd /etc/init.d | |
ln -s net.lo net.<your-nic> | |
rc-update add net.<your-nic> default | |
cat /etc/hosts | |
vim /etc/hosts | |
# | |
# Set preferred keyboard | |
# | |
sed --in-place /etc/conf.d/keymaps -e 's/^keymap.*$/keymap="dvorak"/' | |
# | |
# Start sshd at boot time | |
# | |
rc-update add sshd default | |
# | |
# Add fs maintenance tools | |
# | |
emerge sys-fs/btrfs-progs | |
emerge sys-fs/e2fsprogs | |
# | |
# Add a dhcp client | |
# | |
emerge --ask net-misc/dhcpcd | |
# | |
# Let's get grub 2 | |
# | |
emerge --ask --verbose sys-boot/grub:2 | |
# | |
# Install grub boot loader to /dev/sda | |
# | |
grub-install /dev/sda | |
# | |
# Add dobtrfs parameter to command line. Will be used | |
# when creating the grub configuration next. | |
# | |
echo 'GRUB_CMDLINE_LINUX="dobtrfs"' >> /etc/default/grub | |
# | |
# Create a grub configuration | |
# | |
grub-mkconfig -o /boot/grub/grub.cfg | |
# | |
# Verify dobtrfs parameter made it to the grub.cfg file | |
# | |
grep dobtrfs /boot/grub/grub.cfg | |
# | |
# Install sudo | |
# | |
emerge sudo | |
# | |
# Set root passwd | |
# | |
passwd | |
# | |
# Add a user. Replace 'user1' by your non-root login user. | |
useradd -m -g users -G wheel -s /bin/bash user1 | |
passwd user1 | |
echo 'user1 ALL=(ALL) ALL' > /etc/sudoers.d/user1 | |
# | |
# Verify all packages installed | |
# | |
cat /var/lib/portage/world | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment