Update auto partitioning to use lsblk output rather than the previous mess
This commit is contained in:
parent
0640a65e0b
commit
5416f553fc
@ -12,7 +12,7 @@
|
||||
# immutable variables {
|
||||
|
||||
readonly DIST="ArchLabs" # Linux distributor
|
||||
readonly VER="1.6.75" # Installer version
|
||||
readonly VER="1.6.76" # Installer version
|
||||
readonly LIVE="liveuser" # Live session user
|
||||
readonly MNT="/mnt/install" # Install mountpoint
|
||||
readonly ERR="/tmp/errlog" # Built-in error log
|
||||
|
126
src/lib/mount.sh
126
src/lib/mount.sh
@ -18,8 +18,9 @@ format() {
|
||||
|
||||
decr_count() {
|
||||
# remove a partition from the dialog list and decrement the number partitions left
|
||||
(( $# == 1 )) || return 1
|
||||
|
||||
local p="$1"
|
||||
[[ $p ]] || return 1
|
||||
PARTS="$(sed "s~${p} [0-9]*[G-M]~~; s~${p} [0-9]*\.[0-9]*[G-M]~~" <<< "$PARTS")"
|
||||
(( COUNT > 0 )) && (( COUNT-- ))
|
||||
return 0
|
||||
@ -63,20 +64,15 @@ confirm_mount() {
|
||||
local part="$1"
|
||||
local mount="$2"
|
||||
|
||||
if [[ $mount == "$MNT" ]]; then
|
||||
local msg="Partition: $part\nMountpoint: / (root)"
|
||||
else
|
||||
local msg="Partition: $part\nMountpoint: ${mount#$MNT}"
|
||||
fi
|
||||
local msg="Partition: $part\n"
|
||||
[[ $mount == "$MNT" ]] && msg+="Mountpoint: / (root)" || msg+="Mountpoint: ${mount#$MNT}"
|
||||
|
||||
# partition failed to mount properly
|
||||
if ! [[ $(mount) =~ "$mount" ]]; then
|
||||
infobox "$_MntTitle" "$_MntFail\n$msg\n" 1
|
||||
return 1
|
||||
else
|
||||
# mount was successful
|
||||
infobox "$_MntTitle" "$_MntSucc\n$msg\n" 1
|
||||
decr_count "$part"
|
||||
else
|
||||
infobox "$_MntTitle" "$_MntFail\n$msg\n" 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
@ -84,7 +80,7 @@ confirm_mount() {
|
||||
|
||||
find_partitions() {
|
||||
local str="$1"
|
||||
local err='NONE'
|
||||
local err=''
|
||||
|
||||
# string of partitions as /TYPE/PART SIZE
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
@ -108,7 +104,7 @@ find_partitions() {
|
||||
esac
|
||||
|
||||
# if there aren't enough partitions show the error message
|
||||
if [[ $err != 'NONE' ]]; then
|
||||
if [[ $err ]]; then
|
||||
msgbox "$_ErrTitle" "$err"
|
||||
return 1
|
||||
fi
|
||||
@ -167,9 +163,7 @@ auto_partition() {
|
||||
# confirm or bail
|
||||
yesno "$_PrepParts" "$_PartBody1 $device $_PartBody2" || return 0
|
||||
infobox "$_PrepParts" "\nAuto partitioning device: $device\n" 0
|
||||
|
||||
swapoff -a # make sure swap is disabled in case the device was used for swap
|
||||
|
||||
local dev_info="$(parted -s $device print)"
|
||||
|
||||
# walk the partitions on the device in reverse order and delete them
|
||||
@ -177,88 +171,66 @@ auto_partition() {
|
||||
parted -s $device rm $i >/dev/null 2>&1
|
||||
done
|
||||
|
||||
# make sure we have the correct device table for the system type, gpt or msdos
|
||||
local newtable="gpt"
|
||||
local table="$(awk '/Table:/ {print $3}' <<< "$dev_info")"
|
||||
[[ $SYS == BIOS ]] && newtable="msdos"
|
||||
|
||||
# if the current device table isn't correct run mklabel
|
||||
if [[ $table != "$newtable" ]]; then
|
||||
local newtable
|
||||
[[ $SYS == BIOS ]] && newtable="msdos" || newtable="gpt"
|
||||
if [[ $(awk '/Table:/ {print $3}' <<< "$dev_info") != "$newtable" ]]; then
|
||||
parted -s $device mklabel $newtable >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# when device contains the string 'nvme' then add 'p' before the part number
|
||||
local nvme=""
|
||||
[[ $device =~ nvme ]] && nvme="p"
|
||||
|
||||
local part_num=1
|
||||
BOOT_PART="$device${nvme}$part_num" # set the boot partition label to the first partition
|
||||
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
parted -s $device mkpart primary ext4 1MiB 513MiB >/dev/null 2>&1
|
||||
mkfs.ext4 -q $BOOT_PART >/dev/null 2>&1
|
||||
else
|
||||
parted -s $device mkpart ESP fat32 1MiB 513MiB >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
sleep 0.1; BOOT_PART=$(lsblk -lno NAME $device | awk 'NR==2 {print}')
|
||||
BOOT_DEVICE="$device"
|
||||
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
mkfs.ext4 -q $BOOT_PART >/dev/null 2>&1
|
||||
else
|
||||
mkfs.vfat -F32 $BOOT_PART >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
(( part_num++ )) # increment the partition number
|
||||
BOOT_DEVICE="$device" # only grub on BIOS systems uses this
|
||||
ROOT_PART="${device}${nvme}$part_num" # set root partition label to the second partition
|
||||
|
||||
parted -s $device mkpart primary ext4 513MiB 100% >/dev/null 2>&1
|
||||
sleep 0.1; ROOT_PART=$(lsblk -lno NAME $device | awk 'NR==3 {print}')
|
||||
mkfs.ext4 -q $ROOT_PART >/dev/null 2>&1
|
||||
|
||||
tput civis
|
||||
sleep 0.5 # slow the process down, otherwise lsblk output can be wrong for some things
|
||||
|
||||
echo -e "\nAuto partitioning complete.\n" > /tmp/.devlist
|
||||
lsblk $device -o NAME,MODEL,TYPE,FSTYPE,SIZE >> /tmp/.devlist
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $_PrepParts " --textbox /tmp/.devlist 0 0
|
||||
return 0
|
||||
tput civis; sleep 0.5
|
||||
msgbox "$_PrepParts" "\nAuto partitioning complete.\n$(lsblk $device -o NAME,MODEL,TYPE,FSTYPE,SIZE)"
|
||||
}
|
||||
|
||||
setup_boot_device() {
|
||||
# set BOOT_DEVICE for syslinux on UEFI and grub on BIOS
|
||||
if [[ $BOOT_PART =~ nvme ]]; then
|
||||
BOOT_DEVICE="${BOOT_PART%p[1-9]}"
|
||||
else
|
||||
[[ $BOOT_PART = /dev/nvme* ]] && BOOT_DEVICE="${BOOT_PART%p[1-9]}" ||
|
||||
BOOT_DEVICE="${BOOT_PART%[1-9]}"
|
||||
fi
|
||||
|
||||
BOOT_PART_NUM="${BOOT_PART: -1}"
|
||||
|
||||
# setup the needed partition flags for boot on both system types
|
||||
parted -s $BOOT_DEVICE set $BOOT_PART_NUM boot on >/dev/null 2>&1
|
||||
if [[ $SYS == 'UEFI' ]]; then
|
||||
parted -s $BOOT_DEVICE set $BOOT_PART_NUM esp on >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
show_devices() {
|
||||
tput civis
|
||||
local msg
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk "!/$IGNORE_DEV/"' && /disk|part|lvm|crypt|NAME/ {print $0}' > /tmp/.devlist
|
||||
msg="$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk "!/$IGNORE_DEV/"' && /disk|part|lvm|crypt|NAME/ {print $0}')"
|
||||
else
|
||||
lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk '/disk|part|lvm|crypt|NAME/ {print $0}' > /tmp/.devlist
|
||||
msg="$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk '/disk|part|lvm|crypt|NAME/ {print $0}')"
|
||||
fi
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $_PrepShowDev " --textbox /tmp/.devlist 0 0
|
||||
msgbox "$_PrepShowDev" "$msg"
|
||||
}
|
||||
|
||||
select_device() {
|
||||
local dev
|
||||
local msg
|
||||
if [[ $1 == 'boot' ]]; then
|
||||
msg="$_DevSelTitle for bootloader\n"
|
||||
else
|
||||
unmount_partitions
|
||||
fi
|
||||
[[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || unmount_partitions
|
||||
|
||||
if (( DEV_COUNT == 1 )) && [[ $SYS_DEVS ]]; then
|
||||
if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then
|
||||
DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")"
|
||||
msg="\nOnly one device available$([[ $1 == 'boot' ]] && echo -n " for grub bootloader"):"
|
||||
infobox "$_DevSelTitle" "$msg $DEVICE\n" 1
|
||||
@ -268,7 +240,8 @@ select_device() {
|
||||
--menu "${msg}$_DevSelBody" 0 0 0 $SYS_DEVS)"
|
||||
[[ $? != 0 || $DEVICE == "" ]] && return 1
|
||||
else
|
||||
msg="\nNo available devices for installation to use$([[ $1 == 'boot' ]] && echo -n " for grub bootloader")."
|
||||
msg="\nNo available devices for installation to use$([[ $1 == 'boot' ]] &&
|
||||
echo -n " for grub bootloader")."
|
||||
msgbox "$_ErrTitle" "$msg\n$_Exit"
|
||||
die 1
|
||||
fi
|
||||
@ -294,14 +267,12 @@ edit_partitions() {
|
||||
$( ([[ $DISPLAY ]] && hash gparted >/dev/null 2>&1) && echo -n "gparted -") "cfdisk" "-"\
|
||||
"parted" "-" "$_PartWipe" "-")"
|
||||
[[ $? != 0 || $choice == "" ]] && return 1
|
||||
|
||||
clear
|
||||
tput cnorm
|
||||
clear; tput cnorm
|
||||
|
||||
if [[ $choice != "$_PartWipe" && $choice != "$_PartAuto" ]]; then
|
||||
$choice $device
|
||||
elif [[ $choice == "$_PartWipe" ]]; then
|
||||
yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2" && { clear; wipe -Ifrev $device; }
|
||||
yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2" && wipe -Ifrev $device
|
||||
edit_partitions $device
|
||||
else
|
||||
# if auto_partition fails we need to re-initialize the variables, just to be sure
|
||||
@ -443,18 +414,16 @@ select_filesystem() {
|
||||
|
||||
local fs
|
||||
fs="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_FSTitle: $part " \
|
||||
--menu "\nPartition: ${part}$([[ $cur_fs != "" ]] && echo -en "\nCurrent: ${cur_fs}")\n$_FSBody" 0 0 0 \
|
||||
--menu "\nPartition: ${part}$([[ $cur_fs != "" ]] &&
|
||||
echo -en "\nCurrent: ${cur_fs}")\n$_FSBody" 0 0 0 \
|
||||
$([[ $cur_fs != "" ]] && echo -n "$_Skip -") \
|
||||
"ext4" "${FS_CMDS[ext4]}" "ext3" "${FS_CMDS[ext3]}" \
|
||||
"ext2" "${FS_CMDS[ext2]}" "vfat" "${FS_CMDS[vfat]}" \
|
||||
"ntfs" "${FS_CMDS[ntfs]}" "f2fs" "${FS_CMDS[f2fs]}" \
|
||||
"jfs" "${FS_CMDS[jfs]}" "nilfs2" "${FS_CMDS[nilfs2]}" \
|
||||
"reiserfs" "${FS_CMDS[reiserfs]}" "xfs" "${FS_CMDS[xfs]}")"
|
||||
if [[ $fs == "$_Skip" ]]; then
|
||||
return 0
|
||||
elif [[ $fs == "" ]]; then
|
||||
return 1
|
||||
fi
|
||||
[[ $fs == "$_Skip" ]] && return 0
|
||||
[[ $fs == "" ]] && return 1
|
||||
|
||||
if yesno "$_FSTitle" "\nFormat $part as $fs?\n"; then
|
||||
format $part $fs
|
||||
@ -510,16 +479,9 @@ select_root_partition() {
|
||||
if (( LUKS == 1 && LVM == 0 )); then
|
||||
ROOT_PART="/dev/mapper/$LUKS_NAME"
|
||||
decr_count "$LUKS_PART"
|
||||
elif (( LUKS == 1 && LVM == 1 )); then
|
||||
decr_count "$LUKS_PART"
|
||||
for part in $(echo "$GROUP_PARTS"); do
|
||||
decr_count "$part"
|
||||
done
|
||||
ROOT_PART=""
|
||||
elif (( LUKS == 0 && LVM == 1 )); then
|
||||
for part in $(echo "$GROUP_PARTS"); do
|
||||
decr_count "$part"
|
||||
done
|
||||
elif (( LVM == 1 )); then
|
||||
(( LUKS == 1 )) && decr_count "$LUKS_PART"
|
||||
for part in $(echo "$GROUP_PARTS"); do decr_count "$part"; done
|
||||
ROOT_PART=""
|
||||
fi
|
||||
|
||||
@ -538,7 +500,6 @@ select_root_partition() {
|
||||
|
||||
select_filesystem "$ROOT_PART" || { ROOT_PART=""; return 1; }
|
||||
mount_partition "$ROOT_PART" || { ROOT_PART=""; return 1; }
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -575,6 +536,5 @@ select_mountpoint() {
|
||||
msgbox "$_ErrTitle" "$_ExtErrBody"
|
||||
select_mountpoint || return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
@ -24,11 +24,7 @@ identify_system() {
|
||||
SYS="BIOS"
|
||||
fi
|
||||
|
||||
if [[ $IS_64BIT == true ]]; then
|
||||
readonly BT="$DIST Installer - $SYS (x86_64) - Version $VER"
|
||||
else
|
||||
readonly BT="$DIST Installer - $SYS (i686) - Version $VER"
|
||||
fi
|
||||
readonly BT="$DIST Installer - $SYS (x86_64) - Version $VER"
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -49,7 +45,6 @@ check_requirements() {
|
||||
check_for_errors() {
|
||||
# return if the last process exited normally
|
||||
(( $? == 0 )) && return 0
|
||||
|
||||
local msg="\nThe command exited abnormally: $1"
|
||||
|
||||
# get error message from logfile and strip any non-printable characters,
|
||||
@ -103,10 +98,10 @@ msgbox() {
|
||||
}
|
||||
|
||||
infobox() {
|
||||
local time="$3"
|
||||
local sec="$3"
|
||||
tput civis
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $1 " --infobox "$2\n" 0 0
|
||||
sleep ${time:-2}
|
||||
sleep ${sec:-2}
|
||||
}
|
||||
|
||||
yesno() {
|
||||
|
Reference in New Issue
Block a user