diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d9ea8..3fa248b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 13e92a2..6be88c2 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ -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). @@ -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: @@ -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`. @@ -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 diff --git a/lib/fstab/root.rb b/lib/fstab/root.rb index 299cae9..4a79ea2 100644 --- a/lib/fstab/root.rb +++ b/lib/fstab/root.rb @@ -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 diff --git a/lib/fstab/zfs.rb b/lib/fstab/zfs.rb index 1631be1..326c203 100644 --- a/lib/fstab/zfs.rb +++ b/lib/fstab/zfs.rb @@ -1,4 +1,7 @@ +# frozen_string_literal: true + module Fstab + # Generating fstab for zfs filesystem class Zfs < Root def initialize(devs, options) super @@ -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 diff --git a/lib/getch.rb b/lib/getch.rb index b96a496..043fd13 100644 --- a/lib/getch.rb +++ b/lib/getch.rb @@ -16,7 +16,6 @@ require_relative 'getch/version' module Getch - OPTIONS = { boot_disk: false, disk: false, @@ -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 = { @@ -49,7 +52,7 @@ module Getch terraform: false, bootloader: false, services: false, - finalize: false, + finalize: false } MOUNTPOINT = '/mnt/getch' @@ -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]}" @@ -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]}" diff --git a/lib/getch/command.rb b/lib/getch/command.rb index e9985db..7b33391 100644 --- a/lib/getch/command.rb +++ b/lib/getch/command.rb @@ -2,6 +2,7 @@ require 'open3' require 'nito' +require 'English' module Getch class Command @@ -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| @@ -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 @@ -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 diff --git a/lib/getch/config/keymap.rb b/lib/getch/config/keymap.rb index 5ad9c8c..d85780f 100644 --- a/lib/getch/config/keymap.rb +++ b/lib/getch/config/keymap.rb @@ -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 diff --git a/lib/getch/config/portage.rb b/lib/getch/config/portage.rb index ed82274..ece7f4e 100644 --- a/lib/getch/config/portage.rb +++ b/lib/getch/config/portage.rb @@ -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" @@ -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/ diff --git a/lib/getch/config/timezone.rb b/lib/getch/config/timezone.rb index 0fcf87e..468b210 100644 --- a/lib/getch/config/timezone.rb +++ b/lib/getch/config/timezone.rb @@ -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 diff --git a/lib/getch/device.rb b/lib/getch/device.rb index 9b4c1ae..2756734 100644 --- a/lib/getch/device.rb +++ b/lib/getch/device.rb @@ -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 diff --git a/lib/getch/gentoo/bootloader.rb b/lib/getch/gentoo/bootloader.rb index 49c1875..3016eee 100644 --- a/lib/getch/gentoo/bootloader.rb +++ b/lib/getch/gentoo/bootloader.rb @@ -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 diff --git a/lib/getch/gentoo/finalize.rb b/lib/getch/gentoo/finalize.rb index 61d63ec..f811aab 100644 --- a/lib/getch/gentoo/finalize.rb +++ b/lib/getch/gentoo/finalize.rb @@ -2,6 +2,7 @@ module Getch module Gentoo + # last steps class Finalize def initialize x diff --git a/lib/getch/gentoo/pre_config.rb b/lib/getch/gentoo/pre_config.rb index a546602..0600185 100644 --- a/lib/getch/gentoo/pre_config.rb +++ b/lib/getch/gentoo/pre_config.rb @@ -4,6 +4,7 @@ module Getch module Gentoo + # configure before installting the system class PreConfig include NiTo @@ -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 diff --git a/lib/getch/gentoo/services.rb b/lib/getch/gentoo/services.rb index 87120fe..dbb63af 100644 --- a/lib/getch/gentoo/services.rb +++ b/lib/getch/gentoo/services.rb @@ -2,6 +2,7 @@ module Getch module Gentoo + # install|enable services for the next boot class Services def initialize x diff --git a/lib/getch/gentoo/sources.rb b/lib/getch/gentoo/sources.rb index c37bbc4..52dce93 100644 --- a/lib/getch/gentoo/sources.rb +++ b/lib/getch/gentoo/sources.rb @@ -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 diff --git a/lib/getch/gentoo/tarball.rb b/lib/getch/gentoo/tarball.rb index 0f35a6b..a5dab6d 100644 --- a/lib/getch/gentoo/tarball.rb +++ b/lib/getch/gentoo/tarball.rb @@ -5,14 +5,17 @@ module Getch module Gentoo + # Download the last archive rootfs class Tarball def initialize @log = Log.new @mirror = 'https://mirror.rackspace.com/gentoo' @release = release - @stage_file = OPTIONS[:musl] ? - "stage3-amd64-musl-#{@release}.tar.xz" : - "stage3-amd64-systemd-#{@release}.tar.xz" + @stage_file = if OPTIONS[:musl] + "stage3-amd64-musl-#{@release}.tar.xz" + else + "stage3-amd64-systemd-#{@release}.tar.xz" + end end def x @@ -25,9 +28,11 @@ def x protected def stage3 - OPTIONS[:musl] ? - @mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-musl.txt' : - @mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt' + if OPTIONS[:musl] + "#{@mirror}/releases/amd64/autobuilds/latest-stage3-amd64-musl.txt" + else + "#{@mirror}/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt" + end end # release check line like bellow and return 20231126T163200Z: @@ -51,11 +56,11 @@ def get_stage3 return if File.exist? @stage_file @log.info "wget #{@stage_file}, please wait...\n" - Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file, @stage_file) + Helpers.get_file_online("#{@mirror}/releases/amd64/autobuilds/#{file}", @stage_file) end def control_files - @log.info "Download other files..." + @log.info 'Download other files...' ['DIGESTS', 'asc', 'CONTENTS.gz'].each do |f| Helpers.get_file_online("#{@mirror}/releases/amd64/autobuilds/#{file}.#{f}", "#{@stage_file}.#{f}") end @@ -66,7 +71,7 @@ def checksum @log.info 'Checking SHA512 checksum...' command = "awk '/SHA512 HASH/{getline;print}' #{@stage_file}.DIGESTS | sha512sum --check" _, stderr, status = Open3.capture3(command) - if status.success? then + if status.success? @log.result_ok else cleaning diff --git a/lib/getch/gentoo/terraform.rb b/lib/getch/gentoo/terraform.rb index 68e1b70..08ebfa7 100644 --- a/lib/getch/gentoo/terraform.rb +++ b/lib/getch/gentoo/terraform.rb @@ -1,5 +1,6 @@ module Getch module Gentoo + # install required/usefull packages class Terraform def initialize x diff --git a/lib/getch/gentoo/update.rb b/lib/getch/gentoo/update.rb index e7e612b..7520996 100644 --- a/lib/getch/gentoo/update.rb +++ b/lib/getch/gentoo/update.rb @@ -4,11 +4,13 @@ module Getch module Gentoo + # update system gentoo class Update include NiTo def initialize @log = Log.new + @dest = "#{OPTIONS[:mountpoint]}/etc/portage" x end @@ -18,12 +20,22 @@ def x sync add_musl_repo if OPTIONS[:musl] update + gpg end private + # https://wiki.gentoo.org/wiki/Gentoo_Binary_Host_Quickstart#Package_signature_verification + # Fix permissions error on gnupg directory + def gpg + return unless OPTIONS[:binary] + + mv "#{@dest}/gnupg", "#{@dest}/gnupg.bak" + ChrootOutput.new('getuto') + end + def sync - gentoo_conf = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/gentoo.conf" + gentoo_conf = "#{@dest}/repos.conf/gentoo.conf" @log.info "Synchronize index, please waiting...\n" ChrootOutput.new('emaint sync --auto') sed gentoo_conf, /^sync-type/, 'sync-type = rsync' @@ -31,8 +43,7 @@ def sync def add_musl_repo Install.new('dev-vcs/git') - - file = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/musl.conf" + file = "#{@dest}/repos.conf/musl.conf" content = <<~CONF [musl] location = /var/db/repos/musl diff --git a/lib/getch/gentoo/use.rb b/lib/getch/gentoo/use.rb index 3469e79..b56a951 100644 --- a/lib/getch/gentoo/use.rb +++ b/lib/getch/gentoo/use.rb @@ -4,6 +4,7 @@ module Getch module Gentoo + # Utility to configure use flag on Gentoo class Use include NiTo diff --git a/lib/getch/helpers.rb b/lib/getch/helpers.rb index 0b17ab3..ee81927 100644 --- a/lib/getch/helpers.rb +++ b/lib/getch/helpers.rb @@ -109,9 +109,9 @@ def self.get_memory t = l.split(' ') if l =~ /memtotal/i t && mem = t[1] end - mem || Log.new.fatal('get_memory - failed to get memory') + mem_to_mb = mem.to_i / 1024 || Log.new.fatal('get_memory - failed to get memory') - mem += 'K' + mem_to_mb.to_s end # get the sector size of a disk diff --git a/lib/getch/options.rb b/lib/getch/options.rb index 74baea3..4a84968 100644 --- a/lib/getch/options.rb +++ b/lib/getch/options.rb @@ -66,6 +66,21 @@ def parse(argv) OPTIONS[:home_disk] = Getch::Guard.disk(home) end + opts.on('--boot-size SIZE', Numeric, + 'Specifie the boot size in mebibyte (mib), default use 256.') do |size| + OPTIONS[:boot_size] = size + end + + opts.on('--swap-size SIZE', Numeric, + "Specifie the swap size in megabyte (mb), default use your current memory #{Getch::OPTIONS[:swap_size]}.") do |size| + OPTIONS[:swap_size] = size + end + + opts.on('--root-size SIZE', Numeric, + 'Specifie the root size in gigabyte (G), default use 16 (used only on lvm when --separate-home was not specified.') do |size| + OPTIONS[:root_size] = size + end + opts.on('--lvm', 'System will use LVM, do not work with ZFS.') do OPTIONS[:lvm] = true @@ -80,6 +95,10 @@ def parse(argv) OPTIONS[:musl] = true end + opts.on('--binary', 'Prefer to use binary packages instead of compile them (Gentoo).') do + OPTIONS[:binary] = true + end + opts.on('--verbose', 'Write more messages to the standard output.') do OPTIONS[:verbose] = true end diff --git a/lib/getch/version.rb b/lib/getch/version.rb index db80f9c..215a5ee 100644 --- a/lib/getch/version.rb +++ b/lib/getch/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Getch - VERSION = '0.7.3' + VERSION = '0.11.0' end diff --git a/lib/getch/void/bootloader.rb b/lib/getch/void/bootloader.rb index a64daee..690d766 100644 --- a/lib/getch/void/bootloader.rb +++ b/lib/getch/void/bootloader.rb @@ -2,11 +2,10 @@ module Getch module Void + # install grub class Bootloader def dependencies - Helpers.efi? ? - Install.new('grub-x86_64-efi') : - Install.new('grub') + Helpers.efi? ? Install.new('grub-x86_64-efi') : Install.new('grub') end def install diff --git a/lib/getch/void/finalize.rb b/lib/getch/void/finalize.rb index 88f55b6..d1f6ac5 100644 --- a/lib/getch/void/finalize.rb +++ b/lib/getch/void/finalize.rb @@ -2,6 +2,7 @@ module Getch module Void + # last steps class Finalize def initialize x diff --git a/lib/getch/void/post_config.rb b/lib/getch/void/post_config.rb index 6b40ff2..f707b84 100644 --- a/lib/getch/void/post_config.rb +++ b/lib/getch/void/post_config.rb @@ -2,6 +2,7 @@ module Getch module Void + # config after installing the rootfs class PostConfig def initialize x diff --git a/lib/getch/void/pre_config.rb b/lib/getch/void/pre_config.rb index f31b4b8..0a2aefb 100644 --- a/lib/getch/void/pre_config.rb +++ b/lib/getch/void/pre_config.rb @@ -2,6 +2,7 @@ module Getch module Void + # config before installing the system class PreConfig def initialize x diff --git a/lib/getch/void/services.rb b/lib/getch/void/services.rb index da20a34..49084ab 100644 --- a/lib/getch/void/services.rb +++ b/lib/getch/void/services.rb @@ -2,6 +2,7 @@ module Getch module Void + # install/enable services class Services def initialize x diff --git a/lib/getch/void/update.rb b/lib/getch/void/update.rb index 61b0b2b..74a8ef4 100644 --- a/lib/getch/void/update.rb +++ b/lib/getch/void/update.rb @@ -2,6 +2,7 @@ module Getch module Void + # system update class Update def initialize @log = Log.new diff --git a/lib/lvm2.rb b/lib/lvm2.rb index ca03381..45b8baf 100644 --- a/lib/lvm2.rb +++ b/lib/lvm2.rb @@ -3,12 +3,13 @@ require 'getch/command' module Lvm2 + # Configure system with lvm class Root def initialize(devs, options) @cache = options[:cache_disk] ||= nil @root = devs[:root] ||= nil @home = options[:home_disk] ||= nil - @vg = options[:vg_name] ||= 'vg1' + @vg = options[:vg_name] ||= 'vg0' end def x @@ -28,14 +29,14 @@ def load_datas end def pv_create - devs = [ @path_root ] + devs = [@path_root] @cache && devs << @path_cache @home && devs << @path_home devs.each { |d| d && add_pv(d) } end def vg_create - devs = [ @path_root ] + devs = [@path_root] @cache && devs << @path_cache @home && devs << @path_home add_vg devs @@ -56,7 +57,7 @@ def enable_lvs private def add_pv(dev) - File.exist? dev || @log.fatal("add_pv - no #{dev} exist.") + File.exist?(dev) || @log.fatal("add_pv - no #{dev} exist.") Getch::Command.new('pvcreate', '-f', dev) end @@ -66,15 +67,18 @@ def add_vg(*devs) end def add_swap(dev = nil) - mem = Getch::Helpers.get_memory + mem = "#{Getch::OPTIONS[:swap_size]}M" lvcreate('-L', mem, '-n', 'swap', @vg, dev) end # if home is available, we use the whole space. def add_lv_root - @home ? - @root.match?(/[0-9]/) ? add_root : add_root(nil, @path_root) : - @root.match?(/[0-9]/) ? add_root('16G') : add_root('16G', @path_root) + size = "#{Getch::OPTIONS[:root_size]}G" # in gigabyte + if @home + @root.match?(/[0-9]/) ? add_root : add_root(nil, @path_root) + else + @root.match?(/[0-9]/) ? add_root(size) : add_root(size, @path_root) + end end def add_root(size = nil, dev = nil) @@ -97,6 +101,7 @@ def lvchange_y(name) end end + # Configure hybrid system (encrypt + lvm) class Hybrid < Root def initialize(devs, options) super diff --git a/lib/nito.rb b/lib/nito.rb index e0d636c..3a88f55 100644 --- a/lib/nito.rb +++ b/lib/nito.rb @@ -67,6 +67,10 @@ def cp(src, dest) FileUtils.cp src, dest end + def mv(src, dest) + FileUtils.mv src, dest + end + # create a void file def touch(file) File.write(file, '') unless File.exist? file diff --git a/lib/sgdisk.rb b/lib/sgdisk.rb index ba197c8..6977e55 100644 --- a/lib/sgdisk.rb +++ b/lib/sgdisk.rb @@ -42,13 +42,13 @@ def make_efi def make_boot @boot || return - partition @boot, @boot_code, '0:+256MiB' + partition @boot, @boot_code, "0:+#{Getch::OPTIONS[:boot_size]}MiB" end def make_swap @swap || return - mem = Getch::Helpers.get_memory + mem = "#{Getch::OPTIONS[:swap_size]}M" partition @swap, @swap_code, "0:+#{mem}" end @@ -98,7 +98,7 @@ def end_sector(dev) disk = dev[/^[a-z]+/] cmd = Getch::Command.new("sgdisk -E /dev/#{disk}") end_position = cmd.res.to_i - ( end_position - ( end_position + 1 ) % 2048 ) + (end_position - (end_position + 1) % 2048) end end @@ -135,11 +135,11 @@ def load_codes def make_boot @boot || return - partition @boot, @boot_code, '0:+2G' + partition @boot, @boot_code, "0:+#{Getch::OPTIONS[:boot_size]}MiB" end def make_swap - mem = Getch::Helpers.get_memory + mem = "#{Getch::OPTIONS[:swap_size]}M" partition @swap, @swap_code, "0:+#{mem}" add_zlog add_zcache