From 96c6a3a010fc8f7415553b83b3d4b04f69888b21 Mon Sep 17 00:00:00 2001 From: teldra Date: Fri, 7 May 2021 18:52:50 +0200 Subject: [PATCH] fixes --- files/bash/xbps-aliase.sh | 13 +- files/bin/void-backup | 12 +- files/bin/void-createbackupcontainer | 4 +- files/bin/void-snapshot | 171 +++++++++++++++++---------- files/bin/void-update | 7 +- files/btrbk/btrbk.conf.void | 74 +++++++++--- files/grub-btrfs/void.conf | 2 +- files/nm/30-wg0 | 32 ++--- files/nm/dns-servers.conf | 2 + files/nm/unmanaged-tun.conf | 3 + modules/10-disk/config | 160 ++++++++++++++++++++++++- modules/disk/bios/config | 170 -------------------------- modules/disk/bios/postconfig | 67 ++++------- modules/disk/uefi/config | 170 -------------------------- modules/disk/uefi/postconfig | 60 +++------- 15 files changed, 411 insertions(+), 536 deletions(-) create mode 100644 files/nm/dns-servers.conf create mode 100644 files/nm/unmanaged-tun.conf delete mode 100644 modules/disk/bios/config delete mode 100644 modules/disk/uefi/config diff --git a/files/bash/xbps-aliase.sh b/files/bash/xbps-aliase.sh index 39a84d5..2721740 100644 --- a/files/bash/xbps-aliase.sh +++ b/files/bash/xbps-aliase.sh @@ -5,11 +5,12 @@ alias xs="xbps-query -Rs" alias backup="sudo void-backup" alias snapshot="sudo void-snapshot" -echo "xu = sudo void-update updaten" -echo "xi = sudo xbps-install -S installieren" -echo "xr = sudo xbps-remove -R deinstallieren" -echo "xs = xbps-query -Rs suchen" +echo "xu = sudo void-update updaten" +echo "xi = sudo xbps-install -S installieren" +echo "xr = sudo xbps-remove -R deinstallieren" +echo "xs = xbps-query -Rs suchen" echo "" -echo "backup = sudo void-backup backup machen" -echo "snapshot = sudo void-snapshot snapshot machen" +echo "backup backup machen" +echo "snapshot snapshot machen" +echo "snapshot config snapshots konfigurieren" echo "" diff --git a/files/bin/void-backup b/files/bin/void-backup index 134345c..59313ce 100644 --- a/files/bin/void-backup +++ b/files/bin/void-backup @@ -4,6 +4,10 @@ backupcfg="/etc/backup.cfg" ziel="/var/lib/backup/ziel" cfg="/etc/btrbk/btrbk.conf.void" +for file in btrbk.conf "conf/backup.conf.void"; do + test -f /etc/btrbk/${file} && cfg="/etc/btrbk/${file}" && break +done + fhelp() { echo "Nutze es so:" echo "sudo backup" @@ -131,12 +135,12 @@ if ! mount "/dev/mapper/luks-${UUID}" "${ziel}"; then fi if mountpoint -q /var/lib/backup/quelle/bootfs; then - mkdir -p "/var/lib/backup/ziel/void/bootfs" - backupbootfs="backupbootfs" + mkdir -p /var/lib/backup/quelle/bootfs/system/backup "/var/lib/backup/ziel/void/bootfs" + boot="backupboot" fi -mkdir -p "/var/lib/backup/ziel/void/{rootfs,homefs}" -for t in backuphomefs backuprootfs "${backupbootfs}"; do +mkdir -p /var/lib/backup/quelle/rootfs/system/backup "/var/lib/backup/ziel/void/{rootfs,homefs}" +for t in backup "${boot}"; do if [[ "${t}" ]]; then if ! btrbk --config="${cfg}" --progress --quiet run "${t}"; then btrbk --config="${cfg}" --progress --quiet clean diff --git a/files/bin/void-createbackupcontainer b/files/bin/void-createbackupcontainer index 54d4e77..62da065 100644 --- a/files/bin/void-createbackupcontainer +++ b/files/bin/void-createbackupcontainer @@ -94,9 +94,9 @@ if ! mount "/dev/mapper/luks-${UUID}" "/var/lib/backup/ziel"; then fi if mountpoint -q /boot; then - mkdir -p "/var/lib/backup/ziel/${HOSTNAME}/boot" + mkdir -p "/var/lib/backup/ziel/void/bootfs" fi -mkdir -p "/var/lib/backup/ziel/${HOSTNAME}/{rootfs,home}" +mkdir -p "/var/lib/backup/ziel/void/{rootfs,homefs}" umount "/var/lib/backup/ziel" cryptsetup close "luks-${UUID}" diff --git a/files/bin/void-snapshot b/files/bin/void-snapshot index 73d496e..569322b 100644 --- a/files/bin/void-snapshot +++ b/files/bin/void-snapshot @@ -4,33 +4,32 @@ if [ "${UID}" -ne "0" ]; then exit 1 fi -config() { - echo "Durch Snapshots werden deine Daten regelmässig" +infos() { + echo "Durch automatische Snapshots wird dein System regelmässig" echo "(zur Zeit alle zwei Stunden), ohne mehr Platz" echo "zu verbrauchen, gedoppelt." echo "Dieses hilft zb. gegen unbeabsichtigtes löschen von Dateien." echo "Du kannst aktivieren, das sie regelmässig gemacht werden." - echo "Du kannst aktivieren, das sie vor einem Update gemacht werden." - echo "Es ist sinnvoll dieses zu aktivieren." - echo "Es ist optional, Snapsshots auch für privaten Daten zu aktivieren." + echo "Es ist optional, Snapshots auch für privaten Daten zu aktivieren." echo "Achtung, Daten werden dadurch erst sehr verzögert gelöscht!" +} + +config() { + infos + test -f "/etc/void-snapshot.cfg" || touch "/etc/void-snapshot.cfg" while read -p "Regelmässige Snapshots aktivieren? [Y/n] " answer; do test -z "${answer}" && answer="y" case "${answer}" in y*|Y*|j*|J*) - if ! grep -q "#void.system" /var/spool/cron/root; then - echo '0 */2 * * * /usr/bin/void-snapshot #void.system' >> /var/spool/cron/root - else - echo "Schon aktiviert." - fi + if ! grep -q "AUTO" "/etc/void-snapshot.cfg"; then + echo "AUTO=true" >> "/etc/void-snapshot.cfg" + fi break ;; n*|N*) - if grep -q "#void.system" /var/spool/cron/root; then - sed -i '/#void.system/d' /var/spool/cron/root - else - echo "Schon deaktiviert." - fi + if grep -q "AUTO" "/etc/void-snapshot.cfg"; then + sed -i '/AUTO/d' "/etc/void-snapshot.cfg" + fi break ;; *) echo "Antwort nicht eindeutig." ;; @@ -38,38 +37,40 @@ config() { done answer="" - while read -p "Snapshots vor dem Update? [Y/n] " answer; do + while read -p "Möchtest du das System automatisch Snapshotten? [Y/n] " answer; do test -z "${answer}" && answer="y" case "${answer}" in y*|Y*|j*|J*) - if ! grep -q "SNAP_BEFORE_UPDATE" "/etc/void-snapshot.cfg"; then - echo "SNAP_BEFORE_UPDATE=true" >> "/etc/void-snapshot.cfg" + if ! grep -q "SYSTEMFS" "/etc/void-snapshot.cfg"; then + echo "SYSTEMFS=true" >> "/etc/void-snapshot.cfg" fi break - ;; + ;; n*|N*) - if grep -q "SNAP_BEFORE_UPDATE" "/etc/void-snapshot.cfg"; then - sed -i '/SNAP_BEFORE_UPDATE/d' "/etc/void-snapshot.cfg" + if grep -q "SYSTEMFS" "/etc/void-snapshot.cfg"; then + sed -i '/SYSTEMFS/d' "/etc/void-snapshot.cfg" fi break - ;; - *) echo "Antwort nicht eindeutig." ;; + ;; + *) + echo "Antwort nicht eindeutig." ;; esac done + answer="" - while read -p "Möchtest du auch deine Privaten Daten Snapshotten? [Y/n] " answer; do + while read -p "Möchtest du deine Privaten Daten automatisch Snapshotten? [Y/n] " answer; do test -z "${answer}" && answer="y" case "${answer}" in y*|Y*|j*|J*) - if ! grep -q "SNAP_HOME" "/etc/void-snapshot.cfg"; then - echo "SNAP_HOME=true" >> "/etc/void-snapshot.cfg" + if ! grep -q "HOMEFS" "/etc/void-snapshot.cfg"; then + echo "HOMEFS=true" >> "/etc/void-snapshot.cfg" fi break ;; n*|N*) - if grep -q "SNAP_HOME" "/etc/void-snapshot.cfg"; then - sed -i '/SNAP_HOME/d' "/etc/void-snapshot.cfg" + if grep -q "HOMEFS" "/etc/void-snapshot.cfg"; then + sed -i '/HOMEFS/d' "/etc/void-snapshot.cfg" fi break ;; @@ -80,47 +81,95 @@ config() { cron="" update="" -if [ -t 0 ]; then - cron=1 -elif [ "${1}" = "update" ]; then - update=1 -elif [ "${1}" = "config" ]; then - config - exit +for i in $@; do + case $i in + update) + update=1 + word="update" + SYSTEM=1 + ;; + config) + config + exit + ;; + cron) + cron=1 + word="regular" + ;; + *) + arr+=( "$i" ) + ;; + esac +done + +for i in "${arr[@]}"; do + case $i in + home) + HOMEFS=1 + MANUAL=1 + word="manual" + ;; + system) + SYSTEMFS=1 + MANUAL=1 + word="manual" + ;; + *) + echo unknow word $i + exit + ;; + esac +done + +if [ "$#" -eq "0" ]; then + word="manual" fi cfg="/etc/btrbk/btrbk.conf.void" - -if [ ! -f "/etc/void-snapshot.cfg" ]; then - test -z "${cron}" && exit 0 - config || exit -fi - -. "/etc/void-snapshot.cfg" - -if [ ! "${SNAP_BEFORE_UPDATE}" ] && [ "${update}" ]; then - exit 1 -fi - -if [ -f /etc/btrbk/btrbk.conf ]; then - btrbk --progress --quiet run snapshot -else - if mountpoint -q /var/lib/backup/quelle/bootfs; then - snapshotbootfs="snapshotbootfs" +if [ "${MANUAL}" ]; then + word=manual +elif [ -z "${MANUAL}" ] && [ -z "${update}" ]; then + if [ ! -f "/etc/void-snapshot.cfg" ]; then + if [ "${cron}" ]; then + echo "no config file found" + echo "create one with: snapshot config" + exit 0 + fi + config || exit fi - for s in snapshotrootfs "${snapshotbootfs}"; do - test "${s}" && if ! btrbk --config="${cfg}" --quiet run "${s}"; then - btrbk --config="${cfg}" --quiet clean "${s}" - echo "fail: btrbk --config=${cfg} --quiet run ${s}" + . "/etc/void-snapshot.cfg" +fi + +if [ -z "${AUTO}" ] && [ "${cron}" ]; then + exit 0 +fi + +if [ "${SYSTEMFS}" ]; then + SNAP_BOOT=1 + if mountpoint -q /var/lib/backup/quelle/bootfs; then + mkdir -p "/var/lib/backup/quelle/bootfs/system/snapshots/${word}" + if ! btrbk --config="${cfg}" --quiet run "${word}boot"; then + btrbk --config="${cfg}" --quiet clean "${word}boot" + echo "fail: btrbk --config=${cfg} --quiet run ${word}boot" exit fi - done + fi + mkdir -p "/var/lib/backup/quelle/rootfs/system/snapshots/${word}" + if ! btrbk --config="${cfg}" --quiet run "${word}root"; then + btrbk --config="${cfg}" --quiet clean "${word}root" + echo "fail: btrbk --config=${cfg} --quiet run ${word}root" + exit + fi fi -if [ "${SNAP_HOME}" ]; then - btrbk --config="${cfg}" --quiet run snapshothomefs +if [ "${HOMEFS}" ] && [ -z "${update}" ]; then + mkdir -p "/var/lib/backup/quelle/rootfs/system/snapshots/${word}" + btrbk --config="${cfg}" --quiet run "${word}home" fi -if ! sudo update-grub 2> /dev/null; then - echo update-grub failed + +if [ "${SNAP_BOOT}" ]; then + if ! update-grub 2> /dev/null; then + echo update-grub failed + fi fi diff --git a/files/bin/void-update b/files/bin/void-update index 34d5a3b..e9ee9bf 100644 --- a/files/bin/void-update +++ b/files/bin/void-update @@ -5,6 +5,8 @@ if [ $UID -ne 0 ]; then exit 1 fi +set -Eeuo pipefail + RESTART= echo "Synchronisiere Repositorys" xbps-install -S > /dev/null @@ -14,6 +16,7 @@ if [[ "${#updatedpkgs[@]}" -eq 0 ]]; then echo "Keine Updates" exit else + echo "${updatedpkgs[@]}" echo "Es sind Updates da!" while read -p "Installieren? [Y/n] " answer; do test -z "${answer}" && answer="y" @@ -28,8 +31,8 @@ else done fi -echo "Lege Snapshot an" -void-snapshot +echo "Lege Snapshot an." +void-snapshot update echo "Entferne nicht benutzte Pakete" xbps-remove -oy > /dev/null diff --git a/files/btrbk/btrbk.conf.void b/files/btrbk/btrbk.conf.void index de03286..22424a6 100644 --- a/files/btrbk/btrbk.conf.void +++ b/files/btrbk/btrbk.conf.void @@ -6,41 +6,83 @@ timestamp_format long noauto yes backend btrfs-progs-sudo +# Update snapshots volume /var/lib/backup/quelle/bootfs - group snapshotbootfs - snapshot_dir snapshot + group updateboot updatestats allstats snapshotstats + snapshot_dir system/snapshots/update + snapshot_preserve_min latest + snapshot_preserve no + subvolume bootfs + +volume /var/lib/backup/quelle/rootfs + group updateroot updatestats allstats snapshotstats + snapshot_dir system/snapshots/update + snapshot_preserve_min latest + snapshot_preserve no + subvolume rootfs + + +# Regular snapshots +volume /var/lib/backup/quelle/bootfs + group regularboot cronstats regularstats allstats snapshotstats + snapshot_dir system/snapshots/regular snapshot_preserve_min 4h snapshot_preserve no subvolume bootfs volume /var/lib/backup/quelle/rootfs - group snapshotrootfs - snapshot_dir snapshot + group regularroot cronstats regularstats allstats snapshotstats + snapshot_dir system/snapshots/regular snapshot_preserve_min 4h snapshot_preserve no subvolume rootfs volume /var/lib/backup/quelle/rootfs - group snapshothomefs - snapshot_dir snapshot + group regularhome cronstats regularstats allstats snapshotstats + snapshot_dir system/snapshots/regular snapshot_preserve_min 4h snapshot_preserve no subvolume homefs + +# Manual Snapshots volume /var/lib/backup/quelle/bootfs - group backupbootfs - snapshot_dir backup - snapshot_preserve_min 4h + group manualboot manualstats allstats snapshotstats + snapshot_dir system/snapshots/manual + snapshot_preserve_min latest + snapshot_preserve no + subvolume bootfs + +volume /var/lib/backup/quelle/rootfs + group manualroot manualstats allstats snapshotstats + snapshot_dir system/snapshots/manual + snapshot_preserve_min latest + snapshot_preserve no + subvolume rootfs + +volume /var/lib/backup/quelle/rootfs + group manualhome manualstats allstats snapshotstats + snapshot_dir system/snapshots/manual + snapshot_preserve_min latest + snapshot_preserve no + subvolume homefs + + +# Backup +volume /var/lib/backup/quelle/bootfs + group backupboot backupstats allstats + snapshot_dir system/backup + snapshot_preserve_min latest snapshot_preserve no target_preserve_min latest - target_preserve 20d 10w 2m + target_preserve no subvolume bootfs target send-receive /var/lib/backup/ziel/void/bootfs volume /var/lib/backup/quelle/rootfs - group backuprootfs - snapshot_dir backup - snapshot_preserve_min 4h + group backuproot backupstats allstats + snapshot_dir system/backup + snapshot_preserve_min latest snapshot_preserve no target_preserve_min latest target_preserve no @@ -48,9 +90,9 @@ volume /var/lib/backup/quelle/rootfs target send-receive /var/lib/backup/ziel/void/rootfs volume /var/lib/backup/quelle/rootfs - group backuphomefs - snapshot_dir backup - snapshot_preserve_min 4h + group backuphome backupstats allstats + snapshot_dir system/backup + snapshot_preserve_min latest snapshot_preserve no target_preserve_min latest target_preserve no diff --git a/files/grub-btrfs/void.conf b/files/grub-btrfs/void.conf index 4999956..4952ade 100644 --- a/files/grub-btrfs/void.conf +++ b/files/grub-btrfs/void.conf @@ -10,7 +10,7 @@ GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@" "rootfs" "bootfs" "homefs") # Any path starting with the specified string will be ignored. # e.g : if `prefix path` = @, all snapshots beginning with "@/..." will be ignored. # Default: ("var/lib/docker" "@var/lib/docker" "@/var/lib/docker") -GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker" "backup") +GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker" "system/backup") GRUB_BTRFS_SUBMENUNAME="Void Linux snapshots" GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true" diff --git a/files/nm/30-wg0 b/files/nm/30-wg0 index 19b8fd7..ba3f0e8 100755 --- a/files/nm/30-wg0 +++ b/files/nm/30-wg0 @@ -2,18 +2,22 @@ INTERFACE=$1 ACTION=$2 -if [ -f /etc/wirdeguard/wg0.conf ]; then - if [ ! "$INTERFACE" = "wg0" ]; then - case "$ACTION" in - up) - wg-quick up wg0 - # wg set wg0 peer ZJwTV2l+N+vFwL0KFQb5xpAPqwVcf0YvEMFzTaIoAU8= endpoint home.rotce.de:51820 - ;; - down) - wg-quick down wg0 - ip link delete dev wg0 - ;; - esac - fi +if [ -f /etc/wireguard/wg0.conf ]; then + case "$INTERFACE" in + tun*|wg*) + exit 0 + ;; + *) + case "$ACTION" in + up) + wg-quick up wg0 + #wg set wg0 peer ZJwTV2l+N+vFwL0KFQb5xpAPqwVcf0YvEMFzTaIoAU8= endpoint home.rotce.de:51820 + ;; + down) + wg-quick down wg0 + #ip link delete dev wg0 + ;; + esac + ;; + esac fi - diff --git a/files/nm/dns-servers.conf b/files/nm/dns-servers.conf new file mode 100644 index 0000000..d18800c --- /dev/null +++ b/files/nm/dns-servers.conf @@ -0,0 +1,2 @@ +[global-dns-domain-*] +servers=::1,159.69.114.157 diff --git a/files/nm/unmanaged-tun.conf b/files/nm/unmanaged-tun.conf new file mode 100644 index 0000000..90d244e --- /dev/null +++ b/files/nm/unmanaged-tun.conf @@ -0,0 +1,3 @@ +[keyfile] +unmanaged-devices=interface-name:wg* + diff --git a/modules/10-disk/config b/modules/10-disk/config index ae18527..5cdbe1c 100644 --- a/modules/10-disk/config +++ b/modules/10-disk/config @@ -1,5 +1,159 @@ -if test -d /sys/firmware/efi; then - source "${modules}"/disk/uefi/config +module start "disk" "Partition disk" + + +# find all disks +declare -A disk_tmp=() +declare -A disk=() +index=0 +for i in $(find /dev/disk/by-id/ -type l -printf "%P\n"|grep -v "part" |tac); do + name="$(readlink -f /dev/disk/by-id/"${i}")" + if [[ "${name}" =~ *"^[0-9]+$"* ]]; then + continue + fi + if [[ "${name}" == *"dm"* ]]; then + continue + fi + if [[ "${name}" == *"/dev/sr"* ]]; then + continue + fi + index=$(( index + 1 )) + size="$(fdisk -l "${name}" | head -n1 | awk '{print $3}')" + size=$(awk "BEGIN { printf(\"%.0f\n\", ${size}); }") + size="$(( size - 1 ))" + disk_tmp+=( [${index}.id]="${i}" [${index}.name]="${name}" [${index}.size]="${size}" ) +done +disk_tmp+=( [count]="${index}" ) + +# show devices +echo "Devices:" +for i in $(seq 1 "${disk_tmp[count]}"); do + echo "${disk_tmp[${i}.id]}" "${disk_tmp[${i}.name]}" "${disk_tmp[${i}.size]}" +done + +# if set device on commandline, use this as default +if [[ -z "${extern_device}" ]]; then + device="${disk_tmp[1.id]}" else - source "${modules}"/disk/bios/config + device="${extern_device}" fi + +# choose device +found="" +while input "Which Device?" "${device}"; do + test -z "${output}" && output="${default}" + for i in $(seq 1 "${disk_tmp[count]}"); do + if [[ "${disk_tmp[${i}.id]}" == "${output}" ]] || [[ "${disk_tmp[${i}.name]}" == "${output}" ]]; then + found=1 + disk+=( [id]="${disk_tmp[${i}.id]}" ) + disk+=( [name]="${disk_tmp[${i}.name]}" ) + disk+=( [size]="${disk_tmp[${i}.size]}" ) + break + fi + done + [[ "${found}" == "1" ]] && break + echo "${output} not found" +done + +# if there are partitions, show them and warn +# user choose between exit und wipe +partitions="" +index="" +for i in "$(lsblk -n -l "${disk[name]}" | tail -n +2 | grep part)"; do + echo "${i}" + index=$(( index + 1 )) +done + +if [[ "${#partitions[@]}" -gt 0 ]]; then + echo "there are partitions" + while input "wipe or quit?" "wipe"; do + case "${output}" in + w*|*p*|*W*|*P*) + setconf add wipe "1" + break + ;; + q*|*u*|*t*|*Q*|*U*|*T*) + echo mount / under /mnt + echo mount /boot under /mnt/boot + echo mount /home under /mnt/home + echo create swap + echo start again with -m + exit + ;; + *) echo "please enter wipe or quit" + ;; + esac + done +fi + +echo "######" +echo "With Full Disk Encryption the whole disk will be encrypted," +echo "including /boot. Unlike Ubuntu." +echo "If you choose FDE, you have to enter the password for the" +echo "disc twice, unless you save the key on an usbstick or" +echo "include it into initramfs." +echo "If its included, remember: grub only knows us keylayout: no umlauts" +echo "If you choose to enter once, kernel (/boot) is unencrypted on disk." +echo "You can turn off encryption." +echo "######" + +multiplechoice "fde_key_store" "initramfs" "usb" "once" "twice" "notencrypted" + +if [[ "${cfg[fde_key_store]}" == "notencrypted" ]]; then + setconf add "fde_key_store" "none" +fi + +if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then + addpkg "cryptsetup" + #input_pw "Disk Password" + output="oem" + #setconf "add" "diskpw" "${output}" + cfg+=( [diskpw]="${output}" ) +fi + +if check yesno "Do you want to hibernate?" "y"; then + hibernate=1 + setconf "add" "hibernate" "1" +fi + +ramsize="$(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))" +ramsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}/1024); }")" + +if [[ "${ramsize}" -gt "0" ]] || [[ "${ramsize}" -le "2" ]]; then + test -z "${hibernate}" && swapsize="$(( ramsize * 2 ))" + test -z "${hibernate}" || swapsize="$(( ramsize * 3 ))" +elif [[ "${ramsize}" -gt "2" ]] && [[ "${ramsize}" -le "8" ]]; then + test -z "${hibernate}" && swapsize="${ramsize}" + test -z "${hibernate}" || swapsize="$(( ramsize * 2 ))" +elif [[ "${ramsize}" -gt "8" ]] && [[ "${ramsize}" -le "15" ]]; then + test -z "${hibernate}" && swapsize="${ramsize}" + test -z "${hibernate}" || swapsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}*1.5); }")" +elif [[ "${ramsize}" -gt "15" ]]; then + test -z "${hibernate}" && swapsize="4" + test -z "${hibernate}" || read -p "hibernate not recommended, turning off" empty && hibernate="" && swapsize="4" +fi + +setconf "add" "bootsize" "4" + +echo Configure rootfssize +while input "Size in G? [$(( disk[size] - swapsize - bootsize ))|rest]" "rest"; do + test -z "${output}" && output="${default}" + case "${output}" in + rest) rootfssize="${output}" && break ;; + esac + if [[ "${output}" =~ ^[0-9]+$ ]] && [[ "${output}" -le "$(( disk[size] - cfg[swapsize] - cfg[bootsize] ))" ]]; then + rootfssize="${output}" + break + fi +done + +setconf "add" "fde_key_store" "${cfg[fde_key_store]}" +setconf "add" "fde_keystore" "${cfg[fde_key_store]}" +setconf "add" "FDE_KEY_STORE" "${cfg[fde_key_store]}" +setconf "add" "diskid" "${disk[id]}" +setconf "add" "swapsize" "${swapsize}" +setconf "add" "rootfssize" "${rootfssize}" +setconf "add" "wipe" "${cfg[wipe]}" +setconf "add" "diskname" "${disk[name]}" +setconf "add" "bootsize" "4" +setconf "add" "target_part" "2" +module end diff --git a/modules/disk/bios/config b/modules/disk/bios/config deleted file mode 100644 index 2e442b8..0000000 --- a/modules/disk/bios/config +++ /dev/null @@ -1,170 +0,0 @@ -module start "disk" "Partition disk" - - -# find all disks -declare -A disk_tmp=() -declare -A disk=() -index=0 -for i in $(find /dev/disk/by-id/ -type l -printf "%P\n"|grep -v "part" |tac); do - name="$(readlink -f /dev/disk/by-id/"${i}")" - if [[ "${name}" =~ *"^[0-9]+$"* ]]; then - continue - fi - if [[ "${name}" == *"dm"* ]]; then - continue - fi - if [[ "${name}" == *"/dev/sr"* ]]; then - continue - fi - index=$(( index + 1 )) - size="$(fdisk -l "${name}" | head -n1 | awk '{print $3}')" - size=$(awk "BEGIN { printf(\"%.0f\n\", ${size}); }") - size="$(( size - 1 ))" - disk_tmp+=( [${index}.id]="${i}" [${index}.name]="${name}" [${index}.size]="${size}" ) -done -disk_tmp+=( [count]="${index}" ) - -# show devices -echo "Devices:" -for i in $(seq 1 "${disk_tmp[count]}"); do - echo "${disk_tmp[${i}.id]}" "${disk_tmp[${i}.name]}" "${disk_tmp[${i}.size]}" -done - -# if set device on commandline, use this as default -if [[ -z "${extern_device}" ]]; then - device="${disk_tmp[1.id]}" -else - device="${extern_device}" -fi - -# choose device -found="" -while input "Which Device?" "${device}"; do - test -z "${output}" && output="${default}" - for i in $(seq 1 "${disk_tmp[count]}"); do - if [[ "${disk_tmp[${i}.id]}" == "${output}" ]] || [[ "${disk_tmp[${i}.name]}" == "${output}" ]]; then - found=1 - disk+=( [id]="${disk_tmp[${i}.id]}" ) - disk+=( [name]="${disk_tmp[${i}.name]}" ) - disk+=( [size]="${disk_tmp[${i}.size]}" ) - break - fi - done - [[ "${found}" == "1" ]] && break - echo "${output} not found" -done - -# if there are partitions, show them and warn -# user choose between exit und wipe -partitions="" -index="" -for i in "$(lsblk -n -l "${disk[name]}" | tail -n +2 | grep part)"; do - echo "${i}" - index=$(( index + 1 )) -done - -if [[ "${#partitions[@]}" -gt 0 ]]; then - echo "there are partitions" - while input "wipe or quit?" "wipe"; do - case "${output}" in - w*|*p*|*W*|*P*) - setconf add wipe "1" - break - ;; - q*|*u*|*t*|*Q*|*U*|*T*) - echo mount / under /mnt - echo mount /boot under /mnt/boot - echo mount /home under /mnt/home - echo create swap - echo start again with -m - exit - ;; - *) echo "please enter wipe or quit" - ;; - esac - done -fi - -echo "######" -echo "With Full Disk Encryption the whole disk will be encrypted," -echo "including /boot. Unlike Ubuntu." -echo "If you choose FDE, you have to enter the password for the" -echo "disc twice, unless you save the key on an usbstick or" -echo "include it into initramfs." -echo "If its included, remember: grub only knows us keylayout: no umlauts" -echo "If you choose to enter once, kernel (/boot) is unencrypted on disk." -echo "You can turn off encryption." -echo "######" - -multiplechoice "fde_key_store" "initramfs" "usb" "once" "twice" "notencrypted" - -if [[ "${cfg[fde_key_store]}" == "notencrypted" ]]; then - setconf add "fde_key_store" "none" -fi - -if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then - addpkg "cryptsetup" - #input_pw "Disk Password" - output="oem" - #setconf "add" "diskpw" "${output}" - cfg+=( [diskpw]="${output}" ) -fi - -if check yesno "Do you want to hibernate?" "y"; then - hibernate=1 - setconf "add" "hibernate" "1" -fi - -ramsize="$(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))" -ramsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}/1024); }")" - -if [[ "${ramsize}" -gt "0" ]] || [[ "${ramsize}" -le "2" ]]; then - test -z "${hibernate}" && swapsize="$(( ramsize * 2 ))" - test -z "${hibernate}" || swapsize="$(( ramsize * 3 ))" -elif [[ "${ramsize}" -gt "2" ]] && [[ "${ramsize}" -le "8" ]]; then - test -z "${hibernate}" && swapsize="${ramsize}" - test -z "${hibernate}" || swapsize="$(( ramsize * 2 ))" -elif [[ "${ramsize}" -gt "8" ]] && [[ "${ramsize}" -le "15" ]]; then - test -z "${hibernate}" && swapsize="${ramsize}" - test -z "${hibernate}" || swapsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}*1.5); }")" -elif [[ "${ramsize}" -gt "15" ]]; then - test -z "${hibernate}" && swapsize="4" - test -z "${hibernate}" || read -p "hibernate not recommended, turning off" empty && hibernate="" && swapsize="4" -fi - -if [[ "${cfg[fde_key_store]}" == "once" ]]; then - echo Configure /boot - while input "Size in G?" "4"; do - if check num "${output}"; then - bootsize="${output}" - setconf "add" "bootsize" "${output}" - setconf "add" "target_part" "2" - break - fi - done -else - setconf "add" "target_part" "1" -fi - -echo Configure rootfssize -while input "Size in G? [$(( disk[size] - swapsize - bootsize ))|rest]" "rest"; do - test -z "${output}" && output="${default}" - case "${output}" in - rest) rootfssize="${output}" && break ;; - esac - if [[ "${output}" =~ ^[0-9]+$ ]] && [[ "${output}" -le "$(( disk[size] - cfg[swapsize] - cfg[bootsize] ))" ]]; then - rootfssize="${output}" - break - fi -done - -setconf "add" "fde_key_store" "${cfg[fde_key_store]}" -setconf "add" "fde_keystore" "${cfg[fde_key_store]}" -setconf "add" "FDE_KEY_STORE" "${cfg[fde_key_store]}" -setconf "add" "diskid" "${disk[id]}" -setconf "add" "swapsize" "${swapsize}" -setconf "add" "rootfssize" "${rootfssize}" -setconf "add" "wipe" "${cfg[wipe]}" -setconf "add" "diskname" "${disk[name]}" - -module end diff --git a/modules/disk/bios/postconfig b/modules/disk/bios/postconfig index e12ae17..785e0ee 100644 --- a/modules/disk/bios/postconfig +++ b/modules/disk/bios/postconfig @@ -2,7 +2,7 @@ if ! yesno "nun gehts los, sicher?" y; then exit fi -module start "disk" "Partition disk" +module start "disk" "Partition disk . BIOS" #umounter "${dest}" || exit @@ -19,21 +19,21 @@ if [[ -n "${cfg[wipe]}" ]]; then q" | fdisk "${cfg[diskname]}" > /dev/null fi sleep 2 -if [[ "${cfg[fde_key_store]}" == "once" ]]; then - echo "create bootpartition" - target_boot="${cfg[diskname]}1" - echo "n - p - 1 - - +${cfg[bootsize]}G - a - w - q" | fdisk "${cfg[diskname]}" > /dev/null - sleep 2 - if [[ "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}2" - echo "create rootfs" +echo "create bootpartition" +target_boot="${cfg[diskname]}1" +echo "n +p +1 + ++${cfg[bootsize]}G +a +w +q" | fdisk "${cfg[diskname]}" > /dev/null +sleep 2 + +if [[ "${cfg[rootfssize]}" == "rest" ]]; then + target_partition_tmp="${cfg[diskname]}2" + echo "create rootfs" echo "n p 2 @@ -41,9 +41,9 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then w q" | fdisk "${cfg[diskname]}" > /dev/null - elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}2" - echo "create rootfs with a specific size" +elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then + target_partition_tmp="${cfg[diskname]}2" + echo "create rootfs with a specific size" echo "n p 2 @@ -51,31 +51,6 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then +${rootfssize}G w q" | fdisk "${cfg[diskname]}" > /dev/null - fi -else - if [[ "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}1" - echo "create rootfs without boot" - echo "n - p - 1 - - - a - w - q" | fdisk "${cfg[diskname]}" > /dev/null - elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}1" - echo "create rootfs with a specific size without boot" - echo "n - p - 1 -   - +${rootfssize}G - a - w - q" | fdisk "${cfg[diskname]}" > /dev/null - fi fi sleep 2 @@ -103,7 +78,7 @@ mkswap "/dev/mapper/voidvg.${diskid}-swap" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" btrfs subvol create "${dest}/rootfs" btrfs subvol create "${dest}/homefs" -mkdir -p "${dest}/snapshot" "${dest}/backup" +mkdir -p "${dest}/system/snapshots/{update,regular}" "${dest}/system/backup" umount "${dest}" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=rootfs @@ -114,7 +89,7 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then mkfs.btrfs -q -f "${target_boot}" mount "${target_boot}" "${dest}/boot" btrfs subvol create "${dest}/boot/bootfs" - mkdir -p "${dest}/boot/snapshot" "${dest}/boot/backup" + mkdir -p "${dest}/boot/system/snapshots/{update,regular}" "${dest}/boot/system/backup" umount "${dest}/boot" mount "${target_boot}" "${dest}/boot" -o subvol=bootfs fi diff --git a/modules/disk/uefi/config b/modules/disk/uefi/config deleted file mode 100644 index 91b7787..0000000 --- a/modules/disk/uefi/config +++ /dev/null @@ -1,170 +0,0 @@ -module start "disk" "Partition disk" - - -# find all disks -declare -A disk_tmp=() -declare -A disk=() -index=0 -for i in $(find /dev/disk/by-id/ -type l -printf "%P\n"|grep -v "part" |tac); do - name="$(readlink -f /dev/disk/by-id/"${i}")" - if [[ "${name}" =~ *"^[0-9]+$"* ]]; then - continue - fi - if [[ "${name}" == *"dm"* ]]; then - continue - fi - if [[ "${name}" == *"/dev/sr"* ]]; then - continue - fi - index=$(( index + 1 )) - size="$(fdisk -l "${name}" | head -n1 | awk '{print $3}')" - size=$(awk "BEGIN { printf(\"%.0f\n\", ${size}); }") - size="$(( size - 1 ))" - disk_tmp+=( [${index}.id]="${i}" [${index}.name]="${name}" [${index}.size]="${size}" ) -done -disk_tmp+=( [count]="${index}" ) - -# show devices -echo "Devices:" -for i in $(seq 1 "${disk_tmp[count]}"); do - echo "${disk_tmp[${i}.id]}" "${disk_tmp[${i}.name]}" "${disk_tmp[${i}.size]}" -done - -# if set device on commandline, use this as default -if [[ -z "${extern_device}" ]]; then - device="${disk_tmp[1.id]}" -else - device="${extern_device}" -fi - -# choose device -found="" -while input "Which Device?" "${device}"; do - test -z "${output}" && output="${default}" - for i in $(seq 1 "${disk_tmp[count]}"); do - if [[ "${disk_tmp[${i}.id]}" == "${output}" ]] || [[ "${disk_tmp[${i}.name]}" == "${output}" ]]; then - found=1 - disk+=( [id]="${disk_tmp[${i}.id]}" ) - disk+=( [name]="${disk_tmp[${i}.name]}" ) - disk+=( [size]="${disk_tmp[${i}.size]}" ) - break - fi - done - [[ "${found}" == "1" ]] && break - echo "${output} not found" -done - -# if there are partitions, show them and warn -# user choose between exit und wipe -partitions="" -index="" -for i in "$(lsblk -n -l "${disk[name]}" | tail -n +2 | grep part)"; do - echo "${i}" - index=$(( index + 1 )) -done - -if [[ "${#partitions[@]}" -gt 0 ]]; then - echo "there are partitions" - while input "wipe or quit?" "wipe"; do - case "${output}" in - w*|*p*|*W*|*P*) - setconf add wipe "1" - break - ;; - q*|*u*|*t*|*Q*|*U*|*T*) - echo mount / under /mnt - echo mount /boot under /mnt/boot - echo mount /home under /mnt/home - echo create swap - echo start again with -m - exit - ;; - *) echo "please enter wipe or quit" - ;; - esac - done -fi - -echo "######" -echo "With Full Disk Encryption the whole disk will be encrypted," -echo "including /boot. Unlike Ubuntu." -echo "If you choose FDE, you have to enter the password for the" -echo "disc twice, unless you save the key on an usbstick or" -echo "include it into initramfs." -echo "If its included, remember: grub only knows us keylayout: no umlauts" -echo "If you choose to enter once, kernel (/boot) is unencrypted on disk." -echo "You can turn off encryption." -echo "######" - -multiplechoice "fde_key_store" "initramfs" "usb" "once" "twice" "notencrypted" - -if [[ "${cfg[fde_key_store]}" == "notencrypted" ]]; then - setconf add "fde_key_store" "none" -fi - -if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then - addpkg "cryptsetup" - #input_pw "Disk Password" - output="oem" - #setconf "add" "diskpw" "${output}" - cfg+=( [diskpw]="${output}" ) -fi - -if check yesno "Do you want to hibernate?" "y"; then - hibernate=1 - setconf "add" "hibernate" "1" -fi - -ramsize="$(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))" -ramsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}/1024); }")" - -if [[ "${ramsize}" -gt "0" ]] || [[ "${ramsize}" -le "2" ]]; then - test -z "${hibernate}" && swapsize="$(( ramsize * 2 ))" - test -z "${hibernate}" || swapsize="$(( ramsize * 3 ))" -elif [[ "${ramsize}" -gt "2" ]] && [[ "${ramsize}" -le "8" ]]; then - test -z "${hibernate}" && swapsize="${ramsize}" - test -z "${hibernate}" || swapsize="$(( ramsize * 2 ))" -elif [[ "${ramsize}" -gt "8" ]] && [[ "${ramsize}" -le "15" ]]; then - test -z "${hibernate}" && swapsize="${ramsize}" - test -z "${hibernate}" || swapsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}*1.5); }")" -elif [[ "${ramsize}" -gt "15" ]]; then - test -z "${hibernate}" && swapsize="4" - test -z "${hibernate}" || read -p "hibernate not recommended, turning off" empty && hibernate="" -fi - -if [[ "${cfg[fde_key_store]}" == "once" ]]; then - echo Configure /boot - while input "Size in G?" "4"; do - if check num "${output}"; then - bootsize="${output}" - setconf "add" "bootsize" "${output}" - setconf "add" "target_part" "2" - break - fi - done -else - setconf "add" "target_part" "1" -fi - -echo Configure rootfssize -while input "Size in G? [$(( disk[size] - swapsize - bootsize ))|rest]" "rest"; do - test -z "${output}" && output="${default}" - case "${output}" in - rest) rootfssize="${output}" && break ;; - esac - if [[ "${output}" =~ ^[0-9]+$ ]] && [[ "${output}" -le "$(( disk[size] - cfg[swapsize] - cfg[bootsize] ))" ]]; then - rootfssize="${output}" - break - fi -done - -setconf "add" "fde_key_store" "${cfg[fde_key_store]}" -setconf "add" "fde_keystore" "${cfg[fde_key_store]}" -setconf "add" "FDE_KEY_STORE" "${cfg[fde_key_store]}" -setconf "add" "diskid" "${disk[id]}" -setconf "add" "swapsize" "${swapsize}" -setconf "add" "rootfssize" "${rootfssize}" -setconf "add" "wipe" "${cfg[wipe]}" -setconf "add" "diskname" "${disk[name]}" - -module end diff --git a/modules/disk/uefi/postconfig b/modules/disk/uefi/postconfig index 9a69e86..3c7f113 100644 --- a/modules/disk/uefi/postconfig +++ b/modules/disk/uefi/postconfig @@ -2,7 +2,7 @@ if ! yesno "nun gehts los, sicher?" y; then exit fi -module start "disk" "Partition disk" +module start "disk" "Partition disk . UEFI" diskid="${cfg[diskid]//-/_}" if [[ -n "${cfg[wipe]}" ]]; then @@ -18,28 +18,28 @@ if [[ -n "${cfg[wipe]}" ]]; then q" | fdisk "${cfg[diskname]}" > /dev/null fi sleep 2 -if [[ "${cfg[fde_key_store]}" == "once" ]]; then - echo "create bootpartition" - target_boot="${cfg[diskname]}2" - echo "n - 2 - - +${cfg[bootsize]}G - w - q" | fdisk "${cfg[diskname]}" > /dev/null - sleep 2 - if [[ "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}3" - echo "create rootfs" +echo "create bootpartition" +target_boot="${cfg[diskname]}2" +echo "n +2 + ++${cfg[bootsize]}G +w +q" | fdisk "${cfg[diskname]}" > /dev/null +sleep 2 + +if [[ "${cfg[rootfssize]}" == "rest" ]]; then + target_partition_tmp="${cfg[diskname]}3" + echo "create rootfs" echo "n 3 w q" | fdisk "${cfg[diskname]}" > /dev/null - elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}3" - echo "create rootfs with a specific size" +elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then + target_partition_tmp="${cfg[diskname]}3" + echo "create rootfs with a specific size" echo "n p 3 @@ -47,28 +47,6 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then +${rootfssize}G w q" | fdisk "${cfg[diskname]}" > /dev/null - fi -else - if [[ "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}2" - echo "create rootfs without boot" - echo "n - 2 - - - w - q" | fdisk "${cfg[diskname]}" > /dev/null - elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then - target_partition_tmp="${cfg[diskname]}2" - echo "create rootfs with a specific size without boot" - echo "n - p - 2 -   - +${rootfssize}G - w - q" | fdisk "${cfg[diskname]}" > /dev/null - fi fi sleep 2 @@ -96,7 +74,7 @@ mkswap "/dev/mapper/voidvg.${diskid}-swap" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" btrfs subvol create "${dest}/rootfs" btrfs subvol create "${dest}/homefs" -mkdir -p "${dest}/snapshot" "${dest}/backup" +mkdir -p "${dest}/system/snapshots/{update,regular}" "${dest}/system/backup" umount "${dest}" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=rootfs @@ -107,7 +85,7 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then mkfs.btrfs -q -f "${target_boot}" mount "${target_boot}" "${dest}/boot" btrfs subvol create "${dest}/boot/bootfs" - mkdir -p "${dest}/boot/snapshot" "${dest}/boot/backup" + mkdir -p "${dest}/boot/system/snapshots/{update,regular}" "${dest}/boot/system/backup" umount "${dest}/boot" mount "${target_boot}" "${dest}/boot" -o subvol=bootfs fi