Unverified Commit ca27c636 authored by Erazem Kokot's avatar Erazem Kokot
Browse files

Fix custom partitioning

This commit removes a couple of files connected to setting up the disk,
which broke 1.3.1 and replaces them with a single file
(previously configure_device.sh) from 1.3.0 (when it wasn't broken).
parent 3a92bf95
This diff is collapsed.
#!/usr/bin/env bash
prepare_drives() {
op_title="${part_op_msg}"
if (df | grep "${ARCH}" &>/dev/null); then
umount -R "${ARCH}" &>/dev/null &
pid=$! pri=0.1 msg="${wait_load} \n\n \Z1> \Z2umount -R ${ARCH}\Zn" load
swapoff -a &>/dev/null &
fi
until "${mounted}"; do
PART=$(dialog --ok-button "${ok}" --cancel-button "${cancel}" --menu "${part_msg}" 16 64 4 \
"${method0}" "-" \
"${method1}" "-" \
"${method2}" "-" \
"${menu_msg}" "-" 3>&1 1>&2 2>&3)
if [ "$?" -gt "0" ] || [ "${PART}" == "${menu_msg}" ]; then
main_menu
elif [ "${PART}" != "${method2}" ]; then
dev_menu=" Device: | Size: | Type: |"
if "${screen_h}"; then
cat <<-EOF >"${tmp_menu}"
dialog --colors --backtitle "${backtitle}" --title "${title}" --ok-button "${ok}" --cancel-button "${cancel}" --menu "${drive_msg} \n\n ${dev_menu}" 16 60 5 \\
EOF
else
cat <<-EOF >"${tmp_menu}"
dialog --colors --title "${title}" --ok-button "${ok}" --cancel-button "${cancel}" --menu "${drive_msg} \n\n ${dev_menu}" 16 60 5 \\
EOF
fi
cat <<-EOF >>"${tmp_menu}"
$(lsblk -nio NAME,SIZE,TYPE | grep -E "disk|raid[0-9]+$" | sed 's/[^[:alnum:]_., ]//g' | column -t | sort -k 1,1 | uniq | awk '{print "\""$1"\""" ""\"| "$2" | "$3" |==>\""" \\"}' | column -t)
3>&1 1>&2 2>&3
EOF
DRIVE=$(bash "${tmp_menu}")
rm "${tmp_menu}"
if [ -n "${DRIVE}" ]; then
if (grep <<<"${DRIVE}" -E "nvme.*|mmc.*|md.*" &>/dev/null); then
PART_PREFIX="p"
fi
drive_byte=$(lsblk -nibo NAME,SIZE | grep -w "${DRIVE}" | awk '{print $2}')
drive_mib=$((drive_byte / 1024 / 1024))
drive_gigs=$((drive_mib / 1024))
f2fs=$(lsblk -dnro ROTA /dev/"${DRIVE}")
log "Drive size in MB: ${drive_mib}"
log "F2FS state: ${f2fs}"
fs_select
if (yesno "\n${swap_msg0}" "${yes}" "${no}"); then
while (true); do
SWAPSPACE=$(dialog --ok-button "${ok}" --cancel-button "${cancel}" --inputbox "\n${swap_msg1}" 11 55 "512M" 3>&1 1>&2 2>&3)
if [ "$?" -gt "0" ]; then
SWAP=false
break
else
if [ "$(grep -o ".$" <<<"${SWAPSPACE}")" == "M" ]; then
SWAPSPACE=$(sed <<<"${SWAPSPACE}" 's/M//;s/\..*//')
if [ "${SWAPSPACE}" -lt "$(echo "${drive_mib}-5120" | bc)" ]; then
SWAP=true
break
else
msg "\n${swap_err_msg0}"
fi
elif [ "$(grep -o ".$" <<<"${SWAPSPACE}")" == "G" ]; then
SWAPSPACE=$(echo "$(sed <<<"${SWAPSPACE}" 's/G//')*1024" | bc | sed 's/\..*//')
if [ "${SWAPSPACE}" -lt "$(echo "${drive_mib}-5120" | bc)" ]; then
SWAP=true
break
else
msg "\n${swap_err_msg0}"
fi
else
msg "\n${swap_err_msg1}"
fi
fi
done
log "Swapspace size set to: ${SWAPSPACE}"
fi
if (efivar -l &>/dev/null); then
if (yesno "\n${efi_msg0}" "${yes}" "${no}"); then
GPT=true
UEFI=true
log "UEFI boot activated"
fi
fi
if ! "${UEFI}"; then
if (yesno "\n${gpt_msg}" "${yes}" "${no}" 1); then
GPT=true
log "GPT partition scheme activated"
fi
fi
source "${lang_file}"
if "${SWAP}"; then
drive_var="${drive_var1}"
height=13
if "${UEFI}"; then
drive_var="${drive_var2}"
height=14
fi
elif "${UEFI}"; then
drive_var="${drive_var3}"
height=13
else
height=11
fi
if (yesno "\n${drive_var}" "${write}" "${cancel}" 1); then
(
sgdisk --zap-all /dev/"${DRIVE}"
wipefs -a /dev/"${DRIVE}"
) &>/dev/null &
pid=$! pri=0.1 msg="\n${frmt_load} \n\n \Z1> \Z2sgdisk --zap-all /dev/${DRIVE}\Zn" load
log "Format device: /dev/${DRIVE}"
else
unset PART
fi
else
continue
fi
fi
case "${PART}" in
"${method0}")
auto_part
if ! "${mounted}"; then
msg "\n${part_err_msg}"
fi
;;
"${method1}")
auto_encrypt
if ! "${mounted}"; then
msg "\n${part_err_msg}"
fi
;;
"${method2}")
points=$(echo -e "${points_orig}\n${custom} ${custom}-mountpoint")
part_menu
;;
esac
done
}
#!/usr/bin/env bash
auto_encrypt() {
op_title="${partload_op_msg}"
if (yesno "\n${encrypt_var0}" "${yes}" "${no}" 1); then
while [ "${input}" != "${input_chk}" ]; do
input=$(dialog --nocancel --clear --insecure --passwordbox "${encrypt_var1}" 12 55 --stdout)
input_chk=$(dialog --nocancel --clear --insecure --passwordbox "${encrypt_var2}" 12 55 --stdout)
if [ -z "${input}" ]; then
msg "\n${passwd_msg0}"
input_chk=default
elif [ "${input}" != "${input_chk}" ]; then
msg "\n${passwd_msg1}"
fi
done
else
return
fi
if "${GPT}"; then
if "${UEFI}"; then
echo -e "n\n\n\n512M\nef00\nn\n\n\n\n\nw\ny" | gdisk /dev/"${DRIVE}" &>/dev/null &
pid=$! pri=0.1 msg="\n${load_var0} \n\n \Z1> \Z2gdisk /dev/${DRIVE}\Zn" load
BOOT="${DRIVE}${PART_PREFIX}1"
ROOT="${DRIVE}${PART_PREFIX}2"
else
echo -e "o\ny\nn\n1\n\n+512M\n\nn\n2\n\n+1M\nEF02\nn\n3\n\n\n\nw\ny" | gdisk /dev/"${DRIVE}" &>/dev/null &
pid=$! pri=0.1 msg="\n${load_var0} \n\n \Z1> \Z2gdisk /dev/${DRIVE}\Zn" load
BOOT="${DRIVE}${PART_PREFIX}1"
ROOT="${DRIVE}${PART_PREFIX}3"
fi
else
echo -e "o\nn\np\n1\n\n+512M\nn\np\n2\n\n\nw" | fdisk /dev/"${DRIVE}" &>/dev/null &
pid=$! pri=0.1 msg="\n${load_var0} \n\n \Z1> \Z2fdisk /dev/${DRIVE}\Zn" load
BOOT="${DRIVE}${PART_PREFIX}1"
ROOT="${DRIVE}${PART_PREFIX}2"
fi
log "Create boot partition: ${BOOT}"
log "Create root partition: ${ROOT}"
(
sgdisk --zap-all /dev/"${ROOT}"
sgdisk --zap-all /dev/"${BOOT}"
wipefs -a /dev/"${ROOT}"
wipefs -a /dev/"${BOOT}"
) &>/dev/null &
pid=$! pri=0.1 msg="\n${frmt_load} \n\n \Z1> \Z2wipefs -a /dev/${ROOT}\Zn" load
log "Wipe boot partition"
log "Wipe root partition"
(
lvm pvcreate /dev/"${ROOT}"
lvm vgcreate lvm /dev/"${ROOT}"
) &>/dev/null &
pid=$! pri=0.1 msg="\n${pv_load} \n\n \Z1> \Z2lvm pvcreate /dev/${ROOT}\Zn" load
log "Create physical root volume: /dev/${ROOT}"
if "${SWAP}"; then
lvm lvcreate -L "${SWAPSPACE}M" -n swap lvm &>/dev/null &
pid=$! pri=0.1 msg="\n${swap_load} \n\n \Z1> \Z2lvm lvcreate -L ${SWAPSPACE}M -n swap lvm\Zn" load
log "Create logical swapspace"
fi
(
lvm lvcreate -L 500M -n tmp lvm
lvm lvcreate -l 100%FREE -n lvroot lvm
) &>/dev/null &
pid=$! pri=0.1 msg="\n${lv_load} \n\n \Z1> \Z2lvm lvcreate -l 100%FREE -n lvroot lvm\Zn" load
log "Create logical root volume: lvroot"
log "Create logical tmp filesystem: tmp"
(
printf "%s" "${input}" | cryptsetup luksFormat -c aes-xts-plain64 -s 512 /dev/lvm/lvroot -
printf "%s" "${input}" | cryptsetup open --type luks /dev/lvm/lvroot root -
) &>/dev/null &
pid=$! pri=0.2 msg="\n${encrypt_load} \n\n \Z1> \Z2cryptsetup luksFormat -c aes-xts-plain64 -s 512 /dev/lvm/lvroot\Zn" load
log "Encrypt logical volume: lvroot"
unset input input_chk
input_chk=default
wipefs -a /dev/mapper/root &>/dev/null
case "${FS}" in
jfs | reiserfs)
echo -e "y" | mkfs."${FS}" /dev/mapper/root &>/dev/null &
;;
*)
mkfs."${FS}" /dev/mapper/root &>/dev/null &
;;
esac
pid=$! pri=1 msg="\n${load_var1} \n\n \Z1> \Z2mkfs.${FS} /dev/mapper/root\Zn" load
log "Create root filesystem: ${FS}"
if "${UEFI}"; then
mkfs.vfat -F32 /dev/"${BOOT}" &>/dev/null &
pid=$! pri=0.2 msg="\n${efi_load1} \n\n \Z1> \Z2mkfs.vfat -F32 /dev/${BOOT}\Zn" load
esp_part="/dev/${BOOT}"
esp_mnt=/boot
log "Create boot filesystem: vfat"
else
mkfs.ext4 -O \^64bit /dev/"${BOOT}" &>/dev/null &
pid=$! pri=0.2 msg="\n${boot_load} \n\n \Z1> \Z2mkfs.ext4 /dev/${BOOT}\Zn" load
log "Create boot filesystem: ext4"
fi
(
mount /dev/mapper/root "${ARCH}"
echo "$?" >/tmp/ex_status.var
mkdir "${ARCH}"/boot
mount /dev/"${BOOT}" "${ARCH}"/boot
) &>/dev/null &
pid=$! pri=0.1 msg="\n${mnt_load} \n\n \Z1> \Z2mount /dev/mapper/root ${ARCH}\Zn" load
log "Mount root filesystem: ${ARCH}"
log "Mount boot filesystem: ${ARCH}/boot"
if [ "$(</tmp/ex_status.var)" -eq "0" ]; then
mounted=true
crypted=true
fi
rm /tmp/ex_status.var
}
#!/usr/bin/env bash
fs_select() {
if "${vfat}"; then
FS=$(dialog --menu "${vfat_msg}" 11 65 1 \
"vfat" "${fs7}" 3>&1 1>&2 2>&3)
if [ "$?" -gt "0" ]; then
part_menu
fi
vfat=false
else
if [ "${f2fs}" -eq "0" ]; then
FS=$(dialog --nocancel --menu "${fs_msg}" 17 65 8 \
"ext4" "${fs0}" \
"ext3" "${fs1}" \
"ext2" "${fs2}" \
"btrfs" "${fs3}" \
"f2fs" "${fs6}" \
"jfs" "${fs4}" \
"reiserfs" "${fs5}" \
"xfs" "${fs8}" 3>&1 1>&2 2>&3)
elif "${btrfs}"; then
FS=$(dialog --nocancel --menu "${fs_msg}" 16 65 7 \
"ext4" "${fs0}" \
"ext3" "${fs1}" \
"ext2" "${fs2}" \
"btrfs" "${fs3}" \
"jfs" "${fs4}" \
"reiserfs" "${fs5}" \
"xfs" "${fs8}" 3>&1 1>&2 2>&3)
else
FS=$(dialog --nocancel --menu "${fs_msg}" 15 65 6 \
"ext4" "${fs0}" \
"ext3" "${fs1}" \
"ext2" "${fs2}" \
"jfs" "${fs4}" \
"reiserfs" "${fs5}" \
"xfs" "${fs8}" 3>&1 1>&2 2>&3)
btrfs=true
fi
fi
if [ "${FS}" == "f2fs" ]; then
enable_f2fs=true
elif [ "${FS}" == "btrfs" ]; then
enable_btrfs=true
elif [ "${FS}" == "xfs" ]; then
enable_xfs=true
fi
}
#!/usr/bin/env bash
# Copyright (C) 2017 Dylan Schacht
part_class() {
op_title="${edit_op_msg}"
if [ -z "${part}" ]; then
unset DRIVE ROOT
return
else
part_size=$(grep <<<"${device_list}" -w "${part}" | awk '{print $2}')
part_type=$(grep <<<"${device_list}" -w "${part}" | awk '{print $3}')
part_fs=$(grep <<<"${device_list}" -w "${part}" | awk '{print $4}')
part_mount=$(df | grep -w "${part}" | awk '{print $6}' | sed 's/mnt\/\?//')
fi
if [ "${part_type}" == "lvm" ]; then
part=${part/-//}
fi
if [ "${part_fs}" == "linux_raid_member" ]; then # do nothing
part_menu
elif [ "${part_type}" == "disk" ] || ( (grep -E "raid[0-9]+" <<<"${part_type}" &>/dev/null) && [ -z "${part_fs}" ]); then # Partition
source "${lang_file}"
if (df | grep -w "${part}" | grep "${ARCH}" &>/dev/null); then
if (yesno "\n${mount_warn_var}" "${edit}" "${cancel}" 1); then
points=$(echo -e "${points_orig}\n${custom} ${custom}-mountpoint")
(
umount -R "${ARCH}"
swapoff -a
) &>/dev/null &
pid=$! pri=0.1 msg="${wait_load} \n\n \Z1> \Z2umount -R /mnt\Zn" load
mounted=false
unset DRIVE
select_util
if "${gpart}"; then
${UTIL} /dev/"${part}" &>/dev/null
else
${UTIL} /dev/"${part}"
fi
sleep 0.5
clear
fi
elif (yesno "\n${manual_part_var3}" "${edit}" "${cancel}"); then
select_util
if "${gpart}"; then
${UTIL} /dev/"${part}" &>/dev/null
else
${UTIL} /dev/"${part}"
fi
sleep 0.5
clear
fi
part_menu
elif [ "${part}" == "${done_msg}" ]; then # Done
if ! "${mounted}"; then
msg "\n${root_err_msg1}"
part_menu
else
if [ -z "${BOOT}" ]; then
BOOT="${ROOT}"
fi
final_part=$( (
df -h | grep "${ARCH}" | awk '{print $1,$2,$6 "\\n"}' | sed 's/mnt\/\?//'
swapon | awk 'NR==2 {print $1,$3,"SWAP"}'
) | column -t)
final_count=$(wc <<<"${final_part}" -l)
if [ "${final_count}" -lt "7" ]; then
height=17
elif [ "${final_count}" -lt "13" ]; then
height=23
elif [ "${final_count}" -lt "17" ]; then
height=26
else
height=30
fi
part_menu="${partition}: ${size}: ${mountpoint}:"
if (yesno "\n${write_confirm_msg} \n\n ${part_menu} \n\n${final_part} \n\n ${write_confirm}" "${write}" "${cancel}" 1); then
if (efivar -l &>/dev/null); then
if (fdisk -l | grep "EFI" &>/dev/null); then
if (yesno "\n${efi_man_msg}" "${yes}" "${no}"); then
if [ "$(fdisk -l | grep -c "EFI")" -gt "1" ]; then
efint=1
while (true); do
if [ "$(fdisk -l | grep "EFI" | awk "NR==${efint} {print \$1}")" == "" ]; then
msg "${efi_err_msg1}"
part_menu
fi
esp_part=$(fdisk -l | grep "EFI" | awk "NR==${efint} {print \$1}")
esp_mnt=$(df -T | grep "${esp_part}" | awk '{print $7}' | sed 's|/mnt||')
if (df -T | grep "${esp_part}" &>/dev/null); then
break
else
efint=$((efint + 1))
fi
done
else
esp_part=$(fdisk -l | grep "EFI" | awk '{print $1}')
if ! (df -T | grep "${esp_part}" &>/dev/null); then
source "${lang_file}"
if (yesno "\n${efi_mnt_var}" "${yes}" "${no}"); then
if ! (mountpoint "${ARCH}"/boot &>/dev/null); then
mkdir "${ARCH}"/boot &>/dev/null
mount "${esp_part}" "${ARCH}"/boot
else
msg "\n${efi_err_msg}"
part_menu
fi
else
part_menu
fi
else
esp_mnt=$(df -T | grep "${esp_part}" | awk '{print $7}' | sed 's|/mnt||')
fi
fi
source "${lang_file}"
if ! (df -T | grep "${esp_part}" | grep "vfat" &>/dev/null); then
if (yesno "\n${vfat_var}" "${yes}" "${no}"); then
(
umount -R "${esp_mnt}"
mkfs.vfat -F32 "${esp_part}"
mount "${esp_part}" "${esp_mnt}"
) &>/dev/null &
pid=$! pri=0.2 msg="\n${efi_load1} \n\n \Z1> \Z2mkfs.vfat -F32 ${esp_part}\Zn" load
UEFI=true
else
part_menu
fi
else
UEFI=true
export esp_part esp_mnt
fi
fi
fi
fi
if "${enable_f2fs}"; then
if ! (df | grep "${ARCH}/boot\|${ARCH}/boot/efi" &>/dev/null); then
FS="f2fs" source "${lang_file}"
msg "\n${fs_err_var}"
part_menu
fi
elif "${enable_btrfs}"; then
if ! (df | grep "${ARCH}/boot\|${ARCH}/boot/efi" &>/dev/null); then
FS="btrfs" source "${lang_file}"
msg "\n${fs_err_var}"
part_menu
fi
fi
sleep 1
pid=$! pri=0.1 msg="${wait_load} \n\n \Z1> \Z2Finalize...\Zn" load
return
else
part_menu
fi
fi
else # Install on a partition or md device with a file system
source "${lang_file}" &>/dev/null
if [ -z "${ROOT}" ]; then
case "${part_size}" in
[1-9]T | [4-9]G | [1-9][0-9]*[GT] | [4-9].*[GT] | [4-9],*[GT])
if (yesno "\n${root_var}" "${yes}" "${no}" 1); then
f2fs=$(lsblk -dnro ROTA /dev/${part})
fs_select
if [ "$?" -gt "0" ]; then
part_menu
fi
source "${lang_file}"
if (yesno "\n${root_confirm_var}" "${write}" "${cancel}" 1); then
(
sgdisk --zap-all /dev/"${part}"
wipefs -a /dev/"${part}"
) &>/dev/null &
pid=$! pri=0.1 msg="\n${frmt_load} \n\n \Z1> \Z2wipefs -a /dev/${part}\Zn" load
case "${FS}" in
jfs | reiserfs)
echo -e "y" | mkfs."${FS}" /dev/"${part}" &>/dev/null &
;;
*)
mkfs."${FS}" /dev/"${part}" &>/dev/null &
;;
esac
pid=$! pri=1 msg="\n${load_var1} \n\n \Z1> \Z2mkfs.${FS} /dev/${part}\Zn" load
(
mount /dev/"${part}" "${ARCH}"
echo "$?" >/tmp/ex_status.var
) &>/dev/null &
pid=$! pri=0.1 msg="\n${mnt_load} \n\n \Z1> \Z2mount /dev/${part} ${ARCH}\Zn" load
if [ "$(</tmp/ex_status.var)" -eq "0" ]; then
mounted=true
ROOT="${part}"
if [ "${part_type}" == "lvm" ]; then
lvm_pv=$(lvdisplay -m | grep -A 20 /dev/${part} | grep "Physical volume" | sed 's/^\s\+//g;s/\s\+/ /g' | cut -d ' ' -f 3)
DRIVE=$(lsblk -dnro PKNAME ${lvm_pv})
else
DRIVE=$(lsblk -dnro PKNAME /dev/${part})
fi
else
msg "\n${part_err_msg1}"
return
fi
fi
else
part_menu
fi
;;
*)
msg "\n${root_err_msg}"
;;
esac
elif [ -n "${part_mount}" ]; then
if (yesno "\n${manual_part_var0}" "${edit}" "${back}" 1); then
if [ "${part}" == "${ROOT}" ]; then
if (yesno "\n${manual_part_var2}" "${yes}" "${no}" 1); then
mounted=false
unset ROOT DRIVE
umount -R "${ARCH}" &>/dev/null &
pid=$! pri=0.1 msg="${wait_load} \n\n \Z1> \Z2umount -R ${ARCH}\Zn" load
fi
else
if [ "${part_mount}" == "[SWAP]" ]; then
if (yesno "\n${manual_swap_var}" "${yes}" "${no}" 1); then
swapoff /dev/"${part}" &>/dev/null &
pid=$! pri=0.1 msg="${wait_load} \n\n \Z1> \Z2swapoff /dev/${part}\Zn" load
fi
elif (yesno "\n${manual_part_var1}" "${yes}" "${no}" 1); then
umount "${ARCH}"/"${part_mount}" &>/dev/null &
pid=$! pri=0.1 msg="${wait_load} \n\n \Z1> \Z2umount ${ARCH}${part_mount}\Zn" load
rm -r "${ARCH}"/"${part_mount}"
points=$(echo -e "${part_mount} mountpoint>\n${points}")
fi
fi