def make_partitions(disk: str) -> t.Tuple[str]: def call_parted(cmd: str): call_cmd_and_print_cmd('parted -a optimal --script', disk, f'"{cmd}"') def make_bootloader(): call_parted('mklabel gpt') call_parted('mkpart primary 1MiB 3MiB') call_parted('name 1 grub') call_parted('set 1 bios_grub on') def make_boot(): call_parted('mkpart primary 3MiB 259MiB') call_parted('name 2 boot') call_parted('set 2 boot on') def free_space_to_lvm(): call_parted('mkpart primary 259MiB -1') call_parted('name 3 lvm01') call_parted('set 3 lvm on') make_bootloader() make_boot() free_space_to_lvm() part1 = call_cmd_and_print_cmd( "fdisk -l | grep {d} | tail -n +2 | sed -n 1p | awk '{{print $1}}'". format(d=disk)).strip() part2 = call_cmd_and_print_cmd( "fdisk -l | grep {d} | tail -n +2 | sed -n 2p | awk '{{print $1}}'". format(d=disk)).strip() part3 = call_cmd_and_print_cmd( "fdisk -l | grep {d} | tail -n +2 | sed -n 3p | awk '{{print $1}}'". format(d=disk)).strip() return (part1, part2, part3)
def preinstall(disk: str): launch_ntpd() call_cmd_and_print_cmd('echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6') stage3() chroot_to_install() installation.install( call_cmd_and_print_cmd( f"fdisk -l | grep '{disk}' | grep -i 'efi' | awk '{{print $1}}'"))
def make_fs_and_swap(partition: str): call_cmd_and_print_cmd('mkfs.fat -F 32', partition) call_cmd_and_print_cmd(f'mkfs.ext4 /dev/{LVM_GROUP_NAME}/rootfs') #call_cmd_and_print_cmd(f'mkfs.ext4 /dev/{LVM_GROUP_NAME}/home') call_cmd_and_print_cmd(f'mkswap /dev/{LVM_GROUP_NAME}/swap') call_cmd_and_print_cmd(f'swapon /dev/{LVM_GROUP_NAME}/swap')
def install(boot_device: str): source('/etc/profile') call_cmd_and_print_cmd(f'mount {boot_device} /boot') emerge_base() compiling.compile() call_cmd_and_print_cmd('rc-update add dhcpcd default') call_cmd_and_print_cmd('rc-update add lvmetad boot')
def launch_ntpd(): call_cmd_and_print_cmd('ntpd -q -g')
def stage3(): call_cmd_and_print_cmd('bash stage3.sh')
def emerge_base(): call_cmd_and_print_cmd('emerge-webrsync') call_cmd_and_print_cmd('emerge --oneshot sys-apps/portage') call_cmd_and_print_cmd('emerge app-portage/gentoolkit') print(call_cmd_and_print_cmd('eselect profile list')) print('select profile:') profile_choice = sp.check_output( 'read -t 20 CHOICE; [ -z $CHOICE ] && echo 6 || echo $CHOICE', shell=True).strip().decode() call_cmd_and_print_cmd(f'eselect profile set --force {profile_choice}') print(call_cmd_and_print_cmd('eselect profile list')) call_cmd_and_print_cmd('emerge app-portage/cpuid2cpuflags') call_cmd_and_print_cmd( 'echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags')
def start_ssh_server(): call_cmd_and_print_cmd( 'sed -i "s/everyone/none/" /etc/security/passwdqc.conf') call_cmd_and_print_cmd(r'echo -e "1\n1" | passwd root') call_cmd_and_print_cmd('rc-service sshd start')
def remove_lvm_groups(): existing_lvm_groups = call_cmd_and_print_cmd( "vgs | sed -n 2,\$p | awk '{print $1}'") call_cmd_and_print_cmd(f'vgremove -y {existing_lvm_groups}')
def allocate_space_for_lvm(): call_cmd_and_print_cmd('lvcreate -y -L 2048M -n swap', LVM_GROUP_NAME) call_cmd_and_print_cmd('lvcreate -y -l 100%FREE -n rootfs', LVM_GROUP_NAME)
def create_phy_volume(partition: str): call_cmd_and_print_cmd(f'pvcreate -ff {partition}') call_cmd_and_print_cmd('vgcreate', LVM_GROUP_NAME, partition)
def start_lvm_daemon(): call_cmd_and_print_cmd('/etc/init.d/lvm start')
def call_parted(cmd: str): call_cmd_and_print_cmd('parted -a optimal --script', disk, f'"{cmd}"')
def configuring(): call_cmd_and_print_cmd('echo hostname="gentoo" > /etc/conf.d/hostname') call_cmd_and_print_cmd( r'''blkid | grep 'swap' | sed 's@.*UUID="\([^"]*\)".*@UUID=\1 \t none \t swap \t sw \t 0 \t 0@' >> /etc/fstab''' ) call_cmd_and_print_cmd( r'''blkid | grep 'ext4' | grep 'rootfs' | sed 's@.*UUID="\([^"]*\)".*@UUID=\1 \t / \t ext4 \t noatime \t 0 \t 1@' >> /etc/fstab''' ) call_cmd_and_print_cmd( r'''blkid | grep 'ext4' | grep 'home' | sed "s@.*UUID=\"\([^\"]*\)\".*@UUID=\1 \t /home/ \t ext4 \t noatime \t 0 \t 1@" >> /etc/fstab''' ) call_cmd_and_print_cmd( 'pushd /etc/init.d && ln -s net.lo net.eth0 && rc-update add net.eth0 default && popd' ) call_cmd_and_print_cmd(USE_emerge_pkg('app-admin/sysklogd')) call_cmd_and_print_cmd('rc-update add sysklogd default') call_cmd_and_print_cmd(USE_emerge_pkg('sys-process/cronie')) call_cmd_and_print_cmd('rc-update add cronie default') call_cmd_and_print_cmd(USE_emerge_pkg('sys-apps/mlocate')) call_cmd_and_print_cmd(USE_emerge_pkg('sys-fs/e2fsprogs')) call_cmd_and_print_cmd(USE_emerge_pkg('net-misc/dhcpcd')) call_cmd_and_print_cmd(USE_emerge_pkg('net-wireless/iw')) call_cmd_and_print_cmd(USE_emerge_pkg('net-wireless/wpa_supplicant')) call_cmd_and_print_cmd( '''echo 'GRUB_PLATFORMS="emu efi-32 efi-64 pc"' >> /etc/portage/make.conf''' ) call_cmd_and_print_cmd(USE_emerge_pkg('sys-boot/grub:2')) call_cmd_and_print_cmd( '''echo 'GRUB_CMDLINE_LINUX="dolvm"' >> /etc/default/grub''') call_cmd_and_print_cmd( '''grub-install --target=$(lscpu | head -n1 | sed 's/^[^:]*:[[:space:]]*//')-efi --efi-directory=/boot --removable''' ) call_cmd_and_print_cmd('''grub-mkconfig -o /boot/grub/grub.cfg''') call_cmd_and_print_cmd(USE_emerge_pkg('sys-boot/os-prober'))
def mount_devices_for_os_install(): call_cmd_and_print_cmd(f'mount /dev/{LVM_GROUP_NAME}/rootfs /mnt/gentoo')
def compile(): call_cmd_and_print_cmd( '''echo 'ACCEPT_LICENSE="*"' >> /etc/portage/make.conf''') portage_features = 'FEATURES="{}"'.format(' '.join( ['parallel-install', 'parallel-fetch'])) call_cmd_and_print_cmd( '''echo '{}' >> /etc/portage/make.conf'''.format(portage_features)) call_cmd_and_print_cmd( '''echo 'USE="abi_x86_64 lto pgo X openmp zstd"' >> /etc/portage/make.conf''' ) call_cmd_and_print_cmd( r'''echo "EMERGE_DEFAULT_OPTS=\"--jobs=$(( $(nproc) / 2 ))\"" >> /etc/portage/make.conf''' ) call_cmd_and_print_cmd( '''echo 'INPUT_DEVICES="synaptics libinput"' >> /etc/portage/make.conf''' ) call_cmd_and_print_cmd( '''echo '>sys-devel/gcc-10.3.0-r2' >> /etc/portage/package.mask/gcc''') call_cmd_and_print_cmd('perl-cleaner --all') call_cmd_and_print_cmd('USE="apng" emerge media-libs/libpng') call_cmd_and_print_cmd( 'USE="-harfbuzz -abi_x86_32 -abi_x86_x32" emerge -O1 media-libs/freetype' ) do_with_fallback( 'emerge -uDNv --with-bdeps=y --backtrack=100 --autounmask-write @world' ) call_cmd_and_print_cmd('echo -5 | etc-update') call_cmd_and_print_cmd( 'emerge -uDNv --with-bdeps=y --backtrack=100 @world') call_cmd_and_print_cmd( 'USE="-abi_x86_32 -abi_x86_x32" emerge ' + 'media-libs/freetype ' + 'media-libs/harfbuzz ' + 'dev-libs/libffi ' + 'dev-util/gdbus-codegen ' + 'dev-libs/glib ' + '$(equery -q d harfbuzz freetype libffi | sed -e "/^[[:space:]]*$/d" -e "s/.*/=&/g")' ) call_cmd_and_print_cmd('USE="-gpm" emerge -ND sys-libs/ncurses') call_cmd_and_print_cmd( USE_emerge_pkg('app-editors/vim', 'X', 'python', 'vim-pager', 'perl', 'terminal')) call_cmd_and_print_cmd(USE_emerge_pkg('sys-devel/gcc', 'pgo')) call_cmd_and_print_cmd(USE_emerge_pkg('sys-kernel/gentoo-sources')) call_cmd_and_print_cmd(USE_emerge_pkg('sys-kernel/genkernel')) call_cmd_and_print_cmd('ln -s /usr/src/linux* /usr/src/linux') call_cmd_and_print_cmd( 'genkernel --lvm --mountboot --busybox --install all') call_cmd_and_print_cmd(USE_emerge_pkg('sys-kernel/linux-firmware')) configuring() install_env()
def wipefs(disk: str): call_cmd_and_print_cmd('wipefs -af', disk)