This commit is contained in:
teldra 2021-05-07 18:52:50 +02:00
parent fc5efd6052
commit 96c6a3a010
15 changed files with 411 additions and 536 deletions

View File

@ -5,11 +5,12 @@ alias xs="xbps-query -Rs"
alias backup="sudo void-backup" alias backup="sudo void-backup"
alias snapshot="sudo void-snapshot" alias snapshot="sudo void-snapshot"
echo "xu = sudo void-update updaten" echo "xu = sudo void-update updaten"
echo "xi = sudo xbps-install -S installieren" echo "xi = sudo xbps-install -S installieren"
echo "xr = sudo xbps-remove -R deinstallieren" echo "xr = sudo xbps-remove -R deinstallieren"
echo "xs = xbps-query -Rs suchen" echo "xs = xbps-query -Rs suchen"
echo "" echo ""
echo "backup = sudo void-backup backup machen" echo "backup backup machen"
echo "snapshot = sudo void-snapshot snapshot machen" echo "snapshot snapshot machen"
echo "snapshot config snapshots konfigurieren"
echo "" echo ""

View File

@ -4,6 +4,10 @@ backupcfg="/etc/backup.cfg"
ziel="/var/lib/backup/ziel" ziel="/var/lib/backup/ziel"
cfg="/etc/btrbk/btrbk.conf.void" 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() { fhelp() {
echo "Nutze es so:" echo "Nutze es so:"
echo "sudo backup" echo "sudo backup"
@ -131,12 +135,12 @@ if ! mount "/dev/mapper/luks-${UUID}" "${ziel}"; then
fi fi
if mountpoint -q /var/lib/backup/quelle/bootfs; then if mountpoint -q /var/lib/backup/quelle/bootfs; then
mkdir -p "/var/lib/backup/ziel/void/bootfs" mkdir -p /var/lib/backup/quelle/bootfs/system/backup "/var/lib/backup/ziel/void/bootfs"
backupbootfs="backupbootfs" boot="backupboot"
fi fi
mkdir -p "/var/lib/backup/ziel/void/{rootfs,homefs}" mkdir -p /var/lib/backup/quelle/rootfs/system/backup "/var/lib/backup/ziel/void/{rootfs,homefs}"
for t in backuphomefs backuprootfs "${backupbootfs}"; do for t in backup "${boot}"; do
if [[ "${t}" ]]; then if [[ "${t}" ]]; then
if ! btrbk --config="${cfg}" --progress --quiet run "${t}"; then if ! btrbk --config="${cfg}" --progress --quiet run "${t}"; then
btrbk --config="${cfg}" --progress --quiet clean btrbk --config="${cfg}" --progress --quiet clean

View File

@ -94,9 +94,9 @@ if ! mount "/dev/mapper/luks-${UUID}" "/var/lib/backup/ziel"; then
fi fi
if mountpoint -q /boot; then if mountpoint -q /boot; then
mkdir -p "/var/lib/backup/ziel/${HOSTNAME}/boot" mkdir -p "/var/lib/backup/ziel/void/bootfs"
fi fi
mkdir -p "/var/lib/backup/ziel/${HOSTNAME}/{rootfs,home}" mkdir -p "/var/lib/backup/ziel/void/{rootfs,homefs}"
umount "/var/lib/backup/ziel" umount "/var/lib/backup/ziel"
cryptsetup close "luks-${UUID}" cryptsetup close "luks-${UUID}"

View File

@ -4,33 +4,32 @@ if [ "${UID}" -ne "0" ]; then
exit 1 exit 1
fi fi
config() { infos() {
echo "Durch Snapshots werden deine Daten regelmässig" echo "Durch automatische Snapshots wird dein System regelmässig"
echo "(zur Zeit alle zwei Stunden), ohne mehr Platz" echo "(zur Zeit alle zwei Stunden), ohne mehr Platz"
echo "zu verbrauchen, gedoppelt." echo "zu verbrauchen, gedoppelt."
echo "Dieses hilft zb. gegen unbeabsichtigtes löschen von Dateien." 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 regelmässig gemacht werden."
echo "Du kannst aktivieren, das sie vor einem Update gemacht werden." echo "Es ist optional, Snapshots auch für privaten Daten zu aktivieren."
echo "Es ist sinnvoll dieses zu aktivieren."
echo "Es ist optional, Snapsshots auch für privaten Daten zu aktivieren."
echo "Achtung, Daten werden dadurch erst sehr verzögert gelöscht!" 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 while read -p "Regelmässige Snapshots aktivieren? [Y/n] " answer; do
test -z "${answer}" && answer="y" test -z "${answer}" && answer="y"
case "${answer}" in case "${answer}" in
y*|Y*|j*|J*) y*|Y*|j*|J*)
if ! grep -q "#void.system" /var/spool/cron/root; then if ! grep -q "AUTO" "/etc/void-snapshot.cfg"; then
echo '0 */2 * * * /usr/bin/void-snapshot #void.system' >> /var/spool/cron/root echo "AUTO=true" >> "/etc/void-snapshot.cfg"
else fi
echo "Schon aktiviert."
fi
break break
;; ;;
n*|N*) n*|N*)
if grep -q "#void.system" /var/spool/cron/root; then if grep -q "AUTO" "/etc/void-snapshot.cfg"; then
sed -i '/#void.system/d' /var/spool/cron/root sed -i '/AUTO/d' "/etc/void-snapshot.cfg"
else fi
echo "Schon deaktiviert."
fi
break break
;; ;;
*) echo "Antwort nicht eindeutig." ;; *) echo "Antwort nicht eindeutig." ;;
@ -38,38 +37,40 @@ config() {
done done
answer="" 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" test -z "${answer}" && answer="y"
case "${answer}" in case "${answer}" in
y*|Y*|j*|J*) y*|Y*|j*|J*)
if ! grep -q "SNAP_BEFORE_UPDATE" "/etc/void-snapshot.cfg"; then if ! grep -q "SYSTEMFS" "/etc/void-snapshot.cfg"; then
echo "SNAP_BEFORE_UPDATE=true" >> "/etc/void-snapshot.cfg" echo "SYSTEMFS=true" >> "/etc/void-snapshot.cfg"
fi fi
break break
;; ;;
n*|N*) n*|N*)
if grep -q "SNAP_BEFORE_UPDATE" "/etc/void-snapshot.cfg"; then if grep -q "SYSTEMFS" "/etc/void-snapshot.cfg"; then
sed -i '/SNAP_BEFORE_UPDATE/d' "/etc/void-snapshot.cfg" sed -i '/SYSTEMFS/d' "/etc/void-snapshot.cfg"
fi fi
break break
;; ;;
*) echo "Antwort nicht eindeutig." ;; *)
echo "Antwort nicht eindeutig." ;;
esac esac
done done
answer="" 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" test -z "${answer}" && answer="y"
case "${answer}" in case "${answer}" in
y*|Y*|j*|J*) y*|Y*|j*|J*)
if ! grep -q "SNAP_HOME" "/etc/void-snapshot.cfg"; then if ! grep -q "HOMEFS" "/etc/void-snapshot.cfg"; then
echo "SNAP_HOME=true" >> "/etc/void-snapshot.cfg" echo "HOMEFS=true" >> "/etc/void-snapshot.cfg"
fi fi
break break
;; ;;
n*|N*) n*|N*)
if grep -q "SNAP_HOME" "/etc/void-snapshot.cfg"; then if grep -q "HOMEFS" "/etc/void-snapshot.cfg"; then
sed -i '/SNAP_HOME/d' "/etc/void-snapshot.cfg" sed -i '/HOMEFS/d' "/etc/void-snapshot.cfg"
fi fi
break break
;; ;;
@ -80,47 +81,95 @@ config() {
cron="" cron=""
update="" update=""
if [ -t 0 ]; then for i in $@; do
cron=1 case $i in
elif [ "${1}" = "update" ]; then update)
update=1 update=1
elif [ "${1}" = "config" ]; then word="update"
config SYSTEM=1
exit ;;
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 fi
cfg="/etc/btrbk/btrbk.conf.void" cfg="/etc/btrbk/btrbk.conf.void"
if [ "${MANUAL}" ]; then
if [ ! -f "/etc/void-snapshot.cfg" ]; then word=manual
test -z "${cron}" && exit 0 elif [ -z "${MANUAL}" ] && [ -z "${update}" ]; then
config || exit if [ ! -f "/etc/void-snapshot.cfg" ]; then
fi if [ "${cron}" ]; then
echo "no config file found"
. "/etc/void-snapshot.cfg" echo "create one with: snapshot config"
exit 0
if [ ! "${SNAP_BEFORE_UPDATE}" ] && [ "${update}" ]; then fi
exit 1 config || exit
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"
fi fi
for s in snapshotrootfs "${snapshotbootfs}"; do . "/etc/void-snapshot.cfg"
test "${s}" && if ! btrbk --config="${cfg}" --quiet run "${s}"; then fi
btrbk --config="${cfg}" --quiet clean "${s}"
echo "fail: btrbk --config=${cfg} --quiet run ${s}" 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 exit
fi 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 fi
if [ "${SNAP_HOME}" ]; then if [ "${HOMEFS}" ] && [ -z "${update}" ]; then
btrbk --config="${cfg}" --quiet run snapshothomefs mkdir -p "/var/lib/backup/quelle/rootfs/system/snapshots/${word}"
btrbk --config="${cfg}" --quiet run "${word}home"
fi 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 fi

