Skip to content

Commit

Permalink
Merge branch 'release-0.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
szorfein committed Oct 15, 2024
2 parents f9c31f0 + 7171749 commit aa911cc
Show file tree
Hide file tree
Showing 31 changed files with 170 additions and 66 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.11.0, release 2024-10
* Add a new option `--boot-size SIZE`, like requested in
[#6](https://github.com/szorfein/getch/issues/6), actually, it's only used on a
/boot partition, not /efi.
* Add a new option `--root-size SIZE`.
* Add a new option `--swap-size SIZE`.
* Support [Gentoo binary](https://www.gentoo.org/news/2023/12/29/Gentoo-binary.html), use `--binary`, it make the install of Gentoo faster for small system.

## 0.7.3, release 2024-10
Add a Workflow to build gem on Github

Expand Down
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

</div>

A CLI tool to install Gentoo or Void Linux with default:
A CLI tool to install [Gentoo](https://www.gentoo.org/) (by compiling or in [binary](https://www.gentoo.org/news/2023/12/29/Gentoo-binary.html)) or [Void](https://voidlinux.org/) Linux with default:
+ DNS over HTTPS (with [Quad9](https://www.quad9.net/)).
+ Vim | Nano installed.
+ Iptables installed (not configured).
Expand All @@ -35,7 +35,7 @@ Filesystem supported (with or without encryption)
+ ZFS

Boot Manager:
+ **Gentoo**: `BIOS`, `crypted disk` and `musl` will use `Grub2` and `systemd-boot` for `UEFI`.
+ **Gentoo**: Grub2 except on systemd without encryption.
+ **Void**: use only Grub2.

The ISO images i was able to test and that works:
Expand All @@ -47,7 +47,7 @@ The ISO images i was able to test and that works:
You can also use your current `linux` host, just pay attention to the disk that will be used.

## Dependencies
Getch is build without external libs, so it only require `ruby >= 2.5`.
Getch is build without external libs, so it only require `ruby >= 2.6`.

On a live image of Void, you need to install `xbps-install -S ruby xz gptfdisk
openssl`.
Expand All @@ -73,36 +73,41 @@ Just ensure than the script is run with a root account.
After an install by Getch, take a look on the [wiki](https://github.com/szorfein/getch/wiki).

## Examples
For a french user:
For a french user on Gentoo:

# getch --zoneinfo "Europe/Paris" --language fr_FR --keymap fr
# getch --disk sda --zoneinfo "Europe/Paris" --language fr_FR --keymap fr

Install Gentoo on LVM and use a different root disk `/dev/sdc`
Install Gentoo on LVM and use a different root disk `/dev/vdc`

# getch --format ext4 --lvm --disk sdc
# getch --disk vdc --format ext4 --lvm

Encrypt your disk with LVM with a french keymap
Encrypt your disk with LVM with a french keymap and in binary mode:

# getch --format ext4 --lvm --encrypt --keymap fr
# getch --disk sda --format ext4 --lvm --encrypt --keymap fr --binary

Encrypt with ext4 and create a new user `ninja`:

# getch --format ext4 --encrypt --username ninja
# getch --disk vda --format ext4 --encrypt --username ninja

Change size of root in Gb (default 16 on lvm), swap in Mb (default use your
current total ram) with lvm.

# getch --disk sda -o void --lvm --root-size 10 --swap-size 4096

With ZFS, if used with `--encrypt`, it use the native ZFS encryption:

# getch --format zfs
# getch --disk vda --format zfs

With `Void Linux` and `Musl` enable:

# getch --os void --encrypt -k fr --musl
# getch --disk sda --os void --encrypt -k fr --musl

## Troubleshooting

#### Old VG for LVM
If a old volume group exist, `getch` may fail to partition your disk. You have to clean up your device before proceed with `vgremove` and `pvremove`. An short example how doing this with a volume group named `vg0`:

# vgdisplay | grep vg0
# vgdisplay | grep vg
# vgremove -f vg0
# pvremove -f /dev/sdb

Expand Down
2 changes: 1 addition & 1 deletion lib/fstab/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def write_efi
@efi || return

uuid = gen_uuid @efi
line = "UUID=#{uuid} /efi vfat defaults,nosuid,nodev 0 0"
line = "UUID=#{uuid} /efi vfat defaults,nosuid,nodev 0 2"
echo_a @conf, line
end

Expand Down
11 changes: 8 additions & 3 deletions lib/fstab/zfs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

module Fstab
# Generating fstab for zfs filesystem
class Zfs < Root
def initialize(devs, options)
super
Expand All @@ -14,9 +17,11 @@ def generate

def write_swap
uuid = gen_uuid @swap
@encrypt ?
line = "/dev/mapper/swap-luks none swap sw 0 0" :
line = "UUID=#{uuid} swap swap rw,noatime,discard 0 0"
line = if @encrypt
'/dev/mapper/swap-luks none swap sw 0 0'
else
"UUID=#{uuid} swap swap rw,noatime,discard 0 0"
end
echo_a @conf, line
end
end
Expand Down
15 changes: 10 additions & 5 deletions lib/getch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
require_relative 'getch/version'

module Getch

OPTIONS = {
boot_disk: false,
disk: false,
Expand All @@ -34,8 +33,12 @@ module Getch
timezone: 'UTC',
username: false,
verbose: false,
vg_name: 'vg4',
zfs_name: 'pool'
vg_name: 'vg0',
zfs_name: 'pool',
boot_size: 260,
swap_size: Getch::Helpers.get_memory,
root_size: 16,
binary: false
}

STATES = {
Expand All @@ -49,7 +52,7 @@ module Getch
terraform: false,
bootloader: false,
services: false,
finalize: false,
finalize: false
}

MOUNTPOINT = '/mnt/getch'
Expand All @@ -66,8 +69,9 @@ def resume
STATES[:partition] && return

@log.fatal 'No disk, use at least getch with -d DISK' unless OPTIONS[:disk]
os_cap = OPTIONS[:os].capitalize

puts "\nBuild " + OPTIONS[:os].capitalize + " Linux with the following args:\n"
puts "\nBuild #{os_cap} Linux with the following args:\n"
puts
puts "\tLang: #{OPTIONS[:language]}"
puts "\tTimezone: #{OPTIONS[:timezone]}"
Expand All @@ -77,6 +81,7 @@ def resume
puts "\tUsername: #{OPTIONS[:username]}"
puts "\tEncrypt: #{OPTIONS[:encrypt]}"
puts "\tMusl: #{OPTIONS[:musl]}"
puts "\tBinary mode: #{OPTIONS[:binary]}"
puts
puts "\tseparate-boot disk: #{OPTIONS[:boot_disk]}"
puts "\tseparate-cache disk: #{OPTIONS[:cache_disk]}"
Expand Down
17 changes: 12 additions & 5 deletions lib/getch/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'open3'
require 'nito'
require 'English'

module Getch
class Command
Expand All @@ -20,7 +21,7 @@ def to_s
protected

def x
@log.info 'Exec: ' + @cmd
@log.info "Exec: #{@cmd}"
cmd = build_cmd

Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
Expand Down Expand Up @@ -112,7 +113,7 @@ def initialize(*args)
def x
msg
system('chroot', OPTIONS[:mountpoint], '/bin/bash', '-c', other_args)
$?.success? && return
$CHILD_STATUS.success? && return

@log.fatal "Running #{@cmd}"
end
Expand All @@ -137,11 +138,17 @@ def msg
@log.info "Installing #{@cmd}...\n"
end

# Gentoo binary should not use --changed-use
# https://wiki.gentoo.org/wiki/Binary_package_guide
def other_args
case OPTIONS[:os]
when 'gentoo' then "source /etc/profile && emerge --changed-use #{@cmd}"
when 'void' then "/usr/bin/xbps-install -y #{@cmd}"
end
when 'gentoo'
if OPTIONS[:binary]
"source /etc/profile && emerge #{@cmd}"
else
"source /etc/profile && emerge --changed-use #{@cmd}"
end
when 'void' then "/usr/bin/xbps-install -y #{@cmd}" end
end
end
end
2 changes: 1 addition & 1 deletion lib/getch/config/keymap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def search_dir
@log.fatal('OPTIONS[:os] not supported yet.')
end

File.exist? "#{OPTIONS[:mountpoint]}#{@keymaps_dir}" ||
File.exist?("#{OPTIONS[:mountpoint]}#{@keymaps_dir}") ||
@log.fatal("No dir keymaps #{@keymaps_dir} found.")
end
end
Expand Down
14 changes: 13 additions & 1 deletion lib/getch/config/portage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def portage_dir
mkdir "#{@dest}/package.accept_keywords", 0744
mkdir "#{@dest}/package.unmask", 0744
mkdir "#{@dest}/package.license", 0744
mkdir "#{@dest}/binrepos.conf", 0744 if OPTIONS[:binary]

touch "#{@dest}/package.use/zzz_via_autounmask"
touch "#{@dest}/package.accept_keywords/zzz_via_autounmask"
Expand All @@ -46,17 +47,28 @@ def gentoo_repo
# -fomit-frame-pointer reduce code compiled
# but have repercussions on the debugging of applications
def cpu_conf
change = 'COMMON_FLAGS="-march=native -O2 -pipe -fomit-frame-pointer"'
change = if OPTIONS[:binary]
'COMMON_FLAGS="-O2 -pipe -march=x86-64 -mtune=generic"'
else
'COMMON_FLAGS="-march=native -O2 -pipe -fomit-frame-pointer"'
end
sed "#{@dest}/make.conf", /^COMMON_FLAGS/, change
end

# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#MAKEOPTS
# Gentoo binary
# https://wiki.gentoo.org/wiki/Binary_package_guide
# https://wiki.gentoo.org/wiki/Gentoo_Binary_Host_Quickstart
def make_conf
nproc = `nproc`.chomp

echo_a "#{@dest}/make.conf", 'ACCEPT_KEYWORDS="amd64"'
echo_a "#{@dest}/make.conf", 'INPUT_DEVICES="libinput"'
echo_a "#{@dest}/make.conf", "MAKEOPTS=\"-j#{nproc} -l#{nproc}\""
return unless OPTIONS[:binary]

echo_a "#{@dest}/make.conf", 'EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkg --with-bdeps=y --binpkg-respect-use=y"'
echo_a "#{@dest}/make.conf", 'FEATURES="getbinpkg binpkg-request-signature"'
end

# https://www.gentoo.org/downloads/mirrors/
Expand Down
2 changes: 1 addition & 1 deletion lib/getch/config/timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def for_systemd
return unless Helpers.systemd?

src = "/usr/share/zoneinfo/#{OPTIONS[:timezone]}"
dest = "/etc/localtime"
dest = '/etc/localtime'
Getch::Chroot.new('ln', '-sf', src, dest)
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/getch/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def zcache(dev)
private

def load_devs
raise ArgumentError, 'No disk for root, use --disk DISK.' unless OPTIONS[:disk]

if File.exist? @file
DEVS.merge! YAML.load_file @file
else
Expand Down
8 changes: 6 additions & 2 deletions lib/getch/gentoo/bootloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ def install
bootctl
end

# ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel')
ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel-bin') # should also reload grub-mkconfig
# should also reload grub-mkconfig
if OPTIONS[:binary]
ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel-bin')
else
ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel')
end
end

def bootctl
Expand Down
1 change: 1 addition & 0 deletions lib/getch/gentoo/finalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Getch
module Gentoo
# last steps
class Finalize
def initialize
x
Expand Down
3 changes: 2 additions & 1 deletion lib/getch/gentoo/pre_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module Getch
module Gentoo
# configure before installting the system
class PreConfig
include NiTo

Expand All @@ -30,7 +31,7 @@ def github

def check_ip(host)
ip = `ping -c1 #{host}`.match(/\([0-9]*.[0-9]*.[0-9]*.[0-9]*\)/)
ip[0].tr('()','')
ip[0].tr('()', '')
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/getch/gentoo/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Getch
module Gentoo
# install|enable services for the next boot
class Services
def initialize
x
Expand Down
7 changes: 5 additions & 2 deletions lib/getch/gentoo/sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ def use_flags
def make
Install.new('sys-kernel/installkernel')

# Install.new 'sys-kernel/gentoo-kernel'
Install.new 'sys-kernel/gentoo-kernel-bin'
if OPTIONS[:binary]
Install.new 'sys-kernel/gentoo-kernel-bin'
else
Install.new 'sys-kernel/gentoo-kernel'
end
end

def load_modules
Expand Down
Loading

0 comments on commit aa911cc

Please sign in to comment.