This commit is contained in:
teldra 2021-03-19 14:04:31 +01:00
parent 751dc4db3e
commit 95bd6bc18c
6 changed files with 586 additions and 286 deletions

View File

@ -1,170 +1,5 @@
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]}"
if test -d /sys/firmware/efi; then
source "${modules}"/disk/uefi/config
else
device="${extern_device}"
source "${modules}"/disk/bios/config
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}" -le "2" ]]; then
test -z "${hibernate}" && swapsize="$(( ramsize * 2 ))"
test -z "${hibernate}" || swapsize="$(( ramsize * 3 ))"
elif [[ "${ramsize}" -gt "2" ]] && [[ "${ramsize}" -le "7" ]]; 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

@ -1,120 +1,5 @@
if ! yesno "nun gehts los, sicher?" y; then
exit
fi
module start "disk" "Partition disk"
#umounter "${dest}" || exit
#if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then
# addpkg cryptsetup
#fi
diskid="${cfg[diskid]//-/_}"
if [[ -n "${cfg[wipe]}" ]]; then
echo "Formatting disk"
echo "o
w
q" | fdisk "${cfg[diskname]}" > /dev/null
fi
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
if [[ "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${cfg[diskname]}2"
echo "create rootfs"
echo "n
p
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"
echo "n
p
2
+${rootfssize}G
w
q" | fdisk "${cfg[diskname]}" > /dev/null
fi
if test -d /sys/firmware/efi; then
source "${modules}"/disk/uefi/postconfig
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
source "${modules}"/disk/bios/postconfig
fi
target_partition="${target_partition_tmp}"
if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then
echo -n "${cfg[diskpw]}" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
echo -n "${cfg[diskpw]}" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
#echo -n "oem" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
#echo -n "oem" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
target_partition="/dev/mapper/voidluks-${diskid}"
fi
mkswap "${target_partition}"
vgcreate -q -f "voidvg.${diskid}" "${target_partition}" || exit 1
lvcreate -q -y --name swap -L "${cfg[swapsize]}"G "voidvg.${diskid}"
lvcreate -q -y --name root -l 100%FREE "voidvg.${diskid}"
mkfs.btrfs -q -f "/dev/mapper/voidvg.${diskid}-root"
mkswap "/dev/mapper/voidvg.${diskid}-swap"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"
btrfs subvol create "${dest}/void-rootfs"
btrfs subvol create "${dest}/home"
mkdir -p "${dest}/snapshot"
umount "${dest}"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=void-rootfs
for i in boot home dev proc sys tmp etc var/lib/backup/quelle var/db; do mkdir -p "${dest}/${i}"; done
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"/home -o subvol=home
if [[ "${cfg[fde_key_store]}" == "once" ]]; then
mkfs.btrfs -q -f "${target_boot}"
mount "${target_boot}" "${dest}/boot"
fi
for dir in dev proc sys run; do mkdir -p "${dest}"/$dir ; mount --rbind /$dir "${dest}"/$dir ; mount --make-rslave "${dest}"/$dir ; done
setconf add rootuuid "$(blkid -o value -s UUID ${target_partition})"
setconf add partuuid "$(blkid -o value -s UUID ${cfg[diskname]}${cfg[target_part]})"
[[ "${cfg[fde_key_store]}" == "once" ]] && setconf "add" "bootuuid" "$(blkid -o value -s UUID ${target_boot})"
setconf add swapuuid "$(blkid -o value -s UUID /dev/mapper/voidvg.${diskid}-swap)"
mount -t tmpfs -o size=512m tmpfs "${dest}"/tmp
module end

170
modules/disk/bios/config Normal file
View File

@ -0,0 +1,170 @@
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}" -le "2" ]]; then
test -z "${hibernate}" && swapsize="$(( ramsize * 2 ))"
test -z "${hibernate}" || swapsize="$(( ramsize * 3 ))"
elif [[ "${ramsize}" -gt "2" ]] && [[ "${ramsize}" -le "7" ]]; 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

@ -0,0 +1,120 @@
if ! yesno "nun gehts los, sicher?" y; then
exit
fi
module start "disk" "Partition disk"
#umounter "${dest}" || exit
#if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then
# addpkg cryptsetup
#fi
diskid="${cfg[diskid]//-/_}"
if [[ -n "${cfg[wipe]}" ]]; then
echo "Formatting disk"
echo "o
w
q" | fdisk "${cfg[diskname]}" > /dev/null
fi
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
if [[ "${cfg[rootfssize]}" == "rest" ]]; then
target_partition_tmp="${cfg[diskname]}2"
echo "create rootfs"
echo "n
p
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"
echo "n
p
2
+${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
target_partition="${target_partition_tmp}"
if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then
echo -n "${cfg[diskpw]}" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
echo -n "${cfg[diskpw]}" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
#echo -n "oem" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
#echo -n "oem" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
target_partition="/dev/mapper/voidluks-${diskid}"
fi
mkswap "${target_partition}"
vgcreate -q -f "voidvg.${diskid}" "${target_partition}" || exit 1
lvcreate -q -y --name swap -L "${cfg[swapsize]}"G "voidvg.${diskid}"
lvcreate -q -y --name root -l 100%FREE "voidvg.${diskid}"
mkfs.btrfs -q -f "/dev/mapper/voidvg.${diskid}-root"
mkswap "/dev/mapper/voidvg.${diskid}-swap"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"
btrfs subvol create "${dest}/void-rootfs"
btrfs subvol create "${dest}/home"
mkdir -p "${dest}/snapshot"
umount "${dest}"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=void-rootfs
for i in boot home dev proc sys tmp etc var/lib/backup/quelle var/db; do mkdir -p "${dest}/${i}"; done
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"/home -o subvol=home
if [[ "${cfg[fde_key_store]}" == "once" ]]; then
mkfs.btrfs -q -f "${target_boot}"
mount "${target_boot}" "${dest}/boot"
fi
for dir in dev proc sys run; do mkdir -p "${dest}"/$dir ; mount --rbind /$dir "${dest}"/$dir ; mount --make-rslave "${dest}"/$dir ; done
setconf add rootuuid "$(blkid -o value -s UUID ${target_partition})"
setconf add partuuid "$(blkid -o value -s UUID ${cfg[diskname]}${cfg[target_part]})"
[[ "${cfg[fde_key_store]}" == "once" ]] && setconf "add" "bootuuid" "$(blkid -o value -s UUID ${target_boot})"
setconf add swapuuid "$(blkid -o value -s UUID /dev/mapper/voidvg.${diskid}-swap)"
mount -t tmpfs -o size=512m tmpfs "${dest}"/tmp
module end

170
modules/disk/uefi/config Normal file
View File

@ -0,0 +1,170 @@
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}" -le "2" ]]; then
test -z "${hibernate}" && swapsize="$(( ramsize * 2 ))"
test -z "${hibernate}" || swapsize="$(( ramsize * 3 ))"
elif [[ "${ramsize}" -gt "2" ]] && [[ "${ramsize}" -le "7" ]]; 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

@ -0,0 +1,120 @@
if ! yesno "nun gehts los, sicher?" y; then
exit
fi
module start "disk" "Partition disk"
#umounter "${dest}" || exit
#if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then
# addpkg cryptsetup
#fi
diskid="${cfg[diskid]//-/_}"
if [[ -n "${cfg[wipe]}" ]]; then
echo "Formatting disk"
echo "g
n
1
+1G
t
1
w
q" | fdisk "${cfg[diskname]}" > /dev/null
fi
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
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"
echo "n
p
3
+${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
target_partition="${target_partition_tmp}"
if [[ ! "${cfg[fde_key_store]}" == "none" ]]; then
echo -n "${cfg[diskpw]}" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
echo -n "${cfg[diskpw]}" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
#echo -n "oem" | cryptsetup luksFormat --type luks1 "${target_partition}" -d -
#echo -n "oem" | cryptsetup luksOpen "${target_partition}" "voidluks-${diskid}" -d -
target_partition="/dev/mapper/voidluks-${diskid}"
fi
mkswap "${target_partition}"
vgcreate -q -f "voidvg.${diskid}" "${target_partition}" || exit 1
lvcreate -q -y --name swap -L "${cfg[swapsize]}"G "voidvg.${diskid}"
lvcreate -q -y --name root -l 100%FREE "voidvg.${diskid}"
mkfs.btrfs -q -f "/dev/mapper/voidvg.${diskid}-root"
mkswap "/dev/mapper/voidvg.${diskid}-swap"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"
btrfs subvol create "${dest}/void-rootfs"
btrfs subvol create "${dest}/home"
mkdir -p "${dest}/snapshot"
umount "${dest}"
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}" -o subvol=void-rootfs
for i in boot home dev proc sys tmp etc var/lib/backup/quelle var/db; do mkdir -p "${dest}/${i}"; done
mount "/dev/mapper/voidvg.${diskid}-root" "${dest}"/home -o subvol=home
if [[ "${cfg[fde_key_store]}" == "once" ]]; then
mkfs.btrfs -q -f "${target_boot}"
mount "${target_boot}" "${dest}/boot"
fi
for dir in dev proc sys run; do mkdir -p "${dest}"/$dir ; mount --rbind /$dir "${dest}"/$dir ; mount --make-rslave "${dest}"/$dir ; done
setconf add rootuuid "$(blkid -o value -s UUID ${target_partition})"
setconf add partuuid "$(blkid -o value -s UUID ${cfg[diskname]}${cfg[target_part]})"
[[ "${cfg[fde_key_store]}" == "once" ]] && setconf "add" "bootuuid" "$(blkid -o value -s UUID ${target_boot})"
setconf add swapuuid "$(blkid -o value -s UUID /dev/mapper/voidvg.${diskid}-swap)"
mount -t tmpfs -o size=512m tmpfs "${dest}"/tmp
module end