View File

@ -5,6 +5,8 @@ if [ $UID -ne 0 ]; then
exit 1 exit 1
fi fi
set -Eeuo pipefail
RESTART= RESTART=
echo "Synchronisiere Repositorys" echo "Synchronisiere Repositorys"
xbps-install -S > /dev/null xbps-install -S > /dev/null
@ -14,6 +16,7 @@ if [[ "${#updatedpkgs[@]}" -eq 0 ]]; then
echo "Keine Updates" echo "Keine Updates"
exit exit
else else
echo "${updatedpkgs[@]}"
echo "Es sind Updates da!" echo "Es sind Updates da!"
while read -p "Installieren? [Y/n] " answer; do while read -p "Installieren? [Y/n] " answer; do
test -z "${answer}" && answer="y" test -z "${answer}" && answer="y"
@ -28,8 +31,8 @@ else
done done
fi fi
echo "Lege Snapshot an" echo "Lege Snapshot an."
void-snapshot void-snapshot update
echo "Entferne nicht benutzte Pakete" echo "Entferne nicht benutzte Pakete"
xbps-remove -oy > /dev/null xbps-remove -oy > /dev/null

View File

@ -6,41 +6,83 @@ timestamp_format long
noauto yes noauto yes
backend btrfs-progs-sudo backend btrfs-progs-sudo
# Update snapshots
volume /var/lib/backup/quelle/bootfs volume /var/lib/backup/quelle/bootfs
group snapshotbootfs group updateboot updatestats allstats snapshotstats
snapshot_dir snapshot 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_min 4h
snapshot_preserve no snapshot_preserve no
subvolume bootfs subvolume bootfs
volume /var/lib/backup/quelle/rootfs volume /var/lib/backup/quelle/rootfs
group snapshotrootfs group regularroot cronstats regularstats allstats snapshotstats
snapshot_dir snapshot snapshot_dir system/snapshots/regular
snapshot_preserve_min 4h snapshot_preserve_min 4h
snapshot_preserve no snapshot_preserve no
subvolume rootfs subvolume rootfs
volume /var/lib/backup/quelle/rootfs volume /var/lib/backup/quelle/rootfs
group snapshothomefs group regularhome cronstats regularstats allstats snapshotstats
snapshot_dir snapshot snapshot_dir system/snapshots/regular
snapshot_preserve_min 4h snapshot_preserve_min 4h
snapshot_preserve no snapshot_preserve no
subvolume homefs subvolume homefs
# Manual Snapshots
volume /var/lib/backup/quelle/bootfs volume /var/lib/backup/quelle/bootfs
group backupbootfs group manualboot manualstats allstats snapshotstats
snapshot_dir backup snapshot_dir system/snapshots/manual
snapshot_preserve_min 4h 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 snapshot_preserve no
target_preserve_min latest target_preserve_min latest
target_preserve 20d 10w 2m target_preserve no
subvolume bootfs subvolume bootfs
target send-receive /var/lib/backup/ziel/void/bootfs target send-receive /var/lib/backup/ziel/void/bootfs
volume /var/lib/backup/quelle/rootfs volume /var/lib/backup/quelle/rootfs
group backuprootfs group backuproot backupstats allstats
snapshot_dir backup snapshot_dir system/backup
snapshot_preserve_min 4h snapshot_preserve_min latest
snapshot_preserve no snapshot_preserve no
target_preserve_min latest target_preserve_min latest
target_preserve no target_preserve no
@ -48,9 +90,9 @@ volume /var/lib/backup/quelle/rootfs
target send-receive /var/lib/backup/ziel/void/rootfs target send-receive /var/lib/backup/ziel/void/rootfs
volume /var/lib/backup/quelle/rootfs volume /var/lib/backup/quelle/rootfs
group backuphomefs group backuphome backupstats allstats
snapshot_dir backup snapshot_dir system/backup
snapshot_preserve_min 4h snapshot_preserve_min latest
snapshot_preserve no snapshot_preserve no
target_preserve_min latest target_preserve_min latest
target_preserve no target_preserve no

View File

@ -10,7 +10,7 @@ GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@" "rootfs" "bootfs" "homefs")
# Any path starting with the specified string will be ignored. # Any path starting with the specified string will be ignored.
# e.g : if `prefix path` = @, all snapshots beginning with "@/..." 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") # 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_SUBMENUNAME="Void Linux snapshots"
GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true" GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"

View File

@ -2,18 +2,22 @@
INTERFACE=$1 INTERFACE=$1
ACTION=$2 ACTION=$2
if [ -f /etc/wirdeguard/wg0.conf ]; then if [ -f /etc/wireguard/wg0.conf ]; then
if [ ! "$INTERFACE" = "wg0" ]; then case "$INTERFACE" in
case "$ACTION" in tun*|wg*)
up) exit 0
wg-quick up wg0 ;;
# wg set wg0 peer ZJwTV2l+N+vFwL0KFQb5xpAPqwVcf0YvEMFzTaIoAU8= endpoint home.rotce.de:51820 *)
;; case "$ACTION" in
down) up)
wg-quick down wg0 wg-quick up wg0
ip link delete dev wg0 #wg set wg0 peer ZJwTV2l+N+vFwL0KFQb5xpAPqwVcf0YvEMFzTaIoAU8= endpoint home.rotce.de:51820
;; ;;
esac down)
fi wg-quick down wg0
#ip link delete dev wg0
;;
esac
;;
esac
fi fi

View File

@ -0,0 +1,2 @@
[global-dns-domain-*]
servers=::1,159.69.114.157

View File

@ -0,0 +1,3 @@
[keyfile]
unmanaged-devices=interface-name:wg*

View File

@ -1,5 +1,159 @@
if test -d /sys/firmware/efi; then module start "disk" "Partition disk"
source "${modules}"/disk/uefi/config
# 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 else
source "${modules}"/disk/bios/config device="${extern_device}"
fi 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

View File

@ -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

View File

@ -2,7 +2,7 @@ if ! yesno "nun gehts los, sicher?" y; then
exit exit
fi fi
module start "disk" "Partition disk" module start "disk" "Partition disk . BIOS"
#umounter "${dest}" || exit #umounter "${dest}" || exit
@ -19,21 +19,21 @@ if [[ -n "${cfg[wipe]}" ]]; then
q" | fdisk "${cfg[diskname]}" > /dev/null q" | fdisk "${cfg[diskname]}" > /dev/null
fi fi
sleep 2 sleep 2
if [[ "${cfg[fde_key_store]}" == "once" ]]; then echo "create bootpartition"
echo "create bootpartition" target_boot="${cfg[diskname]}1"
target_boot="${cfg[diskname]}1" echo "n
echo "n p
p 1
1
+${cfg[bootsize]}G
+${cfg[bootsize]}G a
a w
w q" | fdisk "${cfg[diskname]}" > /dev/null
q" | fdisk "${cfg[diskname]}" > /dev/null sleep 2
sleep 2
if [[ "${cfg[rootfssize]}" == "rest" ]]; then if [[ "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${cfg[diskname]}2" target_partition_tmp="${cfg[diskname]}2"
echo "create rootfs" echo "create rootfs"
echo "n echo "n
p p
2 2
@ -41,9 +41,9 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then
w w
q" | fdisk "${cfg[diskname]}" > /dev/null q" | fdisk "${cfg[diskname]}" > /dev/null
elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${cfg[diskname]}2" target_partition_tmp="${cfg[diskname]}2"
echo "create rootfs with a specific size" echo "create rootfs with a specific size"
echo "n echo "n
p p
2 2
@ -51,31 +51,6 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then
+${rootfssize}G +${rootfssize}G
w w
q" | fdisk "${cfg[diskname]}" > /dev/null 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 fi
sleep 2 sleep 2
@ -103,7 +78,7 @@ mkswap "/dev/mapper/voidvg.${diskid}-swap"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"
btrfs subvol create "${dest}/rootfs" btrfs subvol create "${dest}/rootfs"
btrfs subvol create "${dest}/homefs" btrfs subvol create "${dest}/homefs"
mkdir -p "${dest}/snapshot" "${dest}/backup" mkdir -p "${dest}/system/snapshots/{update,regular}" "${dest}/system/backup"
umount "${dest}" umount "${dest}"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=rootfs 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}" mkfs.btrfs -q -f "${target_boot}"
mount "${target_boot}" "${dest}/boot" mount "${target_boot}" "${dest}/boot"
btrfs subvol create "${dest}/boot/bootfs" 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" umount "${dest}/boot"
mount "${target_boot}" "${dest}/boot" -o subvol=bootfs mount "${target_boot}" "${dest}/boot" -o subvol=bootfs
fi fi

View File

@ -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

View File

@ -2,7 +2,7 @@ if ! yesno "nun gehts los, sicher?" y; then
exit exit
fi fi
module start "disk" "Partition disk" module start "disk" "Partition disk . UEFI"
diskid="${cfg[diskid]//-/_}" diskid="${cfg[diskid]//-/_}"
if [[ -n "${cfg[wipe]}" ]]; then if [[ -n "${cfg[wipe]}" ]]; then
@ -18,28 +18,28 @@ if [[ -n "${cfg[wipe]}" ]]; then
q" | fdisk "${cfg[diskname]}" > /dev/null q" | fdisk "${cfg[diskname]}" > /dev/null
fi fi
sleep 2 sleep 2
if [[ "${cfg[fde_key_store]}" == "once" ]]; then echo "create bootpartition"
echo "create bootpartition" target_boot="${cfg[diskname]}2"
target_boot="${cfg[diskname]}2" echo "n
echo "n 2
2
+${cfg[bootsize]}G
+${cfg[bootsize]}G w
w q" | fdisk "${cfg[diskname]}" > /dev/null
q" | fdisk "${cfg[diskname]}" > /dev/null sleep 2
sleep 2
if [[ "${cfg[rootfssize]}" == "rest" ]]; then if [[ "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${cfg[diskname]}3" target_partition_tmp="${cfg[diskname]}3"
echo "create rootfs" echo "create rootfs"
echo "n echo "n
3 3
w w
q" | fdisk "${cfg[diskname]}" > /dev/null q" | fdisk "${cfg[diskname]}" > /dev/null
elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then elif [[ ! "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${cfg[diskname]}3" target_partition_tmp="${cfg[diskname]}3"
echo "create rootfs with a specific size" echo "create rootfs with a specific size"
echo "n echo "n
p p
3 3
@ -47,28 +47,6 @@ if [[ "${cfg[fde_key_store]}" == "once" ]]; then
+${rootfssize}G +${rootfssize}G
w w
q" | fdisk "${cfg[diskname]}" > /dev/null 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 fi
sleep 2 sleep 2
@ -96,7 +74,7 @@ mkswap "/dev/mapper/voidvg.${diskid}-swap"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"
btrfs subvol create "${dest}/rootfs" btrfs subvol create "${dest}/rootfs"
btrfs subvol create "${dest}/homefs" btrfs subvol create "${dest}/homefs"
mkdir -p "${dest}/snapshot" "${dest}/backup" mkdir -p "${dest}/system/snapshots/{update,regular}" "${dest}/system/backup"
umount "${dest}" umount "${dest}"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=rootfs 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}" mkfs.btrfs -q -f "${target_boot}"
mount "${target_boot}" "${dest}/boot" mount "${target_boot}" "${dest}/boot"
btrfs subvol create "${dest}/boot/bootfs" 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" umount "${dest}/boot"
mount "${target_boot}" "${dest}/boot" -o subvol=bootfs mount "${target_boot}" "${dest}/boot" -o subvol=bootfs
fi fi