archboot/usr/bin/archboot-setup.sh

4800 lines
194 KiB
Bash
Raw Normal View History

2020-07-24 19:00:49 +02:00
#!/usr/bin/env bash
# we rely on some output which is parsed in english!
2010-08-12 20:55:08 +02:00
unset LANG
2008-10-20 22:39:25 +02:00
ANSWER="/tmp/.setup"
TITLE="Arch Linux Installation"
# use the first VT not dedicated to a running console
LOG="/dev/tty7"
# don't use /mnt because it's intended to mount other things there!
DESTDIR="/install"
RUNNING_ARCH="$(uname -m)"
2010-06-27 11:18:21 +02:00
EDITOR=""
2012-04-23 15:17:42 +02:00
_BLKID="blkid -c /dev/null"
2013-07-17 09:27:27 +02:00
_LSBLK="lsblk -rpno"
2013-03-16 22:10:26 +01:00
2009-12-22 22:11:50 +01:00
# name of kernel package
KERNELPKG="linux"
2012-01-13 15:52:11 +01:00
# name of the kernel image
[[ "${RUNNING_ARCH}" == "x86_64" ]] && VMLINUZ="vmlinuz-${KERNELPKG}"
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
VMLINUZ="Image.gz"
VMLINUZ_EFISTUB="Image"
fi
# name of the initramfs filesystem
2012-01-13 15:52:11 +01:00
INITRAMFS="initramfs-${KERNELPKG}"
2014-11-12 14:18:16 +01:00
# name of intel ucode initramfs image
INTEL_UCODE="intel-ucode.img"
# name of amd ucode initramfs image
AMD_UCODE="amd-ucode.img"
2008-10-20 22:39:25 +02:00
# abstract the common pacman args
PACMAN="pacman --root "${DESTDIR}" --cachedir="${DESTDIR}"/var/cache/pacman/pkg --noconfirm --noprogressbar"
2008-10-20 22:39:25 +02:00
# downloader
DLPROG="wget"
# sources
2010-06-27 11:18:21 +02:00
SYNC_URL=""
2008-10-20 22:39:25 +02:00
MIRRORLIST="/etc/pacman.d/mirrorlist"
2013-06-07 08:53:17 +02:00
unset PACKAGES
2009-02-11 22:31:52 +01:00
2008-10-20 22:39:25 +02:00
# partitions
2010-06-27 11:18:21 +02:00
PART_ROOT=""
2008-12-29 20:19:31 +01:00
ROOTFS=""
2008-10-20 22:39:25 +02:00
# install stages
2021-09-14 14:46:59 +02:00
S_SRC=0 # choose mirror
2008-10-20 22:39:25 +02:00
S_NET=0 # network configuration
S_PART=0 # partitioning
S_MKFS=0 # formatting
2009-07-12 19:13:12 +02:00
S_MKFSAUTO=0 # auto fs part/formatting
2008-10-20 22:39:25 +02:00
S_INSTALL=0 # package installation
S_CONFIG=0 # configuration editing
# menu item tracker- autoselect the next item
NEXTITEM=""
# DIALOG()
# an el-cheapo dialog wrapper
#
# parameters: see dialog(1)
# returns: whatever dialog did
DIALOG() {
2011-02-04 14:34:11 +01:00
dialog --backtitle "${TITLE}" --aspect 15 "$@"
return $?
2008-10-20 22:39:25 +02:00
}
# chroot_mount()
# prepares target system as a chroot
#
chroot_mount()
{
2013-09-18 18:52:41 +02:00
[[ -e "${DESTDIR}/proc" ]] || mkdir -m 555 "${DESTDIR}/proc"
[[ -e "${DESTDIR}/sys" ]] || mkdir -m 555 "${DESTDIR}/sys"
[[ -e "${DESTDIR}/dev" ]] || mkdir -m 755 "${DESTDIR}/dev"
2021-10-16 00:08:11 +02:00
mount proc "${DESTDIR}/proc" -t proc -o nosuid,noexec,nodev
mount sys "${DESTDIR}/sys" -t sysfs -o nosuid,noexec,nodev,ro
mount udev "${DESTDIR}/dev" -t devtmpfs -o mode=0755,nosuid
mount devpts "${DESTDIR}/dev/pts" -t devpts -o mode=0620,gid=5,nosuid,noexec
mount shm "${DESTDIR}/dev/shm" -t tmpfs -o mode=1777,nosuid,nodev
}
# chroot_umount()
# tears down chroot in target system
#
chroot_umount()
{
2013-09-18 15:53:26 +02:00
umount -R "${DESTDIR}/proc"
umount -R "${DESTDIR}/sys"
umount -R "${DESTDIR}/dev"
}
getfstype()
{
2013-07-17 08:37:17 +02:00
echo "$(${_LSBLK} FSTYPE ${1})"
}
# getfsuuid()
# converts /dev devices to FSUUIDs
2009-03-28 13:36:54 +01:00
#
# parameters: device file
# outputs: FSUUID on success
2009-03-28 13:36:54 +01:00
# nothing on failure
# returns: nothing
getfsuuid()
2009-03-28 13:36:54 +01:00
{
2013-07-17 08:37:17 +02:00
echo "$(${_LSBLK} UUID ${1})"
2009-03-28 13:36:54 +01:00
}
2010-05-24 15:05:20 +02:00
# parameters: device file
# outputs: LABEL on success
# nothing on failure
# returns: nothing
getfslabel()
2010-05-24 15:05:20 +02:00
{
2013-07-17 08:37:17 +02:00
echo "$(${_LSBLK} LABEL ${1})"
}
getpartuuid()
{
2013-07-17 08:37:17 +02:00
echo "$(${_LSBLK} PARTUUID ${1})"
}
getpartlabel()
{
2013-07-17 08:37:17 +02:00
echo "$(${_LSBLK} PARTLABEL ${1})"
2010-05-24 15:05:20 +02:00
}
2012-07-25 21:40:32 +02:00
# list all net devices with mac adress
net_interfaces() {
2012-07-25 21:40:32 +02:00
for i in $(ls /sys/class/net); do
echo "$i $(cat /sys/class/net/$i/address)"
done
}
# activate_dmraid()
# activate dmraid devices
activate_dmraid()
{
2013-05-21 12:38:07 +02:00
if [[ -e /usr/bin/dmraid ]]; then
DIALOG --infobox "Activating dmraid arrays..." 0 0
2013-05-21 12:38:07 +02:00
dmraid -ay -I -Z >/dev/null 2>&1
fi
}
# activate_lvm2
# activate lvm2 devices
activate_lvm2()
{
2010-05-28 16:45:28 +02:00
ACTIVATE_LVM2=""
if [[ -e /usr/bin/lvm ]]; then
2011-02-04 14:34:11 +01:00
OLD_LVM2_GROUPS=${LVM2_GROUPS}
OLD_LVM2_VOLUMES=${LVM2_VOLUMES}
DIALOG --infobox "Scanning logical volumes..." 0 0
2013-05-21 12:38:07 +02:00
lvm vgscan --ignorelockingfailure >/dev/null 2>&1
DIALOG --infobox "Activating logical volumes..." 0 0
2013-05-21 12:38:07 +02:00
lvm vgchange --ignorelockingfailure --ignoremonitoring -ay >/dev/null 2>&1
2010-05-28 18:00:25 +02:00
LVM2_GROUPS="$(vgs -o vg_name --noheading 2>/dev/null)"
LVM2_VOLUMES="$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)"
2011-02-04 14:34:11 +01:00
[[ "${OLD_LVM2_GROUPS}" = "${LVM2_GROUPS}" && "${OLD_LVM2_GROUPS}" = "${LVM2_GROUPS}" ]] && ACTIVATE_LVM2="no"
fi
}
# activate_raid
# activate md devices
activate_raid()
{
2010-05-28 16:45:28 +02:00
ACTIVATE_RAID=""
2013-05-21 12:38:07 +02:00
if [[ -e /usr/bin/mdadm ]]; then
DIALOG --infobox "Activating RAID arrays..." 0 0
2013-05-21 12:38:07 +02:00
mdadm --assemble --scan >/dev/null 2>&1 || ACTIVATE_RAID="no"
fi
}
# activate_luks
# activate luks devices
activate_luks()
{
2010-05-28 16:45:28 +02:00
ACTIVATE_LUKS=""
if [[ -e /usr/bin/cryptsetup ]]; then
DIALOG --infobox "Scanning for luks encrypted devices..." 0 0
2013-07-17 09:27:27 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep "crypto_LUKS")" ]]; then
2013-07-24 12:38:28 +02:00
for PART in $(${_LSBLK} NAME,FSTYPE | grep " crypto_LUKS$" | cut -d' ' -f 1); do
2010-06-03 22:38:56 +02:00
# skip already encrypted devices, device mapper!
2013-07-24 15:43:37 +02:00
if ! [[ "$(${_LSBLK} TYPE ${PART} | grep "crypt$")" ]]; then
2010-05-28 17:49:07 +02:00
RUN_LUKS=""
2011-02-04 14:34:11 +01:00
DIALOG --yesno "Setup detected luks encrypted device, do you want to activate ${PART} ?" 0 0 && RUN_LUKS="1"
[[ "${RUN_LUKS}" = "1" ]] && _enter_luks_name && _enter_luks_passphrase && _opening_luks
[[ "${RUN_LUKS}" = "" ]] && ACTIVATE_LUKS="no"
2010-06-03 22:38:56 +02:00
else
ACTIVATE_LUKS="no"
fi
done
else
ACTIVATE_LUKS="no"
fi
fi
}
# activate_special_devices()
# activate special devices:
# activate dmraid, lvm2 and raid devices, if not already activated during bootup!
# run it more times if needed, it can be hidden by each other!
activate_special_devices()
{
2010-05-28 16:45:28 +02:00
ACTIVATE_RAID=""
ACTIVATE_LUKS=""
ACTIVATE_LVM2=""
activate_dmraid
2011-02-04 14:34:11 +01:00
while ! [[ "${ACTIVATE_LVM2}" = "no" && "${ACTIVATE_RAID}" = "no" && "${ACTIVATE_LUKS}" = "no" ]]; do
activate_raid
activate_lvm2
activate_luks
done
}
2010-03-16 07:32:39 +01:00
# destdir_mounts()
2011-02-04 14:34:11 +01:00
# check if PART_ROOT is set and if something is mounted on ${DESTDIR}
2010-03-16 07:32:39 +01:00
destdir_mounts(){
# Don't ask for filesystem and create new filesystems
ASK_MOUNTPOINTS=""
PART_ROOT=""
2011-02-04 14:34:11 +01:00
# check if something is mounted on ${DESTDIR}
PART_ROOT="$(mount | grep "${DESTDIR} " | cut -d' ' -f 1)"
# Run mountpoints, if nothing is mounted on ${DESTDIR}
if [[ "${PART_ROOT}" = "" ]]; then
DIALOG --msgbox "Setup couldn't detect mounted partition(s) in ${DESTDIR}, please set mountpoints first." 0 0
2013-10-19 09:36:35 +02:00
detect_uefi_boot
mountpoints || return 1
fi
}
# lists linux blockdevices
blockdevices() {
# all available block disk devices
for dev in $(${_LSBLK} NAME,TYPE | grep "disk$" | cut -d' ' -f1); do
# exclude checks:
#- dmraid_devices
# $(${_LSBLK} TYPE ${dev} | grep dmraid
2013-08-07 19:45:08 +02:00
#- iso9660 devices
# "$(${_LSBLK} FSTYPE ${dev} | grep "iso9660")
#- fakeraid isw devices
2013-08-21 09:09:10 +02:00
# $(${_LSBLK} FSTYPE ${dev} | grep "isw_raid_member")
#- fakeraid ddf devices
# $(${_LSBLK} FSTYPE ${dev} | grep "ddf_raid_member")
if ! [[ "$(${_LSBLK} TYPE ${dev} | grep "dmraid")" || "$(${_LSBLK} FSTYPE ${dev} | grep "iso9660")" || "$(${_LSBLK} FSTYPE ${dev} | grep "isw_raid_member")" || "$(${_LSBLK} FSTYPE ${dev} | grep "ddf_raid_member")" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# lists linux blockdevice partitions
blockdevices_partitions() {
# all available block devices partitions
# printk off needed cause of parted usage
printk off
for part in $(${_LSBLK} NAME,TYPE | grep "part$"| cut -d' ' -f1); do
# exclude checks:
#- part of raid device
2013-07-20 08:54:10 +02:00
# $(${_LSBLK} FSTYPE ${part} | grep "linux_raid_member")
#- part of lvm2 device
# $(${_LSBLK} FSTYPE /dev/${part} | grep "LVM2_member")
#- part of luks device
# $(${_LSBLK} FSTYPE /dev/${part} | grep "crypto_LUKS")
#- extended partition
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")
# - extended partition (LBA)
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")
#- bios_grub partitions
# "$(echo ${part} | grep "[a-z]$(parted -s $(${_LSBLK} PKNAME ${part}) print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$")"
2013-08-07 19:45:08 +02:00
#- iso9660 devices
# "$(${_LSBLK} FSTYPE -s ${part} | grep "iso9660")"
if ! [[ "$(${_LSBLK} FSTYPE ${part} | grep "linux_raid_member")" || "$(${_LSBLK} FSTYPE ${part} | grep "LVM2_member")" || "$(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")" || "$(echo ${part} | grep "[a-z]$(parted -s $(${_LSBLK} PKNAME ${part}) print 2>/dev/null | grep bios_grub | cut -d " " -f 2)$")" || "$(${_LSBLK} FSTYPE -s ${part} | grep "iso9660")" ]]; then
echo "${part}"
[[ "${1}" ]] && echo ${1}
fi
done
printk on
2010-05-19 20:10:52 +02:00
}
# list none partitionable raid md devices
raid_devices() {
2013-07-20 08:54:10 +02:00
for dev in $(${_LSBLK} NAME,TYPE | grep " raid.*$" | cut -d' ' -f 1 | grep -v "_d.*$" | sort -u); do
2013-07-19 09:46:03 +02:00
# exclude checks:
# - part of lvm2 device_found
# ${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")
# - part of isw fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member")
2013-08-21 09:09:10 +02:00
# - part of ddf fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")
if ! [[ "$(${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")" || "$(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")" || "$(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member")" || "$(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")" ]]; then
2013-07-19 09:46:03 +02:00
echo "${dev}"
[[ "${1}" ]] && echo ${1}
2010-05-19 20:10:52 +02:00
fi
done
}
# lists default linux partitionable raid devices
partitionable_raid_devices() {
2013-07-20 08:54:10 +02:00
for dev in $(${_LSBLK} NAME,TYPE | grep " raid.*$" | cut -d' ' -f 1 | grep "_d.*$" | sort -u); do
echo "${dev}"
[[ "${1}" ]] && echo ${1}
2010-05-19 07:43:36 +02:00
done
}
# lists linux partitionable raid devices partitions
2010-05-19 07:43:36 +02:00
partitionable_raid_devices_partitions() {
2013-07-20 08:54:10 +02:00
for part in $(${_LSBLK} NAME,TYPE | grep "md$" | cut -d' ' -f 1 | sort -u) ; do
# exclude checks:
# - part of lvm2 device_found
# ${_LSBLK} FSTYPE ${part} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS")
# - extended partition
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")
# - extended partition (LBA)
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")")
# - part of isw fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member")
2013-08-21 09:09:10 +02:00
# - part of ddf fakeraid
# $(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")
if ! [[ "$(${_LSBLK} FSTYPE ${part} | grep "LVM2_member")" || "$(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")" || $(${_LSBLK} FSTYPE ${dev} -s | grep "isw_raid_member") || "$(${_LSBLK} FSTYPE ${dev} -s | grep "ddf_raid_member")" ]]; then
echo "${part}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# lists dmraid devices
dmraid_devices() {
for dev in $(${_LSBLK} NAME,TYPE | grep "dmraid$" | cut -d' ' -f 1 | grep -v "_.*p.*$" | sort -u); do
echo "${dev}"
[[ "${1}" ]] && echo ${1}
done
# isw_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " raid.*$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "isw_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
2013-08-21 09:09:10 +02:00
# ddf_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " raid.*$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "ddf_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# dmraid_partitions
# - show dmraid partitions
dmraid_partitions() {
for part in $(${_LSBLK} NAME,TYPE | grep "dmraid$" | cut -d' ' -f 1 | grep "_.*p.*$" | sort -u); do
# exclude checks:
# - part of lvm2 device
# ${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")
# - part of raid device
# $(${_LSBLK} FSTYPE ${dev} | grep "linux_raid_member$")
# - extended partition
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")
# - extended partition (LBA)
# $(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")
if ! [[ "$(${_LSBLK} FSTYPE ${part} | grep "crypto_LUKS$")" || "$(${_LSBLK} FSTYPE ${part} | grep "LVM2_member$")" || "$(${_LSBLK} FSTYPE ${part} | grep "linux_raid_member$")" || "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "Extended$")"|| "$(sfdisk -l 2>/dev/null | grep "${part}" | grep "(LBA)$")" ]]; then
echo "${part}"
[[ "${1}" ]] && echo ${1}
fi
2010-05-19 20:10:52 +02:00
done
# isw_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " md$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "isw_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
2013-08-21 09:09:10 +02:00
# ddf_raid_member, managed by mdadm
for dev in $(${_LSBLK} NAME,TYPE ${i} | grep " md$" | cut -d' ' -f 1 | sort -u); do
if [[ "$(${_LSBLK} NAME,FSTYPE -s | grep "ddf_raid_member$" | cut -d' ' -f 1)" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
# dm_devices
2013-07-20 08:30:33 +02:00
# - show device mapper devices:
# lvm2 and cryptdevices
dm_devices() {
2013-07-20 08:30:33 +02:00
for dev in $(${_LSBLK} NAME,TYPE | grep -e "lvm$" -e "crypt$" | cut -d' ' -f1 | sort -u); do
# exclude checks:
# - part of lvm2 device
# ${_LSBLK} FSTYPE ${dev} | grep "LVM2_member")
# - part of luks device
# $(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS")
# - part of raid device
# $(${_LSBLK} FSTYPE ${dev} | grep "linux_raid_member$")
2013-07-22 12:42:50 +02:00
# - part of running raid on encrypted device
# $(${_LSBLK} TYPE ${dev} | grep "raid.*$
2013-07-22 12:42:50 +02:00
if ! [[ "$(${_LSBLK} FSTYPE ${dev} | grep "crypto_LUKS$")" || "$(${_LSBLK} FSTYPE ${dev} | grep "LVM2_member$")" || "$(${_LSBLK} FSTYPE ${dev} | grep "linux_raid_member$")" || "$(${_LSBLK} TYPE ${dev} | grep "raid.*$")" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
2008-10-20 22:39:25 +02:00
}
finddisks() {
blockdevices ${1}
2011-02-04 14:34:11 +01:00
dmraid_devices ${1}
partitionable_raid_devices ${1}
}
findpartitions() {
blockdevices_partitions ${1}
2011-02-04 14:34:11 +01:00
dm_devices ${1}
dmraid_partitions ${1}
raid_devices ${1}
partitionable_raid_devices_partitions ${1}
2008-10-20 22:39:25 +02:00
}
2009-06-28 22:40:06 +02:00
# don't check on raid devices!
findbootloaderdisks() {
2011-02-04 14:34:11 +01:00
if ! [[ "${USE_DMRAID}" = "1" ]]; then
blockdevices ${1}
2009-06-28 22:40:06 +02:00
else
2011-02-04 14:34:11 +01:00
dmraid_devices ${1}
fi
2009-06-28 22:40:06 +02:00
}
# don't list raid devices, lvm2 and devicemapper!
findbootloaderpartitions() {
2011-02-04 14:34:11 +01:00
if ! [[ "${USE_DMRAID}" = "1" ]]; then
blockdevices_partitions ${1}
2009-06-28 22:40:06 +02:00
else
2011-02-04 14:34:11 +01:00
dmraid_partitions ${1}
2009-06-22 09:19:44 +02:00
fi
2009-01-28 22:43:20 +01:00
}
# find any gpt/guid formatted disks
find_gpt() {
GUID_DETECTED=""
for i in $(finddisks); do
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${i})" == "gpt" ]] && GUID_DETECTED="1"
done
}
2012-06-25 11:34:07 +02:00
# freeze and unfreeze xfs, as hack for grub(2) installing
2010-03-14 17:03:56 +01:00
freeze_xfs() {
sync
2013-05-21 12:38:07 +02:00
if [[ -x /usr/bin/xfs_freeze ]]; then
2011-02-04 14:34:11 +01:00
if [[ "$(cat /proc/mounts | grep "${DESTDIR}/boot " | grep " xfs ")" ]]; then
2013-05-21 12:38:07 +02:00
xfs_freeze -f ${DESTDIR}/boot >/dev/null 2>&1
xfs_freeze -u ${DESTDIR}/boot >/dev/null 2>&1
fi
2011-02-04 14:34:11 +01:00
if [[ "$(cat /proc/mounts | grep "${DESTDIR} " | grep " xfs ")" ]]; then
2013-05-21 12:38:07 +02:00
xfs_freeze -f ${DESTDIR} >/dev/null 2>&1
xfs_freeze -u ${DESTDIR} >/dev/null 2>&1
2010-03-14 17:03:56 +01:00
fi
fi
2010-03-14 17:03:56 +01:00
}
2008-10-20 22:39:25 +02:00
mapdev() {
partition_flag=0
device_found=0
# check if we use sd or vd device
2013-07-17 21:08:15 +02:00
if ! [[ "$(echo ${1} | grep /dev/sd)" || "$(echo ${1} | grep /dev/vd)" ]]; then
2011-02-04 14:34:11 +01:00
linuxdevice=$(echo ${1} | sed -e 's#p[0-9].*$##')
2009-06-28 22:40:06 +02:00
else
2011-02-04 14:34:11 +01:00
linuxdevice=$(echo ${1} | sed -e 's#[0-9].*$##g')
2009-06-28 22:40:06 +02:00
fi
2013-07-17 21:08:15 +02:00
if ! [[ "$(echo ${1} | grep /dev/sd)" || "$(echo ${1} | grep /dev/vd)" ]]; then
2011-02-04 14:34:11 +01:00
if [[ "$(echo ${1} | egrep 'p[0-9].*$')" ]]; then
pnum=$(echo ${1} | sed -e 's#.*p##g')
2009-06-28 22:40:06 +02:00
partition_flag=1
fi
else
2011-02-04 14:34:11 +01:00
if [[ "$(echo ${1} | egrep '[0-9]$')" ]]; then
2013-07-17 21:08:15 +02:00
# /dev/sdX and /dev/vdX
2011-02-04 14:34:11 +01:00
pnum=$(echo ${1} | cut -b9-)
2009-06-28 22:40:06 +02:00
partition_flag=1
fi
fi
2011-02-04 14:34:11 +01:00
for dev in ${devs}; do
if [[ "(" = $(echo ${dev} | cut -b1) ]]; then
grubdevice="${dev}"
else
2011-02-04 14:34:11 +01:00
if [[ "${dev}" = "${linuxdevice}" ]]; then
2009-06-28 22:40:06 +02:00
device_found=1
break
fi
fi
2009-02-11 12:03:41 +01:00
done
2011-02-04 14:34:11 +01:00
if [[ "${device_found}" = "1" ]]; then
if [[ "${partition_flag}" = "0" ]]; then
echo "${grubdevice}"
else
grubdevice_stringlen=${#grubdevice}
2011-02-04 14:34:11 +01:00
grubdevice_stringlen=$((${grubdevice_stringlen} - 1))
grubdevice=$(echo ${grubdevice} | cut -b1-${grubdevice_stringlen})
echo "${grubdevice},${pnum})"
fi
else
echo "DEVICE NOT FOUND"
fi
2008-10-20 22:39:25 +02:00
}
printk()
{
2011-02-04 14:34:11 +01:00
case ${1} in
"on") echo 4 >/proc/sys/kernel/printk ;;
"off") echo 0 >/proc/sys/kernel/printk ;;
esac
2008-10-20 22:39:25 +02:00
}
getdest() {
2011-02-04 14:34:11 +01:00
[[ "${DESTDIR}" ]] && return 0
DIALOG --inputbox "Enter the destination directory where your target system is mounted" 8 65 "${DESTDIR}" 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
DESTDIR=$(cat ${ANSWER})
2008-10-20 22:39:25 +02:00
}
# geteditor()
# prompts the user to choose an editor
# sets EDITOR global variable
#
2008-10-20 22:39:25 +02:00
geteditor() {
2011-02-04 14:34:11 +01:00
if ! [[ "${EDITOR}" ]]; then
DIALOG --menu "Select a Text Editor to Use" 10 35 3 \
"1" "nano (easier)" \
2011-02-04 14:34:11 +01:00
"2" "vi" 2>${ANSWER} || return 1
case $(cat ${ANSWER}) in
"1") EDITOR="nano" ;;
"2") EDITOR="vi" ;;
esac
fi
2008-10-20 22:39:25 +02:00
}
2010-05-24 15:39:55 +02:00
# set device name scheme
set_device_name_scheme() {
NAME_SCHEME_PARAMETER=""
2012-08-30 15:46:45 +02:00
NAME_SCHEME_LEVELS=""
MENU_DESC_TEXT=""
2012-09-07 14:47:55 +02:00
# check if gpt/guid formatted disks are there
find_gpt
2012-08-30 15:46:45 +02:00
## util-linux root=PARTUUID=/root=PARTLABEL= support - https://git.kernel.org/?p=utils/util-linux/util-linux.git;a=commitdiff;h=fc387ee14c6b8672761ae5e67ff639b5cae8f27c;hp=21d1fa53f16560dacba33fffb14ffc05d275c926
## mkinitcpio's init root=PARTUUID= support - https://projects.archlinux.org/mkinitcpio.git/tree/init_functions#n185
if [[ "${GUID_DETECTED}" == "1" ]]; then
NAME_SCHEME_LEVELS="${NAME_SCHEME_LEVELS} PARTUUID PARTUUID=<partuuid> PARTLABEL PARTLABEL=<partlabel>"
MENU_DESC_TEXT="\nPARTUUID and PARTLABEL are specific to GPT disks.\nIn GPT disks, PARTUUID is recommended.\nIn MBR/msdos disks,"
2012-08-30 15:46:45 +02:00
fi
NAME_SCHEME_LEVELS="${NAME_SCHEME_LEVELS} FSUUID UUID=<uuid> FSLABEL LABEL=<label> KERNEL /dev/<kernelname>"
DIALOG --menu "Select the device name scheme you want to use in config files. ${MENU_DESC_TEXT} FSUUID is recommended." 15 70 9 ${NAME_SCHEME_LEVELS} 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
NAME_SCHEME_PARAMETER=$(cat ${ANSWER})
2010-05-24 15:39:55 +02:00
NAME_SCHEME_PARAMETER_RUN="1"
2010-03-14 22:51:57 +01:00
}
2010-03-15 07:14:28 +01:00
# set GUID (gpt) usage
2010-08-27 21:48:37 +02:00
set_guid() {
2010-03-15 07:14:28 +01:00
GUIDPARAMETER=""
2022-01-05 15:00:21 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
GUIDPARAMETER="yes"
else
## Lenovo BIOS-GPT issues - Arch Forum - https://bbs.archlinux.org/viewtopic.php?id=131149 , https://bbs.archlinux.org/viewtopic.php?id=133330 , https://bbs.archlinux.org/viewtopic.php?id=138958
## Lenovo BIOS-GPT issues - in Fedora - https://bugzilla.redhat.com/show_bug.cgi?id=735733, https://bugzilla.redhat.com/show_bug.cgi?id=749325 , http://git.fedorahosted.org/git/?p=anaconda.git;a=commit;h=ae74cebff312327ce2d9b5ac3be5dbe22e791f09
DIALOG --yesno "Do you want to use GUID Partition Table (GPT)?\n\nIt is a standard for the layout of the partition table on a physical storage disk. Although it forms a part of the Unified Extensible Firmware Interface (UEFI) standard, it is also used on some BIOS systems because of the limitations of MBR aka msdos partition tables, which restrict maximum disk size to 2 TiB.\n\nWindows 10 and later versions include the capability to use GPT for non-boot aka data disks (only UEFI systems can boot Windows 10 and later from GPT disks).\n\nAttention:\n- Please check if your other operating systems have GPT support!\n- Use this option for a GRUB(2) setup, which should support LVM, RAID\n etc., which doesn't fit into the usual 30k MS-DOS post-MBR gap.\n- BIOS-GPT boot may not work in some Lenovo systems (irrespective of the\n bootloader used). " 0 0 && GUIDPARAMETER="yes"
fi
2010-03-15 07:14:28 +01:00
}
# Get a list of available disks for use in the "Available disks" dialogs.
# This will print the mountpoints as follows, getting size info from lsblk:
# /dev/sda 64G
_getavaildisks()
{
for i in $(finddisks); do
${_LSBLK} NAME,SIZE -d ${i}
done
2009-02-01 23:01:19 +01:00
}
# Get a list of available partitions for use in the "Available Mountpoints" dialogs.
# This will print the mountpoints as follows, getting size info from lsblk:
# /dev/sda1 640M
2009-02-01 23:01:19 +01:00
_getavailpartitions()
{
for i in $(findpartitions); do
${_LSBLK} NAME,SIZE -d ${i}
done
}
# Disable swap and all mounted partitions for the destination system. Unmount
# the destination root partition last!
_umountall()
{
DIALOG --infobox "Disabling swapspace, unmounting already mounted disk devices..." 0 0
swapoff -a >/dev/null 2>&1
for i in $(findmnt --list --submounts ${DESTDIR} -o TARGET -n | tac); do
umount $i
done
}
# Disable all software raid devices
2009-02-01 23:01:19 +01:00
_stopmd()
{
2011-02-03 21:54:43 +01:00
if [[ "$(cat /proc/mdstat 2>/dev/null | grep ^md)" ]]; then
2009-03-28 13:36:54 +01:00
DISABLEMD=""
DIALOG --defaultno --yesno "Setup detected already running raid devices, do you want to disable them completely?" 0 0 && DISABLEMD="1"
2011-02-04 14:34:11 +01:00
if [[ "${DISABLEMD}" = "1" ]]; then
2009-03-28 13:36:54 +01:00
DIALOG --infobox "Disabling all software raid devices..." 0 0
2009-03-28 16:06:28 +01:00
for i in $(cat /proc/mdstat 2>/dev/null | grep ^md | sed -e 's# :.*##g'); do
2011-02-04 14:34:11 +01:00
mdadm --manage --stop /dev/${i} > ${LOG}
2009-03-28 13:36:54 +01:00
done
2009-07-02 22:29:46 +02:00
DIALOG --infobox "Cleaning superblocks of all software raid devices..." 0 0
for i in $(${_LSBLK} NAME,FSTYPE | grep "linux_raid_member$" | cut -d' ' -f 1); do
2011-02-04 14:34:11 +01:00
mdadm --zero-superblock ${i} > ${LOG}
2009-07-02 22:29:46 +02:00
done
2009-03-28 13:36:54 +01:00
fi
fi
DISABLEMDSB=""
if [[ "$(${_LSBLK} FSTYPE | grep "linux_raid_member")" ]]; then
DIALOG --defaultno --yesno "Setup detected superblock of raid devices, do you want to clean the superblock of them?" 0 0 && DISABLEMDSB="1"
2011-02-04 14:34:11 +01:00
if [[ "${DISABLEMDSB}" = "1" ]]; then
DIALOG --infobox "Cleaning superblocks of all software raid devices..." 0 0
for i in $(${_LSBLK} NAME,FSTYPE | grep "linux_raid_member$" | cut -d' ' -f 1); do
2011-02-04 14:34:11 +01:00
mdadm --zero-superblock ${i} > ${LOG}
done
fi
fi
}
# Disable all lvm devices
_stoplvm()
{
DISABLELVM=""
DETECTED_LVM=""
2010-08-27 21:48:37 +02:00
LV_VOLUMES="$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)"
LV_GROUPS="$(vgs -o vg_name --noheading 2>/dev/null)"
LV_PHYSICAL="$(pvs -o pv_name --noheading 2>/dev/null)"
2011-02-04 14:34:11 +01:00
! [[ "${LV_VOLUMES}" = "" ]] && DETECTED_LVM=1
! [[ "${LV_GROUPS}" = "" ]] && DETECTED_LVM=1
! [[ "${LV_PHYSICAL}" = "" ]] && DETECTED_LVM=1
if [[ "${DETECTED_LVM}" = "1" ]]; then
DIALOG --defaultno --yesno "Setup detected lvm volumes, volume groups or physical devices, do you want to remove them completely?" 0 0 && DISABLELVM="1"
fi
2011-02-04 14:34:11 +01:00
if [[ "${DISABLELVM}" = "1" ]]; then
DIALOG --infobox "Removing logical volumes ..." 0 0
2011-02-04 14:34:11 +01:00
for i in ${LV_VOLUMES}; do
lvremove -f /dev/mapper/${i} 2>/dev/null> ${LOG}
done
DIALOG --infobox "Removing logical groups ..." 0 0
2011-02-04 14:34:11 +01:00
for i in ${LV_GROUPS}; do
vgremove -f ${i} 2>/dev/null > ${LOG}
done
DIALOG --infobox "Removing physical volumes ..." 0 0
2011-02-04 14:34:11 +01:00
for i in ${LV_PHYSICAL}; do
pvremove -f ${i} 2>/dev/null > ${LOG}
done
fi
}
2009-04-17 22:29:31 +02:00
# Disable all luks encrypted devices
_stopluks()
{
DISABLELUKS=""
DETECTED_LUKS=""
LUKSDEVICE=""
2011-02-06 20:14:39 +01:00
# detect already running luks devices
2013-07-24 20:38:59 +02:00
LUKSDEVICE="$(${_LSBLK} NAME,TYPE | grep " crypt$" | cut -d' ' -f1)"
2011-02-04 14:34:11 +01:00
! [[ "${LUKSDEVICE}" = "" ]] && DETECTED_LUKS=1
if [[ "${DETECTED_LUKS}" = "1" ]]; then
2011-02-06 20:14:39 +01:00
DIALOG --defaultno --yesno "Setup detected running luks encrypted devices, do you want to remove them completely?" 0 0 && DISABLELUKS="1"
2009-04-17 22:29:31 +02:00
fi
2011-02-04 14:34:11 +01:00
if [[ "${DISABLELUKS}" = "1" ]]; then
2009-04-17 22:29:31 +02:00
DIALOG --infobox "Removing luks encrypted devices ..." 0 0
2011-02-04 14:34:11 +01:00
for i in ${LUKSDEVICE}; do
2013-07-24 20:38:59 +02:00
LUKS_REAL_DEVICE="$(${_LSBLK} NAME,FSTYPE -s "${LUKSDEVICE}" | grep " crypto_LUKS$" | cut -d' ' -f1)"
2011-02-04 14:34:11 +01:00
cryptsetup remove ${i} > ${LOG}
2009-04-17 22:29:31 +02:00
# delete header from device
2013-07-24 20:38:59 +02:00
wipefs -a ${LUKS_REAL_DEVICE} >/dev/null 2>&1
2011-02-06 20:14:39 +01:00
done
fi
DISABLELUKS=""
DETECTED_LUKS=""
# detect not running luks devices
[[ "$(${_LSBLK} FSTYPE | grep "crypto_LUKS")" ]] && DETECTED_LUKS=1
2011-02-06 20:14:39 +01:00
if [[ "${DETECTED_LUKS}" = "1" ]]; then
DIALOG --defaultno --yesno "Setup detected not running luks encrypted devices, do you want to remove them completely?" 0 0 && DISABLELUKS="1"
fi
if [[ "${DISABLELUKS}" = "1" ]]; then
DIALOG --infobox "Removing not running luks encrypted devices ..." 0 0
2013-07-24 20:38:59 +02:00
for i in $(${_LSBLK} NAME,FSTYPE | grep "crypto_LUKS$" | cut -d' ' -f1); do
# delete header from device
wipefs -a ${i} >/dev/null 2>&1
2009-04-17 22:29:31 +02:00
done
fi
2011-02-03 21:54:43 +01:00
[[ -e /tmp/.crypttab ]] && rm /tmp/.crypttab
2009-04-17 22:29:31 +02:00
}
2009-06-26 10:33:54 +02:00
#_dmraid_update
_dmraid_update()
{
2013-07-20 08:30:33 +02:00
printk off
2009-06-26 10:33:54 +02:00
DIALOG --infobox "Deactivating dmraid devices ..." 0 0
2009-07-12 19:15:34 +02:00
dmraid -an >/dev/null 2>&1
2011-02-04 14:34:11 +01:00
if [[ "${DETECTED_LVM}" = "1" || "${DETECTED_LUKS}" = "1" ]]; then
DIALOG --defaultno --yesno "Setup detected running dmraid devices and/or running lvm2, luks encrypted devices. If you reduced/deleted partitions on your dmraid device a complete reset of devicemapper devices is needed. This will reset also your created lvm2 or encrypted devices. Are you sure you want to do this?" 0 0 && RESETDM="1"
2011-02-04 14:34:11 +01:00
if [[ "${RESETDM}" = "1" ]]; then
2009-06-26 10:33:54 +02:00
DIALOG --infobox "Resetting devicemapper devices ..." 0 0
dmsetup remove_all >/dev/null 2>&1
fi
2009-06-26 10:33:54 +02:00
else
DIALOG --infobox "Resetting devicemapper devices ..." 0 0
dmsetup remove_all >/dev/null 2>&1
2009-06-26 10:33:54 +02:00
fi
DIALOG --infobox "Reactivating dmraid devices ..." 0 0
dmraid -ay -I -Z >/dev/null 2>&1
2013-07-20 08:30:33 +02:00
printk on
2009-06-26 10:33:54 +02:00
}
#helpbox for raid
_helpraid()
{
2009-02-13 19:01:00 +01:00
DIALOG --msgbox "LINUX SOFTWARE RAID SUMMARY:\n
2009-02-14 18:51:13 +01:00
-----------------------------\n\n
2009-02-13 19:01:00 +01:00
Linear mode:\n
You have two or more partitions which are not necessarily the same size\n
(but of course can be), which you want to append to each other.\n
Spare-disks are not supported here. If a disk dies, the array dies with\n
it.\n\n
RAID-0:\n
You have two or more devices, of approximately the same size, and you want\n
to combine their storage capacity and also combine their performance by\n
accessing them in parallel. Like in Linear mode, spare disks are not\n
supported here either. RAID-0 has no redundancy, so when a disk dies, the\n
array goes with it.\n\n
RAID-1:\n
You have two devices of approximately same size, and you want the two to\n
be mirrors of each other. Eventually you have more devices, which you\n
want to keep as stand-by spare-disks, that will automatically become a\n
part of the mirror if one of the active devices break.\n\n
2010-03-14 10:15:47 +01:00
RAID-4:\n
You have three or more devices of roughly the same size and you want\n
a way that protects data against loss of any one disk.\n
Fault tolerance is achieved by adding an extra disk to the array, which\n
is dedicated to storing parity information. The overall capacity of the\n
array is reduced by one disk.\n
The storage efficiency is 66 percent. With six drives, the storage\n
efficiency is 87 percent. The main disadvantage is poor performance for\n
multiple,\ simultaneous, and independent read/write operations.\n
Thus, if any disk fails, all data stay intact. But if two disks fail,\n
all data is lost.\n\n
2009-02-13 19:01:00 +01:00
RAID-5:\n
You have three or more devices of roughly the same size, you want to\n
combine them into a larger device, but still to maintain a degree of\n
redundancy fordata safety. Eventually you have a number of devices to use\n
as spare-disks, that will not take part in the array before another device\n
fails. If you use N devices where the smallest has size S, the size of the\n
entire array will be (N-1)*S. This \"missing\" space is used for parity\n
(redundancy) information. Thus, if any disk fails, all data stay intact.\n
But if two disks fail, all data is lost.\n\n
2010-03-14 10:15:47 +01:00
RAID-6:\n
You have four or more devices of roughly the same size and you want\n
a way that protects data against loss of any two disks.\n
Fault tolerance is achieved by adding an two extra disk to the array,\n
which is dedicated to storing parity information. The overall capacity\n
of the array is reduced by 2 disks.\n
2010-03-14 10:15:47 +01:00
Thus, if any two disks fail, all data stay intact. But if 3 disks fail,\n
all data is lost.\n\n
2009-02-13 19:01:00 +01:00
RAID-10:\n
Shorthand for RAID1+0, a mirrored striped array and needs a minimum of\n
two disks. It provides superior data security and can survive multiple\n
disk failures. The main disadvantage is cost, because 50% of your\n
storage is duplication." 0 0
}
# Create raid or raid_partition
_raid()
{
MDFINISH=""
2011-02-04 14:34:11 +01:00
while [[ "${MDFINISH}" != "DONE" ]]; do
2010-05-18 23:52:30 +02:00
activate_special_devices
: >/tmp/.raid
: >/tmp/.raid-spare
# check for devices
# Remove all raid devices with children
RAID_BLACKLIST="$(for i in $(${_LSBLK} NAME,TYPE | grep " raid.*$" | cut -d' ' -f1 | sort -u); do
echo $(${_LSBLK} NAME ${i}) _
done)"
PARTS="$(for i in $(findpartitions); do
! [[ "$(echo "${RAID_BLACKLIST}" | egrep "${i} _")" ]] && echo $i _
done)"
2009-02-14 18:51:13 +01:00
# break if all devices are in use
2011-02-04 14:34:11 +01:00
if [[ "${PARTS}" = "" ]]; then
2009-02-14 18:51:13 +01:00
DIALOG --msgbox "All devices in use. No more devices left for new creation." 0 0
return 1
fi
# enter raid device name
RAIDDEVICE=""
2011-02-04 14:34:11 +01:00
while [[ "${RAIDDEVICE}" = "" ]]; do
if [[ "${RAID_PARTITION}" = "" ]]; then
DIALOG --inputbox "Enter the node name for the raiddevice:\n/dev/md[number]\n/dev/md0\n/dev/md1\n\n" 15 65 "/dev/md0" 2>${ANSWER} || return 1
2010-03-18 22:46:21 +01:00
fi
2011-02-04 14:34:11 +01:00
if [[ "${RAID_PARTITION}" = "1" ]]; then
DIALOG --inputbox "Enter the node name for partitionable raiddevice:\n/dev/md_d[number]\n/dev/md_d0\n/dev/md_d1" 15 65 "/dev/md_d0" 2>${ANSWER} || return 1
2010-03-18 22:46:21 +01:00
fi
2011-02-04 14:34:11 +01:00
RAIDDEVICE=$(cat ${ANSWER})
if [[ "$(cat /proc/mdstat 2>/dev/null | grep "^$(echo ${RAIDDEVICE} | sed -e 's#/dev/##g')")" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical node names! Please enter another name." 8 65
RAIDDEVICE=""
fi
done
2010-03-14 10:15:47 +01:00
RAIDLEVELS="linear - raid0 - raid1 - raid4 - raid5 - raid6 - raid10 -"
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select the raid level you want to use" 21 50 11 ${RAIDLEVELS} 2>${ANSWER} || return 1
LEVEL=$(cat ${ANSWER})
# raid5 and raid10 support parity parameter
PARITY=""
2011-02-04 14:34:11 +01:00
if [[ "${LEVEL}" = "raid5" || "${LEVEL}" = "raid6" || "${LEVEL}" = "raid10" ]]; then
PARITYLEVELS="left-asymmetric - left-symmetric - right-asymmetric - right-symmetric -"
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select the parity layout you want to use (default is left-symmetric)" 21 50 13 ${PARITYLEVELS} 2>${ANSWER} || return 1
PARTIY=$(cat ${ANSWER})
fi
# show all devices with sizes
DIALOG --cr-wrap --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)" 0 0
# select the first device to use, no missing option available!
RAIDNUMBER=1
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select device ${RAIDNUMBER}" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
echo "${PART}" >>/tmp/.raid
while [[ "${PART}" != "DONE" ]]; do
RAIDNUMBER=$((${RAIDNUMBER} + 1))
# clean loop from used partition and options
2011-02-04 14:34:11 +01:00
PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g" -e 's#MISSING\ _##g' -e 's#SPARE\ _##g')"
# raid0 doesn't support missing devices
2011-02-04 14:34:11 +01:00
! [[ "${LEVEL}" = "raid0" || "${LEVEL}" = "linear" ]] && MDEXTRA="MISSING _"
# add more devices
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select additional device ${RAIDNUMBER}" 21 50 13 ${PARTS} ${MDEXTRA} DONE _ 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
SPARE=""
2011-02-04 14:34:11 +01:00
! [[ "${LEVEL}" = "raid0" || "${LEVEL}" = "linear" ]] && DIALOG --yesno --defaultno "Would you like to use ${PART} as spare device?" 0 0 && SPARE="1"
[[ "${PART}" = "DONE" ]] && break
if [[ "${PART}" = "MISSING" ]]; then
DIALOG --yesno "Would you like to create a degraded raid on ${RAIDDEVICE}?" 0 0 && DEGRADED="missing"
echo "${DEGRADED}" >>/tmp/.raid
else
2011-02-04 14:34:11 +01:00
if [[ "${SPARE}" = "1" ]]; then
echo "${PART}" >>/tmp/.raid-spare
else
2011-02-04 14:34:11 +01:00
echo "${PART}" >>/tmp/.raid
fi
fi
done
# final step ask if everything is ok?
2012-04-22 19:29:38 +02:00
DIALOG --yesno "Would you like to create ${RAIDDEVICE} like this?\n\nLEVEL:\n${LEVEL}\n\nDEVICES:\n$(for i in $(cat /tmp/.raid); do echo "${i}\n";done)\nSPARES:\n$(for i in $(cat /tmp/.raid-spare); do echo "${i}\n";done)" 0 0 && MDFINISH="DONE"
done
_createraid
}
# create raid device
_createraid()
{
2009-02-13 19:01:00 +01:00
DEVICES="$(echo -n $(cat /tmp/.raid))"
SPARES="$(echo -n $(cat /tmp/.raid-spare))"
# combine both if spares are available, spares at the end!
2011-02-04 14:34:11 +01:00
[[ -n ${SPARES} ]] && DEVICES="${DEVICES} ${SPARES}"
2009-02-13 19:01:00 +01:00
# get number of devices
RAID_DEVICES="$(cat /tmp/.raid | wc -l)"
SPARE_DEVICES="$(cat /tmp/.raid-spare | wc -l)"
2009-02-13 19:01:00 +01:00
# generate options for mdadm
2012-04-22 19:30:41 +02:00
RAIDOPTIONS="--force --run --level=${LEVEL}"
2011-02-04 14:34:11 +01:00
[[ "$(echo ${RAIDDEVICE} | grep /md_d[0-9])" ]] && RAIDOPTIONS="${RAIDOPTIONS} -a mdp"
! [[ "${RAID_DEVICES}" = "0" ]] && RAIDOPTIONS="${RAIDOPTIONS} --raid-devices=${RAID_DEVICES}"
! [[ "${SPARE_DEVICES}" = "0" ]] && RAIDOPTIONS="${RAIDOPTIONS} --spare-devices=${SPARE_DEVICES}"
! [[ "${PARITY}" = "" ]] && RAIDOPTIONS="${RAIDOPTIONS} --layout=${PARITY}"
DIALOG --infobox "Creating ${RAIDDEVICE}..." 0 0
mdadm --create ${RAIDDEVICE} ${RAIDOPTIONS} ${DEVICES} >${LOG} 2>&1
2011-02-03 21:54:43 +01:00
if [[ $? -gt 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error creating ${RAIDDEVICE} (see ${LOG} for details)." 0 0
2009-02-13 19:01:00 +01:00
return 1
fi
2011-02-04 14:34:11 +01:00
if [[ "$(echo ${RAIDDEVICE} | grep /md_d[0-9])" ]]; then
2010-03-18 22:46:21 +01:00
# switch for mbr usage
set_guid
2011-02-04 14:34:11 +01:00
if [[ "${GUIDPARAMETER}" = "" ]]; then
DIALOG --msgbox "Now you'll be put into the parted program where you can partition your raiddevice to your needs." 18 70
parted -a optimal -s ${RAIDDEVICE} mktable msdos
clear
2011-02-04 14:34:11 +01:00
parted ${RAIDDEVICE} print
parted ${RAIDDEVICE}
2010-03-18 22:46:21 +01:00
else
2011-02-04 14:34:11 +01:00
DISC=${RAIDDEVICE}
RUN_CFDISK="1"
2012-06-25 11:34:07 +02:00
CHECK_BIOS_BOOT_GRUB=""
2012-04-24 18:50:27 +02:00
CHECK_UEFISYS_PART=""
2011-09-12 21:38:58 +02:00
check_gpt
2010-03-18 22:46:21 +01:00
fi
2009-02-14 18:51:13 +01:00
fi
}
# help for lvm
_helplvm()
{
DIALOG --msgbox "LOGICAL VOLUME SUMMARY:\n
-----------------------------\n\n
LVM is a Logical Volume Manager for the Linux kernel. With LVM you can\n
abstract your storage space and have \"virtual partitions\" which are easier\n
2009-04-17 22:29:31 +02:00
to modify.\n\nThe basic building block of LVM are:\n
- Physical volume (PV):\n
2012-10-08 09:14:16 +02:00
Partition on storage disk (or even storage disk itself or loopback file) on\n
2009-04-17 22:29:31 +02:00
which you can have virtual groups. It has a special header and is\n
divided into physical extents. Think of physical volumes as big building\n
2012-10-08 09:14:16 +02:00
blocks which can be used to build your storage drive.\n
2009-04-17 22:29:31 +02:00
- Volume group (VG):\n
Group of physical volumes that are used as storage volume (as one disk).\n
2012-10-08 09:14:16 +02:00
They contain logical volumes. Think of volume groups as storage drives.\n
2009-04-17 22:29:31 +02:00
- Logical volume(LV):\n
A \"virtual/logical partition\" that resides in a volume group and is\n
composed of physical extents. Think of logical volumes as normal\n
partitions." 0 0
}
# Creates physical volume
_createpv()
{
PVFINISH=""
2011-02-04 14:34:11 +01:00
while [[ "${PVFINISH}" != "DONE" ]]; do
2010-05-18 23:52:30 +02:00
activate_special_devices
: >/tmp/.pvs-create
2013-07-22 20:53:30 +02:00
# Remove all lvm devices with children
LVM_BLACKLIST="$(for i in $(${_LSBLK} NAME,TYPE | grep " lvm$" | cut -d' ' -f1 | sort -u); do
echo $(${_LSBLK} NAME ${i}) _
done)"
PARTS="$(for i in $(findpartitions); do
! [[ "$(echo "${LVM_BLACKLIST}" | egrep "${i} _")" ]] && echo $i _
done)"
# break if all devices are in use
2011-02-04 14:34:11 +01:00
if [[ "${PARTS}" = "" ]]; then
DIALOG --msgbox "No devices left for physical volume creation." 0 0
return 1
fi
# show all devices with sizes
DIALOG --cr-wrap --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)\n\n" 0 0
# select the first device to use
DEVNUMBER=1
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select device number ${DEVNUMBER} for physical volume" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
echo "${PART}" >>/tmp/.pvs-create
while [[ "${PART}" != "DONE" ]]; do
DEVNUMBER=$((${DEVNUMBER} + 1))
# clean loop from used partition and options
2011-02-04 14:34:11 +01:00
PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
# add more devices
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select additional device number ${DEVNUMBER} for physical volume" 21 50 13 ${PARTS} DONE _ 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
[[ "${PART}" = "DONE" ]] && break
echo "${PART}" >>/tmp/.pvs-create
done
# final step ask if everything is ok?
DIALOG --yesno "Would you like to create physical volume on devices below?\n$(cat /tmp/.pvs-create | sed -e 's#$#\\n#g')" 0 0 && PVFINISH="DONE"
done
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Creating physical volume on ${PART}..." 0 0
PART="$(echo -n $(cat /tmp/.pvs-create))"
2011-02-04 14:34:11 +01:00
pvcreate ${PART} >${LOG} 2>&1
2011-02-03 21:54:43 +01:00
if [[ $? -gt 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error creating physical volume on ${PART} (see ${LOG} for details)." 0 0
return 1
fi
2013-07-25 09:15:08 +02:00
# run udevadm to get values exported
udevadm trigger
udevadm settle
}
2009-04-11 19:01:22 +02:00
#find physical volumes that are not in use
findpv()
{
for i in $(${_LSBLK} NAME,FSTYPE | grep " LVM2_member$" | cut -d' ' -f1 | sort -u); do
2013-07-25 09:15:08 +02:00
# exclude checks:
#- not part of running lvm2
# ! "$(${_LSBLK} TYPE ${i} | grep "lvm")"
#- not part of volume group
# $(pvs -o vg_name --noheading ${i} | grep " $")
if [[ ! "$(${_LSBLK} TYPE ${i} | grep "lvm")" && $(pvs -o vg_name --noheading ${i} | grep " $") ]]; then
echo "${i}"
[[ "${1}" ]] && echo ${1}
fi
done
2009-04-11 19:01:22 +02:00
}
getavailablepv()
{
for i in $(${_LSBLK} NAME,FSTYPE | grep " LVM2_member$" | cut -d' ' -f1 | sort -u); do
2013-07-25 09:30:31 +02:00
# exclude checks:
#- not part of running lvm2
# ! "$(${_LSBLK} TYPE ${i} | grep "lvm")"
#- not part of volume group
# $(pvs -o vg_name --noheading ${i} | grep " $")
if [[ ! "$(${_LSBLK} TYPE ${i} | grep "lvm")" && $(pvs -o vg_name --noheading ${i} | grep " $") ]]; then
echo "$(${_LSBLK} NAME,SIZE ${i})"
fi
done
2009-04-11 19:01:22 +02:00
}
#find volume groups that are not already full in use
findvg()
{
for dev in $(vgs -o vg_name --noheading);do
2011-02-04 14:34:11 +01:00
if ! [[ "$(vgs -o vg_free --noheading --units m ${dev} | grep " 0m$")" ]]; then
echo "${dev}"
[[ "${1}" ]] && echo ${1}
fi
done
}
getavailablevg()
{
2013-07-25 13:00:18 +02:00
for i in "$(vgs -o vg_name,vg_free --noheading --units m)"; do
2011-02-04 14:34:11 +01:00
if ! [[ "$(echo ${i} | grep " 0m$")" ]]; then
2013-07-25 13:00:18 +02:00
echo "${i}\n"
2009-07-01 21:07:37 +02:00
fi
done
}
# Creates volume group
_createvg()
{
2009-04-10 23:21:08 +02:00
VGFINISH=""
2011-02-04 14:34:11 +01:00
while [[ "${VGFINISH}" != "DONE" ]]; do
2009-04-11 19:01:22 +02:00
: >/tmp/.pvs
2009-04-10 23:21:08 +02:00
VGDEVICE=""
2009-04-11 19:01:22 +02:00
PVS=$(findpv _)
2009-04-10 23:21:08 +02:00
# break if all devices are in use
2011-02-04 14:34:11 +01:00
if [[ "${PVS}" = "" ]]; then
DIALOG --msgbox "No devices left for Volume Group creation." 0 0
2009-04-10 23:21:08 +02:00
return 1
fi
2009-04-11 19:01:22 +02:00
# enter volume group name
VGDEVICE=""
2011-02-04 14:34:11 +01:00
while [[ "${VGDEVICE}" = "" ]]; do
DIALOG --inputbox "Enter the Volume Group name:\nfoogroup\n<yourvolumegroupname>\n\n" 15 65 "foogroup" 2>${ANSWER} || return 1
VGDEVICE=$(cat ${ANSWER})
if [[ "$(vgs -o vg_name --noheading 2>/dev/null | grep "^ $(echo ${VGDEVICE})")" ]]; then
2009-04-11 19:01:22 +02:00
DIALOG --msgbox "ERROR: You have defined 2 identical Volume Group names! Please enter another name." 8 65
VGDEVICE=""
fi
done
2013-07-25 09:30:31 +02:00
# show all devices with sizes, which are not in use
2013-07-25 09:34:15 +02:00
DIALOG --cr-wrap --msgbox "Physical Volumes:\n$(getavailablepv)" 0 0
2009-04-11 19:01:22 +02:00
# select the first device to use, no missing option available!
PVNUMBER=1
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select Physical Volume ${PVNUMBER} for ${VGDEVICE}" 21 50 13 ${PVS} 2>${ANSWER} || return 1
PV=$(cat ${ANSWER})
echo "${PV}" >>/tmp/.pvs
while [[ "${PVS}" != "DONE" ]]; do
PVNUMBER=$((${PVNUMBER} + 1))
2009-04-11 19:01:22 +02:00
# clean loop from used partition and options
2011-02-04 14:34:11 +01:00
PVS="$(echo ${PVS} | sed -e "s#${PV}\ _##g")"
2009-04-11 19:01:22 +02:00
# add more devices
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select additional Physical Volume ${PVNUMBER} for ${VGDEVICE}" 21 50 13 ${PVS} DONE _ 2>${ANSWER} || return 1
PV=$(cat ${ANSWER})
[[ "${PV}" = "DONE" ]] && break
echo "${PV}" >>/tmp/.pvs
2009-04-11 19:01:22 +02:00
done
2009-04-10 23:21:08 +02:00
# final step ask if everything is ok?
2011-02-04 14:34:11 +01:00
DIALOG --yesno "Would you like to create Volume Group like this?\n\n${VGDEVICE}\n\nPhysical Volumes:\n$(cat /tmp/.pvs | sed -e 's#$#\\n#g')" 0 0 && VGFINISH="DONE"
2009-04-10 23:21:08 +02:00
done
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Creating Volume Group ${VGDEVICE}..." 0 0
2009-04-11 19:01:22 +02:00
PV="$(echo -n $(cat /tmp/.pvs))"
2011-02-04 14:34:11 +01:00
vgcreate ${VGDEVICE} ${PV} >${LOG} 2>&1
2011-02-03 21:54:43 +01:00
if [[ $? -gt 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error creating Volume Group ${VGDEVICE} (see ${LOG} for details)." 0 0
2009-04-10 23:21:08 +02:00
return 1
fi
}
# Creates logical volume
_createlv()
{
LVFINISH=""
2011-02-04 14:34:11 +01:00
while [[ "${LVFINISH}" != "DONE" ]]; do
LVDEVICE=""
LV_SIZE_SET=""
LVS=$(findvg _)
# break if all devices are in use
2011-02-04 14:34:11 +01:00
if [[ "${LVS}" = "" ]]; then
DIALOG --msgbox "No Volume Groups with free space available for Logical Volume creation." 0 0
return 1
fi
2013-07-25 13:00:18 +02:00
# show all devices with sizes, which are not 100% in use!
DIALOG --cr-wrap --msgbox "Volume Groups:\n$(getavailablevg)" 0 0
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select Volume Group" 21 50 13 ${LVS} 2>${ANSWER} || return 1
LV=$(cat ${ANSWER})
# enter logical volume name
LVDEVICE=""
2011-02-04 14:34:11 +01:00
while [[ "${LVDEVICE}" = "" ]]; do
DIALOG --inputbox "Enter the Logical Volume name:\nfooname\n<yourvolumename>\n\n" 15 65 "fooname" 2>${ANSWER} || return 1
LVDEVICE=$(cat ${ANSWER})
if [[ "$(lvs -o lv_name,vg_name --noheading 2>/dev/null | grep " $(echo ${LVDEVICE}) $(echo ${LV})"$)" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical Logical Volume names! Please enter another name." 8 65
LVDEVICE=""
fi
done
2011-02-04 14:34:11 +01:00
while [[ "${LV_SIZE_SET}" = "" ]]; do
LV_ALL=""
DIALOG --inputbox "Enter the size (MB) of your Logical Volume,\nMinimum value is > 0.\n\nVolume space left: $(vgs -o vg_free --noheading --units m ${LV})B\n\nIf you enter no value, all free space left will be used." 10 65 "" 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
LV_SIZE=$(cat ${ANSWER})
if [[ "${LV_SIZE}" = "" ]]; then
2012-05-12 16:07:20 +02:00
DIALOG --yesno "Would you like to create Logical Volume with no free space left?" 0 0 && LV_ALL="1"
if ! [[ "${LV_ALL}" = "1" ]]; then
LV_SIZE=0
fi
fi
2011-02-04 14:34:11 +01:00
if [[ "${LV_SIZE}" = "0" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
2011-02-04 14:34:11 +01:00
if [[ "${LV_SIZE}" -ge "$(vgs -o vg_free --noheading --units m | sed -e 's#m##g')" ]]; then
DIALOG --msgbox "ERROR: You have entered a too large size, please enter again." 0 0
else
LV_SIZE_SET=1
fi
fi
done
#Contiguous doesn't work with +100%FREE
LV_CONTIGUOUS=""
2011-02-04 14:34:11 +01:00
[[ "${LV_ALL}" = "" ]] && DIALOG --defaultno --yesno "Would you like to create Logical Volume as a contiguous partition, that means that your space doesn't get partitioned over one or more disks nor over non-contiguous physical extents.\n(usefull for swap space etc.)?" 0 0 && LV_CONTIGUOUS="1"
if [[ "${LV_CONTIGUOUS}" = "1" ]]; then
CONTIGUOUS=yes
LV_EXTRA="-C y"
else
CONTIGUOUS=no
LV_EXTRA=""
fi
2011-02-04 14:34:11 +01:00
[[ "${LV_SIZE}" = "" ]] && LV_SIZE="All free space left"
# final step ask if everything is ok?
2011-02-04 14:34:11 +01:00
DIALOG --yesno "Would you like to create Logical Volume ${LVDEVICE} like this?\nVolume Group:\n${LV}\nVolume Size:\n${LV_SIZE}\nContiguous Volume:\n${CONTIGUOUS}" 0 0 && LVFINISH="DONE"
done
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Creating Logical Volume ${LVDEVICE}..." 0 0
if [[ "${LV_ALL}" = "1" ]]; then
lvcreate ${LV_EXTRA} -l +100%FREE ${LV} -n ${LVDEVICE} >${LOG} 2>&1
else
2011-02-04 14:34:11 +01:00
lvcreate ${LV_EXTRA} -L ${LV_SIZE} ${LV} -n ${LVDEVICE} >${LOG} 2>&1
fi
2011-02-03 21:54:43 +01:00
if [[ $? -gt 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error creating Logical Volume ${LVDEVICE} (see ${LOG} for details)." 0 0
return 1
fi
}
# enter luks name
_enter_luks_name() {
LUKSDEVICE=""
2011-02-04 14:34:11 +01:00
while [[ "${LUKSDEVICE}" = "" ]]; do
DIALOG --inputbox "Enter the name for luks encrypted device ${PART}:\nfooname\n<yourname>\n\n" 15 65 "fooname" 2>${ANSWER} || return 1
LUKSDEVICE=$(cat ${ANSWER})
if ! [[ "$(cryptsetup status ${LUKSDEVICE} | grep inactive)" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical luks encryption device names! Please enter another name." 8 65
LUKSDEVICE=""
fi
done
}
# enter luks passphrase
_enter_luks_passphrase () {
LUKSPASSPHRASE=""
2011-02-04 14:34:11 +01:00
while [[ "${LUKSPASSPHRASE}" = "" ]]; do
DIALOG --insecure --passwordbox "Enter passphrase for luks encrypted device ${PART}:" 0 0 2>${ANSWER} || return 1
LUKSPASS=$(cat ${ANSWER})
2011-02-08 16:25:16 +01:00
DIALOG --insecure --passwordbox "Retype passphrase for luks encrypted device ${PART}:" 0 0 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
LUKSPASS2=$(cat ${ANSWER})
2013-07-24 20:38:59 +02:00
if [[ -n "${LUKSPASS}" && -n "${LUKSPASS2}" && "${LUKSPASS}" = "${LUKSPASS2}" ]]; then
2011-02-04 14:34:11 +01:00
LUKSPASSPHRASE=${LUKSPASS}
2012-07-27 12:02:05 +02:00
echo ${LUKSPASSPHRASE} > /tmp/passphrase-${LUKSDEVICE}
LUKSPASSPHRASE=/tmp/passphrase-${LUKSDEVICE}
else
2013-07-24 20:38:59 +02:00
DIALOG --msgbox "Passphrases didn't match or was empty, please enter again." 0 0
fi
done
}
# opening luks
_opening_luks() {
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Opening encrypted ${PART}..." 0 0
2011-02-08 16:25:16 +01:00
luksOpen_success="0"
while [[ "${luksOpen_success}" = "0" ]]; do
cryptsetup luksOpen ${PART} ${LUKSDEVICE} >${LOG} <${LUKSPASSPHRASE} && luksOpen_success=1
if [[ "${luksOpen_success}" = "0" ]]; then
DIALOG --msgbox "Error: Passphrases didn't match, please enter again." 0 0
_enter_luks_passphrase || return 1
fi
done
2012-07-27 12:02:05 +02:00
DIALOG --yesno "Would you like to save the passphrase of luks device in /etc/$(basename ${LUKSPASSPHRASE})?\nName:${LUKSDEVICE}" 0 0 || LUKSPASSPHRASE="ASK"
echo ${LUKSDEVICE} ${PART} /etc/$(basename ${LUKSPASSPHRASE}) >> /tmp/.crypttab
}
2009-04-19 17:19:37 +02:00
# help for luks
_helpluks()
{
DIALOG --msgbox "LUKS ENCRYPTION SUMMARY:\n
-----------------------------\n\n
Encryption is useful for two (related) reasons.\n
Firstly, it prevents anyone with physical access to your computer,\n
2012-10-08 09:14:16 +02:00
and your storage drive in particular, from getting the data from it\n
2009-04-19 17:19:37 +02:00
(unless they have your passphrase/key).\n
2012-10-08 09:14:16 +02:00
Secondly, it allows you to wipe the data on your storage drive with\n
2009-04-19 17:19:37 +02:00
far more confidence in the event of you selling or discarding\n
your drive.\n
Basically, it supplements the access control mechanisms of the operating\n
system (like file permissions) by making it harder to bypass the operating\n
system by inserting a boot CD, for example. Encrypting the root partition\n
prevents anyone from using this method to insert viruses or trojans onto\n
your computer.\n\n
ATTENTION:\n
Having encrypted partitions does not protect you from all possible\n
attacks. The encryption is only as good as your key management, and there\n
are other ways to break into computers, while they are running." 0 0
}
# create luks device
2009-04-17 22:29:31 +02:00
_luks()
{
2011-02-06 22:12:44 +01:00
NAME_SCHEME_PARAMETER_RUN=""
2009-04-17 22:29:31 +02:00
LUKSFINISH=""
2011-02-04 14:34:11 +01:00
while [[ "${LUKSFINISH}" != "DONE" ]]; do
2010-05-18 23:52:30 +02:00
activate_special_devices
2013-07-22 21:17:06 +02:00
# Remove all crypt devices with children
CRYPT_BLACKLIST="$(for i in $(${_LSBLK} NAME,TYPE | grep " crypt$" | cut -d' ' -f1 | sort -u); do
echo $(${_LSBLK} NAME ${i}) _
done)"
PARTS="$(for i in $(findpartitions); do
! [[ "$(echo "${CRYPT_BLACKLIST}" | egrep "${i} _")" ]] && echo $i _
done)"
# break if all devices are in use
2011-02-04 14:34:11 +01:00
if [[ "${PARTS}" = "" ]]; then
2009-04-17 22:29:31 +02:00
DIALOG --msgbox "No devices left for luks encryption." 0 0
return 1
fi
2009-07-01 21:07:37 +02:00
# show all devices with sizes
DIALOG --cr-wrap --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)\n\n" 0 0
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select device for luks encryption" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
2009-07-01 21:07:37 +02:00
# enter luks name
_enter_luks_name
2011-02-06 22:12:44 +01:00
### TODO: offer more options for encrypt!
### defaults are used only
# final step ask if everything is ok?
2011-02-04 14:34:11 +01:00
DIALOG --yesno "Would you like to encrypt luks device below?\nName:${LUKSDEVICE}\nDevice:${PART}\n" 0 0 && LUKSFINISH="DONE"
done
2013-07-24 20:38:59 +02:00
_enter_luks_passphrase || return 1
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Encrypting ${PART}..." 0 0
cryptsetup luksFormat ${PART} >${LOG} <${LUKSPASSPHRASE}
_opening_luks
2009-02-01 23:01:19 +01:00
}
autoprepare() {
2009-04-17 22:29:31 +02:00
# check on encrypted devices, else weird things can happen!
_stopluks
2009-03-28 13:36:54 +01:00
# check on raid devices, else weird things can happen during partitioning!
_stopmd
# check on lvm devices, else weird things can happen during partitioning!
_stoplvm
2010-05-24 15:39:55 +02:00
NAME_SCHEME_PARAMETER_RUN=""
2010-03-15 07:14:28 +01:00
# switch for mbr usage
set_guid
2018-06-25 14:58:11 +02:00
: >/tmp/.device-names
DISCS=$(blockdevices)
2011-02-04 14:34:11 +01:00
if [[ "$(echo ${DISCS} | wc -w)" -gt 1 ]]; then
DIALOG --cr-wrap --msgbox "Available Disks:\n\n$(_getavaildisks)\n" 0 0
DIALOG --menu "Select the storage drive to use" 14 55 7 $(blockdevices _) 2>"${ANSWER}" || return 1
2011-02-04 14:34:11 +01:00
DISC=$(cat ${ANSWER})
else
DISC="${DISCS}"
if [[ "${DISC}" = "" ]]; then
DIALOG --msgbox "ERROR: Setup cannot find available disk device, please use normal installation routine for partitioning and mounting devices." 0 0
return 1
fi
fi
BOOT_PART_SIZE=""
GUID_PART_SIZE=""
UEFISYS_PART_SIZE=""
2010-03-11 12:07:35 +01:00
DEFAULTFS=""
_UEFISYS_BOOTPART=""
UEFISYS_MOUNTPOINT=""
2020-07-24 18:58:47 +02:00
UEFISYS_PART_SET=""
BOOT_PART_SET=""
SWAP_PART_SET=""
ROOT_PART_SET=""
CHOSEN_FS=""
# get just the disk size in 1000*1000 MB
DISC_SIZE="$(($(${_LSBLK} SIZE -d -b ${DISC})/1000000))"
if [[ "${DISC_SIZE}" = "" ]]; then
2010-08-27 21:48:37 +02:00
DIALOG --msgbox "ERROR: Setup cannot detect size of your device, please use normal installation routine for partitioning and mounting devices." 0 0
return 1
fi
if [[ "${GUIDPARAMETER}" = "yes" ]]; then
2013-10-14 12:01:58 +02:00
DIALOG --inputbox "Enter the mountpoint of your UEFI SYSTEM PARTITION (Default is /boot) : " 0 0 "/boot" 2>"${ANSWER}" || return 1
UEFISYS_MOUNTPOINT="$(cat ${ANSWER})"
fi
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
DIALOG --msgbox "You have chosen to use /boot as the UEFISYS Mountpoint. The minimum partition size is 260 MiB and only FAT32 FS is supported" 0 0
_UEFISYS_BOOTPART="1"
fi
2011-02-04 14:34:11 +01:00
while [[ "${DEFAULTFS}" = "" ]]; do
FSOPTS=""
2011-02-04 14:34:11 +01:00
[[ "$(which mkfs.ext2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext2 Ext2"
[[ "$(which mkfs.ext3 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext3 Ext3"
[[ "$(which mkfs.ext4 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext4 Ext4"
[[ "$(which mkfs.btrfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} btrfs Btrfs"
[[ "$(which mkfs.nilfs2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} nilfs2 Nilfs2"
[[ "$(which mkfs.f2fs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} f2fs F2FS"
2011-02-04 14:34:11 +01:00
[[ "$(which mkreiserfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} reiserfs Reiser3"
[[ "$(which mkfs.xfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} xfs XFS"
[[ "$(which mkfs.jfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} jfs JFS"
2013-06-22 20:29:23 +02:00
# create 1 MB bios_grub partition for grub BIOS GPT support
2011-02-04 14:34:11 +01:00
if [[ "${GUIDPARAMETER}" = "yes" ]]; then
GUID_PART_SIZE="2"
2012-06-25 11:34:07 +02:00
GPT_BIOS_GRUB_PART_SIZE="${GUID_PART_SIZE}"
_PART_NUM="1"
_GPT_BIOS_GRUB_PART_NUM="${_PART_NUM}"
DISC_SIZE="$((${DISC_SIZE}-${GUID_PART_SIZE}))"
2010-03-11 12:07:35 +01:00
fi
if [[ "${GUIDPARAMETER}" = "yes" ]]; then
if [[ "${_UEFISYS_BOOTPART}" == "1" ]]; then
while [[ "${UEFISYS_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your /boot partition,\nMinimum value is 260.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "1024" 2>${ANSWER} || return 1
UEFISYS_PART_SIZE="$(cat ${ANSWER})"
if [[ "${UEFISYS_PART_SIZE}" = "" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
if [[ "${UEFISYS_PART_SIZE}" -ge "${DISC_SIZE}" || "${UEFISYS_PART_SIZE}" -lt "260" || "${UEFISYS_PART_SIZE}" = "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
BOOT_PART_SET=1
UEFISYS_PART_SET=1
_PART_NUM="$((${_PART_NUM}+1))"
_UEFISYS_PART_NUM="${_PART_NUM}"
fi
fi
done
else
while [[ "${UEFISYS_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your UEFI SYSTEM PARTITION,\nMinimum value is 260.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "1024" 2>${ANSWER} || return 1
UEFISYS_PART_SIZE="$(cat ${ANSWER})"
if [[ "${UEFISYS_PART_SIZE}" = "" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
if [[ "${UEFISYS_PART_SIZE}" -ge "${DISC_SIZE}" || "${UEFISYS_PART_SIZE}" -lt "260" || "${UEFISYS_PART_SIZE}" = "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
UEFISYS_PART_SET=1
_PART_NUM="$((${_PART_NUM}+1))"
_UEFISYS_PART_NUM="${_PART_NUM}"
fi
fi
done
fi
DISC_SIZE="$((${DISC_SIZE}-${UEFISYS_PART_SIZE}))"
while [[ "${BOOT_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your /boot partition,\nMinimum value is 16.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "512" 2>${ANSWER} || return 1
BOOT_PART_SIZE="$(cat ${ANSWER})"
if [[ "${BOOT_PART_SIZE}" = "" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
if [[ "${BOOT_PART_SIZE}" -ge "${DISC_SIZE}" || "${BOOT_PART_SIZE}" -lt "16" || "${SBOOT_PART_SIZE}" = "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
BOOT_PART_SET=1
_PART_NUM="$((${_UEFISYS_PART_NUM}+1))"
_BOOT_PART_NUM="${_PART_NUM}"
DISC_SIZE="$((${DISC_SIZE}-${BOOT_PART_SIZE}))"
fi
fi
done
else
while [[ "${BOOT_PART_SET}" = "" ]]; do
2013-06-22 20:39:26 +02:00
DIALOG --inputbox "Enter the size (MB) of your /boot partition,\nMinimum value is 16.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "512" 2>${ANSWER} || return 1
BOOT_PART_SIZE="$(cat ${ANSWER})"
if [[ "${BOOT_PART_SIZE}" = "" ]]; then
DIALOG --msgbox "ERROR: You have entered a invalid size, please enter again." 0 0
else
2013-06-22 20:39:26 +02:00
if [[ "${BOOT_PART_SIZE}" -ge "${DISC_SIZE}" || "${BOOT_PART_SIZE}" -lt "16" || "${SBOOT_PART_SIZE}" = "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
BOOT_PART_SET=1
_PART_NUM="1"
2013-06-22 20:39:26 +02:00
_BOOT_PART_NUM="${_PART_NUM}"
DISC_SIZE="$((${DISC_SIZE}-${BOOT_PART_SIZE}))"
2013-06-22 20:39:26 +02:00
fi
fi
2013-06-22 20:39:26 +02:00
done
fi
2010-04-16 07:31:29 +02:00
SWAP_SIZE="256"
2011-02-04 14:34:11 +01:00
[[ "${DISC_SIZE}" -lt "256" ]] && SWAP_SIZE="${DISC_SIZE}"
while [[ "${SWAP_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your swap partition,\nMinimum value is > 0.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "${SWAP_SIZE}" 2>"${ANSWER}" || return 1
2011-02-04 14:34:11 +01:00
SWAP_PART_SIZE=$(cat ${ANSWER})
if [[ "${SWAP_PART_SIZE}" = "" || "${SWAP_PART_SIZE}" = "0" ]]; then
2010-03-11 12:07:35 +01:00
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
2011-02-04 14:34:11 +01:00
if [[ "${SWAP_PART_SIZE}" -ge "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered a too large size, please enter again." 0 0
else
SWAP_PART_SET=1
_PART_NUM="$((${_PART_NUM}+1))"
_SWAP_PART_NUM="${_PART_NUM}"
fi
fi
done
2013-06-22 20:39:26 +02:00
2011-02-04 14:34:11 +01:00
while [[ "${CHOSEN_FS}" = "" ]]; do
DIALOG --menu "Select a filesystem for / and /home:" 16 45 9 ${FSOPTS} 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
FSTYPE=$(cat ${ANSWER})
DIALOG --yesno "${FSTYPE} will be used for / and /home. Is this OK?" 0 0 && CHOSEN_FS=1
done
# / and /home are subvolumes on btrfs
if ! [[ "${FSTYPE}" = "btrfs" ]]; then
DISC_SIZE="$((${DISC_SIZE}-${SWAP_PART_SIZE}))"
ROOT_SIZE="7500"
[[ "${DISC_SIZE}" -lt "7500" ]] && ROOT_SIZE="${DISC_SIZE}"
while [[ "${ROOT_PART_SET}" = "" ]]; do
DIALOG --inputbox "Enter the size (MB) of your / partition\nMinimum value is 2500,\nthe /home partition will use the remaining space.\n\nDisk space left: ${DISC_SIZE} MB" 10 65 "${ROOT_SIZE}" 2>"${ANSWER}" || return 1
ROOT_PART_SIZE=$(cat ${ANSWER})
if [[ "${ROOT_PART_SIZE}" = "" || "${ROOT_PART_SIZE}" = "0" || "${ROOT_PART_SIZE}" -lt "2500" ]]; then
DIALOG --msgbox "ERROR: You have entered an invalid size, please enter again." 0 0
else
if [[ "${ROOT_PART_SIZE}" -ge "${DISC_SIZE}" ]]; then
DIALOG --msgbox "ERROR: You have entered a too large size, please enter again." 0 0
else
DIALOG --yesno "$((${DISC_SIZE}-${ROOT_PART_SIZE})) MB will be used for your /home partition. Is this OK?" 0 0 && ROOT_PART_SET=1
fi
fi
done
fi
_PART_NUM="$((${_PART_NUM}+1))"
_ROOT_PART_NUM="${_PART_NUM}"
if ! [[ "${FSTYPE}" = "btrfs" ]]; then
_PART_NUM="$((${_PART_NUM}+1))"
fi
_HOME_PART_NUM="${_PART_NUM}"
2010-03-11 12:07:35 +01:00
DEFAULTFS=1
done
2011-02-04 14:34:11 +01:00
DIALOG --defaultno --yesno "${DISC} will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 \
|| return 1
2011-02-04 14:34:11 +01:00
DEVICE=${DISC}
# validate DEVICE
2011-02-04 14:34:11 +01:00
if [[ ! -b "${DEVICE}" ]]; then
DIALOG --msgbox "Device '${DEVICE}' is not valid" 0 0
return 1
fi
# validate DEST
2011-02-04 14:34:11 +01:00
if [[ ! -d "${DESTDIR}" ]]; then
DIALOG --msgbox "Destination directory '${DESTDIR}' is not valid" 0 0
return 1
fi
2011-02-03 21:54:43 +01:00
[[ -e /tmp/.fstab ]] && rm -f /tmp/.fstab
# disable swap and all mounted partitions, umount / last!
_umountall
# we assume a /dev/sdX,/dev/vdX or /dev/nvmeXnY format
2012-01-09 13:54:09 +01:00
if [[ "${GUIDPARAMETER}" == "yes" ]]; then
# GPT (GUID) is supported only by 'parted' or 'sgdisk'
2010-03-11 12:07:35 +01:00
printk off
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Partitioning ${DEVICE}" 0 0
# clean partition table to avoid issues!
sgdisk --zap ${DEVICE} &>/dev/null
2012-04-24 18:50:27 +02:00
# clear all magic strings/signatures - mdadm, lvm, partition tables etc.
dd if=/dev/zero of=${DEVICE} bs=512 count=2048 &>/dev/null
wipefs -a ${DEVICE} &>/dev/null
# create fresh GPT
sgdisk --clear ${DEVICE} &>/dev/null
2012-04-24 18:50:27 +02:00
# create actual partitions
sgdisk --set-alignment="2048" --new=${_GPT_BIOS_GRUB_PART_NUM}:0:+${GPT_BIOS_GRUB_PART_SIZE}M --typecode=${_GPT_BIOS_GRUB_PART_NUM}:EF02 --change-name=${_GPT_BIOS_GRUB_PART_NUM}:BIOS_GRUB ${DEVICE} > ${LOG}
sgdisk --set-alignment="2048" --new=${_UEFISYS_PART_NUM}:0:+${UEFISYS_PART_SIZE}M --typecode=${_UEFISYS_PART_NUM}:EF00 --change-name=${_UEFISYS_PART_NUM}:UEFI_SYSTEM ${DEVICE} > ${LOG}
if [[ "${_UEFISYS_BOOTPART}" == "1" ]]; then
sgdisk --attributes=${_UEFISYS_PART_NUM}:set:2 ${DEVICE} > ${LOG}
else
sgdisk --set-alignment="2048" --new=${_BOOT_PART_NUM}:0:+${BOOT_PART_SIZE}M --typecode=${_BOOT_PART_NUM}:8300 --attributes=${_BOOT_PART_NUM}:set:2 --change-name=${_BOOT_PART_NUM}:ARCHLINUX_BOOT ${DEVICE} > ${LOG}
fi
sgdisk --set-alignment="2048" --new=${_SWAP_PART_NUM}:0:+${SWAP_PART_SIZE}M --typecode=${_SWAP_PART_NUM}:8200 --change-name=${_SWAP_PART_NUM}:ARCHLINUX_SWAP ${DEVICE} > ${LOG}
if [[ "${FSTYPE}" = "btrfs" ]]; then
sgdisk --set-alignment="2048" --new=${_ROOT_PART_NUM}:0:0 --typecode=${_ROOT_PART_NUM}:8300 --change-name=${_ROOT_PART_NUM}:ARCHLINUX_ROOT ${DEVICE} > ${LOG}
else
sgdisk --set-alignment="2048" --new=${_ROOT_PART_NUM}:0:+${ROOT_PART_SIZE}M --typecode=${_ROOT_PART_NUM}:8300 --change-name=${_ROOT_PART_NUM}:ARCHLINUX_ROOT ${DEVICE} > ${LOG}
sgdisk --set-alignment="2048" --new=${_HOME_PART_NUM}:0:0 --typecode=${_HOME_PART_NUM}:8302 --change-name=${_HOME_PART_NUM}:ARCHLINUX_HOME ${DEVICE} > ${LOG}
fi
sgdisk --print ${DEVICE} > ${LOG}
2010-03-11 12:07:35 +01:00
else
# start at sector 1 for 4k drive compatibility and correct alignment
2010-03-11 12:07:35 +01:00
printk off
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Partitioning ${DEVICE}" 0 0
2010-03-11 12:07:35 +01:00
# clean partitiontable to avoid issues!
2011-02-04 14:34:11 +01:00
dd if=/dev/zero of=${DEVICE} bs=512 count=2048 >/dev/null 2>&1
wipefs -a ${DEVICE} &>/dev/null
2010-03-11 12:07:35 +01:00
# create DOS MBR with parted
parted -a optimal -s ${DEVICE} unit MiB mktable msdos >/dev/null 2>&1
parted -a optimal -s ${DEVICE} unit MiB mkpart primary 1 $((${GUID_PART_SIZE}+${BOOT_PART_SIZE})) >${LOG}
parted -a optimal -s ${DEVICE} unit MiB set 1 boot on >${LOG}
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE})) $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE})) >${LOG}
# $(sgdisk -E ${DEVICE}) | grep ^[0-9] as end of last partition to keep the possibilty to convert to GPT later, instead of 100%
if [[ "${FSTYPE}" = "btrfs" ]]; then
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE})) $(sgdisk -E ${DEVICE} | grep ^[0-9])S >${LOG}
else
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE})) $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE}+${ROOT_PART_SIZE})) >${LOG}
parted -a optimal -s ${DEVICE} unit MiB mkpart primary $((${GUID_PART_SIZE}+${BOOT_PART_SIZE}+${SWAP_PART_SIZE}+${ROOT_PART_SIZE})) $(sgdisk -E ${DEVICE} | grep ^[0-9])S >${LOG}
fi
2010-03-11 12:07:35 +01:00
fi
2011-02-03 21:54:43 +01:00
if [[ $? -gt 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error partitioning ${DEVICE} (see ${LOG} for details)" 0 0
printk on
return 1
fi
# reread partitiontable for kernel
partprobe ${DEVICE}
printk on
## wait until /dev initialized correct devices
2010-03-11 12:07:35 +01:00
udevadm settle
if [[ "${NAME_SCHEME_PARAMETER_RUN}" == "" ]]; then
set_device_name_scheme || return 1
fi
## FSSPECS - default filesystem specs (the + is bootable flag)
## <partnum>:<mountpoint>:<partsize>:<fstype>[:<fsoptions>][:+]:labelname
## The partitions in FSSPECS list should be listed in the "mountpoint" order.
## Make sure the "root" partition is defined first in the FSSPECS list
_FSSPEC_ROOT_PART="${_ROOT_PART_NUM}:/:${FSTYPE}::ROOT_ARCH"
_FSSPEC_HOME_PART="${_HOME_PART_NUM}:/home:${FSTYPE}::HOME_ARCH"
_FSSPEC_SWAP_PART="${_SWAP_PART_NUM}:swap:swap::SWAP_ARCH"
_FSSPEC_BOOT_PART="${_BOOT_PART_NUM}:/boot:ext2::BOOT_ARCH"
_FSSPEC_UEFISYS_PART="${_UEFISYS_PART_NUM}:${UEFISYS_MOUNTPOINT}:vfat:-F32:EFISYS"
if [[ "${GUIDPARAMETER}" == "yes" ]]; then
if [[ "${_UEFISYS_BOOTPART}" == "1" ]]; then
FSSPECS="${_FSSPEC_ROOT_PART} ${_FSSPEC_UEFISYS_PART} ${_FSSPEC_HOME_PART} ${_FSSPEC_SWAP_PART}"
else
FSSPECS="${_FSSPEC_ROOT_PART} ${_FSSPEC_BOOT_PART} ${_FSSPEC_UEFISYS_PART} ${_FSSPEC_HOME_PART} ${_FSSPEC_SWAP_PART}"
fi
else
FSSPECS="${_FSSPEC_ROOT_PART} ${_FSSPEC_BOOT_PART} ${_FSSPEC_HOME_PART} ${_FSSPEC_SWAP_PART}"
fi
## make and mount filesystems
2011-02-04 14:34:11 +01:00
for fsspec in ${FSSPECS}; do
DOMKFS="yes"
PART="${DEVICE}$(echo ${fsspec} | tr -d ' ' | cut -f1 -d:)"
2018-06-25 14:15:15 +02:00
# Add check on nvme controller: Uses /dev/nvme0n1pX name scheme
[[ $(echo "${DEVICE}" | grep "nvme") ]] && PART="${DEVICE}p$(echo ${fsspec} | tr -d ' ' | cut -f1 -d:)"
MP="$(echo ${fsspec} | tr -d ' ' | cut -f2 -d:)"
FSTYPE="$(echo ${fsspec} | tr -d ' ' | cut -f3 -d:)"
FS_OPTIONS="$(echo ${fsspec} | tr -d ' ' | cut -f4 -d:)"
[[ "${FS_OPTIONS}" == "" ]] && FS_OPTIONS="NONE"
LABEL_NAME="$(echo ${fsspec} | tr -d ' ' | cut -f5 -d:)"
BTRFS_DEVICES="${PART}"
if [[ "${FSTYPE}" = "btrfs" ]]; then
BTRFS_COMPRESS="compress=lzo"
[[ "${MP}" = "/" ]] && BTRFS_SUBVOLUME="root"
[[ "${MP}" = "/home" ]] && BTRFS_SUBVOLUME="home" && DOMKFS="no"
DOSUBVOLUME="yes"
else
BTRFS_COMPRESS="NONE"
BTRFS_SUBVOLUME="NONE"
DOSUBVOLUME="no"
fi
BTRFS_LEVEL="NONE"
2014-08-02 11:24:13 +02:00
if ! [[ "${FSTYPE}" = "swap" ]]; then
DIALOG --infobox "Creating ${FSTYPE} on ${PART}\nwith FSLABEL ${LABEL_NAME} ,\nmounting to ${DESTDIR}${MP}" 0 0
else
DIALOG --infobox "Creating and activating swapspace on ${PART}" 0 0
fi
_mkfs ${DOMKFS} ${PART} ${FSTYPE} ${DESTDIR} ${MP} ${LABEL_NAME} ${FS_OPTIONS} ${BTRFS_DEVICES} ${BTRFS_LEVEL} ${BTRFS_SUBVOLUME} ${DOSUBVOLUME} ${BTRFS_COMPRESS} || return 1
sleep 1
done
DIALOG --msgbox "Auto-prepare was successful" 0 0
S_MKFSAUTO=1
2008-10-20 22:39:25 +02:00
}
detect_DISC() {
if [[ "${DISC}" == "" ]] || [[ ! "$(echo ${DISC} | grep '/dev/')" ]]; then
DISC="$(${_LSBLK} PKNAME "$(findmnt -vno SOURCE "${DESTDIR}/boot")")"
fi
if [[ "${DISC}" == "" ]]; then
DISC="$(${_LSBLK} PKNAME "$(findmnt -vno SOURCE "${DESTDIR}/")")"
fi
}
2011-09-12 21:38:58 +02:00
check_gpt() {
2011-10-07 09:38:59 +02:00
GUID_DETECTED=""
2012-04-23 15:17:42 +02:00
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${DISC})" == "gpt" ]] && GUID_DETECTED="1"
2011-10-27 09:51:17 +02:00
if [[ "${GUID_DETECTED}" == "" ]]; then
2013-10-15 17:49:45 +02:00
DIALOG --defaultno --yesno "Setup detected no GUID (gpt) partition table on ${DISC}.\n\nDo you want to convert the existing MBR table in ${DISC} to a GUID (gpt) partition table?" 0 0 || return 1
sgdisk --mbrtogpt ${DISC} > ${LOG} && GUID_DETECTED="1"
# reread partitiontable for kernel
partprobe ${DISC} > ${LOG}
if [[ "${GUID_DETECTED}" == "" ]]; then
DIALOG --defaultno --yesno "Conversion failed on ${DISC}.\nSetup detected no GUID (gpt) partition table on ${DISC}.\n\nDo you want to create a new GUID (gpt) table now on ${DISC}?\n\n${DISC} will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 || return 1
# clean partition table to avoid issues!
sgdisk --zap ${DISC} &>/dev/null
# clear all magic strings/signatures - mdadm, lvm, partition tables etc.
dd if=/dev/zero of=${DISC} bs=512 count=2048 &>/dev/null
wipefs -a ${DISC} &>/dev/null
# create fresh GPT
sgdisk --clear ${DISC} &>/dev/null
GUID_DETECTED="1"
fi
fi
2011-10-27 09:51:17 +02:00
if [[ "${GUID_DETECTED}" == "1" ]]; then
### This check is not enabled in any function yet!
if [[ "${CHECK_UEFISYS_PART}" == "1" ]]; then
check_efisys_part
2011-09-12 21:38:58 +02:00
fi
2012-06-25 11:34:07 +02:00
if [[ "${CHECK_BIOS_BOOT_GRUB}" == "1" ]]; then
2011-09-12 21:38:58 +02:00
if ! [[ "$(sgdisk -p ${DISC} | grep 'EF02')" ]]; then
2013-06-22 20:29:23 +02:00
DIALOG --msgbox "Setup detected no BIOS BOOT PARTITION in ${DISC}. Please create a >=1 MB BIOS Boot partition for grub BIOS GPT support." 0 0
RUN_CFDISK="1"
fi
fi
fi
if [[ "${RUN_CFDISK}" == "1" ]]; then
DIALOG --msgbox "Now you'll be put into cfdisk where you can partition your storage drive.\nYou should make a swap partition and as many data partitions as you will need." 18 70
clear && cfdisk ${DISC}
# reread partitiontable for kernel
partprobe ${DEVICE}
2011-10-07 15:41:32 +02:00
fi
2010-03-18 22:46:21 +01:00
}
## check and mount EFISYS partition at ${UEFISYS_MOUNTPOINT}
check_efisys_part() {
detect_DISC
2012-01-09 13:54:09 +01:00
if [[ "$(${_BLKID} -p -i -o value -s PTTYPE ${DISC})" != "gpt" ]]; then
GUID_DETECTED=""
DIALOG --defaultno --yesno "Setup detected no GUID (gpt) partition table on ${DISC}.\nUEFI boot requires ${DISC} to be partitioned as GPT.\n\nDo you want to convert the existing MBR table in ${DISC} to a GUID (gpt) partition table?" 0 0 || return 1
DIALOG --msgbox "Setup will now try to non-destructively convert ${DISC} to GPT using sgdisk." 0 0
sgdisk --mbrtogpt ${DISC} > ${LOG} && GUID_DETECTED="1"
partprobe ${DISC} > ${LOG}
if [[ "${GUID_DETECTED}" == "" ]]; then
DIALOG --msgbox "Conversion failed on ${DISC}.\nSetup detected no GUID (gpt) partition table on ${DISC}.\n\n You need to fix your partition table first, before setup can proceed." 0 0
return 1
fi
fi
2012-04-24 18:50:27 +02:00
if [[ ! "$(sgdisk -p ${DISC} | grep 'EF00')" ]]; then
# Windows 10 recommends a minimum of 260MB Efi Systen Partition
DIALOG --msgbox "Setup detected no EFI System partition in ${DISC}. You will now be put into cfdisk. Please create a >= 260 MB partition with cfdisk type EFI System .\nWhen prompted (later) to format as FAT32, say YES.\nIf you already have a >=260 MB FAT32 EFI System partition, check whether that partition has EFI System cfdisk type code." 0 0
clear && cfdisk "${DISC}"
RUN_CFDISK=""
2012-04-24 18:50:27 +02:00
fi
if [[ "$(sgdisk -p ${DISC} | grep 'EF00')" ]]; then
2018-06-25 11:30:38 +02:00
# check on unique PARTTYPE c12a7328-f81f-11d2-ba4b-00a0c93ec93b for EFI System Partition type UUID
2018-06-25 11:45:48 +02:00
UEFISYS_PART="$(${_LSBLK} NAME,PARTTYPE ${DISC} | grep 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' | cut -d " " -f1)"
2012-01-09 13:54:09 +01:00
2013-09-17 12:30:49 +02:00
if [[ "$(${_LSBLK} FSTYPE ${UEFISYS_PART})" != "vfat" ]]; then
## Check whether EFISYS is FAT, otherwise inform the user and offer to format the partition as FAT32.
DIALOG --defaultno --yesno "Detected EFI System partition ${UEFISYS_PART} does not appear to be FAT formatted. UEFI Specification requires EFI System partition to be FAT32 formatted. Do you want to format ${UEFISYS_PART} as FAT32?\nNote: Setup will proceed even if you select NO. Some systems like Apple Macs may work with Non-FAT EFI System partition. However the installed system is not in conformance with UEFI Spec., and MAY NOT boot properly." 0 0 && _FORMAT_UEFISYS_FAT32="1"
fi
if [[ "$(${_LSBLK} FSTYPE ${UEFISYS_PART})" == "vfat" ]] && [[ "$(${_BLKID} -p -i -o value -s VERSION ${UEFISYS_PART})" != "FAT32" ]]; then
## Check whether EFISYS is FAT32 (specifically), otherwise warn the user about compatibility issues with UEFI Spec.
DIALOG --defaultno --yesno "Detected EFI System partition ${UEFISYS_PART} does not appear to be FAT32 formatted. Do you want to format ${UEFISYS_PART} as FAT32?\nNote: Setup will proceed even if you select NO. Most systems will boot fine even with FAT16 or FAT12 EFI System partition, however some firmwares may refuse to boot with a non-FAT32 EFI System partition. It is recommended to use FAT32 for maximum compatibility with UEFI Spec." 0 0 && _FORMAT_UEFISYS_FAT32="1"
2012-04-24 18:50:27 +02:00
fi
#autodetect efisys mountpoint, on fail ask for mountpoint
UEFISYS_MOUNTPOINT="/$(basename $(mount | grep "${UEFISYS_PART}" | cut -d " " -f 3))"
if [[ "${UEFISYS_MOUNTPOINT}" == "/" ]]; then
DIALOG --inputbox "Enter the mountpoint of your EFI System partition (Default is /boot): " 0 0 "/boot" 2>${ANSWER} || return 1
2013-06-22 20:25:34 +02:00
UEFISYS_MOUNTPOINT="$(cat ${ANSWER})"
fi
2013-09-09 15:18:29 +02:00
umount "${DESTDIR}/${UEFISYS_MOUNTPOINT}" &> /dev/null
umount "${UEFISYS_PART}" &> /dev/null
2012-04-24 18:50:27 +02:00
if [[ "${_FORMAT_UEFISYS_FAT32}" == "1" ]]; then
mkfs.vfat -F32 -n "EFISYS" "${UEFISYS_PART}"
2012-01-09 13:54:09 +01:00
fi
2013-03-16 22:10:26 +01:00
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}"
if [[ "$(${_LSBLK} FSTYPE ${UEFISYS_PART})" == "vfat" ]]; then
2013-03-16 22:10:26 +01:00
mount -o rw,flush -t vfat "${UEFISYS_PART}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}"
else
DIALOG --msgbox "${UEFISYS_PART} is not formatted using FAT filesystem. Setup will go ahead but there might be issues using non-FAT FS for EFI System partition." 0 0
2013-03-16 22:10:26 +01:00
mount -o rw "${UEFISYS_PART}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}"
fi
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI" || true
else
DIALOG --msgbox "Setup did not find any EFI System partition in ${DISC}. Please create >= 260 MB FAT32 partition with cfdisk type EFI System code and try again." 0 0
return 1
2012-01-09 13:54:09 +01:00
fi
}
2008-10-20 22:39:25 +02:00
partition() {
# disable swap and all mounted partitions, umount / last!
_umountall
# activate dmraid
activate_dmraid
2009-04-17 22:29:31 +02:00
# check on encrypted devices, else weird things can happen!
_stopluks
2009-03-28 13:36:54 +01:00
# check on raid devices, else weird things can happen during partitioning!
_stopmd
# check on lvm devices, else weird things can happen during partitioning!
_stoplvm
2009-06-26 10:33:54 +02:00
# update dmraid
! [[ "$(dmraid_devices)" = "" ]] && _dmraid_update
2010-03-15 07:14:28 +01:00
# switch for mbr usage
set_guid
# Select disk to partition
DISCS=$(finddisks _)
2011-02-04 14:34:11 +01:00
DISCS="${DISCS} OTHER _ DONE +"
DIALOG --cr-wrap --msgbox "Available Disks:\n\n$(_getavaildisks)\n" 0 0
DISC=""
while true; do
# Prompt the user with a list of known disks
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select the disk you want to partition\n(select DONE when finished)" 14 55 7 ${DISCS} 2>${ANSWER} || return 1
DISC=$(cat ${ANSWER})
2012-01-09 13:54:09 +01:00
if [[ "${DISC}" == "OTHER" ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --inputbox "Enter the full path to the device you wish to partition" 8 65 "/dev/sda" 2>${ANSWER} || DISC=""
DISC=$(cat ${ANSWER})
fi
# Leave our loop if the user is done partitioning
2012-01-09 13:54:09 +01:00
[[ "${DISC}" == "DONE" ]] && break
MSDOS_DETECTED=""
2012-01-09 13:54:09 +01:00
if ! [[ "${DISC}" == "" ]]; then
if [[ "${GUIDPARAMETER}" == "yes" ]]; then
2012-06-25 11:34:07 +02:00
CHECK_BIOS_BOOT_GRUB=""
2012-04-24 18:50:27 +02:00
CHECK_UEFISYS_PART=""
RUN_CFDISK="1"
2011-09-12 21:38:58 +02:00
check_gpt
else
2012-04-23 15:17:42 +02:00
[[ "$(${_BLKID} -p -i -o value -s PTTYPE ${DISC})" == "dos" ]] && MSDOS_DETECTED="1"
2012-01-09 13:54:09 +01:00
if [[ "${MSDOS_DETECTED}" == "" ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --defaultno --yesno "Setup detected no MS-DOS partition table on ${DISC}.\nDo you want to create a MS-DOS partition table now on ${DISC}?\n\n${DISC} will be COMPLETELY ERASED! Are you absolutely sure?" 0 0 || return 1
# clean partitiontable to avoid issues!
2011-02-04 14:34:11 +01:00
dd if=/dev/zero of=${DEVICE} bs=512 count=2048 >/dev/null 2>&1
wipefs -a ${DEVICE} /dev/null 2>&1
2011-09-12 21:38:58 +02:00
parted -a optimal -s ${DISC} mktable msdos >${LOG}
fi
# Partition disc
DIALOG --msgbox "Now you'll be put into cfdisk where you can partition your storage drive. You should make a swap partition and as many data partitions as you will need." 18 70
clear
cfdisk ${DISC}
# reread partitiontable for kernel
partprobe ${DISC}
fi
fi
done
2009-06-26 10:33:54 +02:00
# update dmraid
_dmraid_update
2012-07-26 14:33:41 +02:00
NEXTITEM="4"
S_PART=1
2008-10-20 22:39:25 +02:00
}
2010-06-27 11:33:33 +02:00
# scan and update btrfs devices
btrfs_scan() {
btrfs device scan >/dev/null 2>&1
}
2010-06-26 21:41:17 +02:00
# mount btrfs for checks
mount_btrfs() {
btrfs_scan
BTRFSMP="$(mktemp -d /tmp/brtfsmp.XXXX)"
2011-02-04 14:34:11 +01:00
mount ${PART} ${BTRFSMP}
2010-06-26 21:41:17 +02:00
}
# unmount btrfs after checks done
umount_btrfs() {
2011-02-04 14:34:11 +01:00
umount ${BTRFSMP}
rm -r ${BTRFSMP}
2010-06-26 21:41:17 +02:00
}
# Set BTRFS_DEVICES on detected btrfs devices
find_btrfs_raid_devices() {
btrfs_scan
2011-02-04 14:34:11 +01:00
if [[ "${DETECT_CREATE_FILESYSTEM}" = "no" && "${FSTYPE}" = "btrfs" ]]; then
for i in $(btrfs filesystem show ${PART} | cut -d " " -f 11); do
BTRFS_DEVICES="${BTRFS_DEVICES}#${i}"
done
fi
}
2010-07-15 21:24:55 +02:00
find_btrfs_raid_bootloader_devices() {
btrfs_scan
BTRFS_COUNT=1
if [[ "$(${_LSBLK} FSTYPE ${bootdev})" = "btrfs" ]]; then
2010-07-15 21:24:55 +02:00
BTRFS_DEVICES=""
2011-02-04 14:34:11 +01:00
for i in $(btrfs filesystem show ${bootdev} | cut -d " " -f 11); do
BTRFS_DEVICES="${BTRFS_DEVICES}#${i}"
BTRFS_COUNT=$((${BTRFS_COUNT}+1))
2010-07-15 21:24:55 +02:00
done
fi
}
# find btrfs subvolume
find_btrfs_subvolume() {
2011-02-04 14:34:11 +01:00
if [[ "${DETECT_CREATE_FILESYSTEM}" = "no" ]]; then
# existing btrfs subvolumes
mount_btrfs
2014-04-12 13:47:34 +02:00
for i in $(btrfs subvolume list ${BTRFSMP} | cut -d " " -f 9); do
2011-02-04 14:34:11 +01:00
echo ${i}
[[ "${1}" ]] && echo ${1}
done
umount_btrfs
fi
}
find_btrfs_bootloader_subvolume() {
BTRFS_SUBVOLUME_COUNT=1
if [[ "$(${_LSBLK} FSTYPE ${bootdev})" = "btrfs" ]]; then
BTRFS_SUBVOLUMES=""
2011-02-04 14:34:11 +01:00
PART="${bootdev}"
mount_btrfs
2011-02-04 14:34:11 +01:00
for i in $(btrfs subvolume list ${BTRFSMP} | cut -d " " -f 7); do
BTRFS_SUBVOLUMES="${BTRFS_SUBVOLUMES}#${i}"
BTRFS_SUBVOLUME_COUNT=$((${BTRFS_COUNT}+1))
done
umount_btrfs
fi
}
# subvolumes already in use
subvolumes_in_use() {
SUBVOLUME_IN_USE=""
2011-02-04 14:34:11 +01:00
for i in $(grep ${PART}[:#] /tmp/.parts); do
if [[ "$(echo ${i} | grep ":btrfs:")" ]]; then
SUBVOLUME_IN_USE="${SUBVOLUME_IN_USE} $(echo ${i} | cut -d: -f 9)"
fi
done
}
# ask for btrfs compress option
btrfs_compress() {
BTRFS_COMPRESS="NONE"
2018-06-23 21:26:43 +02:00
BTRFS_COMPRESSLEVELS="lzo - zlib - zstd -"
2011-02-04 14:34:11 +01:00
if [[ "${BTRFS_SUBVOLUME}" = "NONE" ]]; then
2014-04-12 10:32:12 +02:00
DIALOG --yesno "Would you like to compress the data on ${PART}?" 0 0 && BTRFS_COMPRESS="compress"
else
2014-04-12 10:32:12 +02:00
DIALOG --yesno "Would you like to compress the data on ${PART} subvolume=${BTRFS_SUBVOLUME}?" 0 0 && BTRFS_COMPRESS="compress"
fi
2012-01-18 18:13:01 +01:00
if [[ "${BTRFS_COMPRESS}" = "compress" ]]; then
DIALOG --menu "Select the compression method you want to use" 21 50 9 ${BTRFS_COMPRESSLEVELS} 2>${ANSWER} || return 1
BTRFS_COMPRESS="compress=$(cat ${ANSWER})"
fi
}
2014-04-11 19:52:30 +02:00
# values that are needed for fs creation
clear_fs_values() {
: >/tmp/.btrfs-devices
2014-04-11 19:52:30 +02:00
DOMKFS="no"
LABEL_NAME=""
FS_OPTIONS=""
BTRFS_DEVICES=""
BTRFS_LEVEL=""
2014-04-11 19:52:30 +02:00
BTRFS_SUBVOLUME=""
DOSUBVOLUME=""
BTRFS_COMPRESS=""
}
# do not ask for btrfs filesystem creation, if already prepared for creation!
check_btrfs_filesystem_creation() {
DETECT_CREATE_FILESYSTEM="no"
SKIP_FILESYSTEM="no"
SKIP_ASK_SUBVOLUME="no"
2011-02-04 14:34:11 +01:00
for i in $(grep ${PART}[:#] /tmp/.parts); do
if [[ "$(echo ${i} | grep ":btrfs:")" ]]; then
FSTYPE="btrfs"
SKIP_FILESYSTEM="yes"
# check on filesystem creation, skip subvolume asking then!
2011-02-04 14:34:11 +01:00
[[ "$(echo ${i} | cut -d: -f 4 | grep yes)" ]] && DETECT_CREATE_FILESYSTEM="yes"
[[ "${DETECT_CREATE_FILESYSTEM}" = "yes" ]] && SKIP_ASK_SUBVOLUME="yes"
fi
done
}
# remove devices with no subvolume from list and generate raid device list
2010-06-29 07:44:46 +02:00
btrfs_parts() {
2011-02-03 21:54:43 +01:00
if [[ -s /tmp/.btrfs-devices ]]; then
BTRFS_DEVICES=""
2010-06-29 07:44:46 +02:00
for i in $(cat /tmp/.btrfs-devices); do
2011-02-04 14:34:11 +01:00
BTRFS_DEVICES="${BTRFS_DEVICES}#${i}"
2010-07-01 22:22:54 +02:00
# remove device if no subvolume is used!
2011-02-04 14:34:11 +01:00
[[ "${BTRFS_SUBVOLUME}" = "NONE" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${i}\ _##g")"
2010-06-29 07:44:46 +02:00
done
else
2011-02-04 14:34:11 +01:00
[[ "${BTRFS_SUBVOLUME}" = "NONE" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
2010-06-29 07:44:46 +02:00
fi
}
# choose raid level to use on btrfs device
2010-06-13 16:17:05 +02:00
btrfs_raid_level() {
2013-05-07 09:56:47 +02:00
BTRFS_RAIDLEVELS="NONE - raid0 - raid1 - raid5 - raid6 - raid10 - single -"
2010-06-13 16:17:05 +02:00
BTRFS_RAID_FINISH=""
BTRFS_LEVEL=""
2011-02-04 14:34:11 +01:00
BTRFS_DEVICE="${PART}"
2010-06-13 16:17:05 +02:00
: >/tmp/.btrfs-devices
2014-04-09 08:45:36 +02:00
DIALOG --msgbox "BTRFS DATA RAID OPTIONS:\n\nRAID5/6 are for testing purpose. Use with extreme care!\n\nIf you don't need this feature select NONE." 0 0
2011-02-04 14:34:11 +01:00
while [[ "${BTRFS_RAID_FINISH}" != "DONE" ]]; do
2014-04-09 08:45:36 +02:00
DIALOG --menu "Select the raid data level you want to use" 21 50 9 ${BTRFS_RAIDLEVELS} 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
BTRFS_LEVEL=$(cat ${ANSWER})
if [[ "${BTRFS_LEVEL}" = "NONE" ]]; then
echo "${BTRFS_DEVICE}" >>/tmp/.btrfs-devices
2010-06-13 16:17:05 +02:00
break
else
# take selected device as 1st device, add additional devices in part below.
select_btrfs_raid_devices
fi
done
}
# select btrfs raid devices
2010-06-12 18:30:33 +02:00
select_btrfs_raid_devices () {
# show all devices with sizes
# DIALOG --msgbox "DISKS:\n$(_getavaildisks)\n\nPARTITIONS:\n$(_getavailpartitions)" 0 0
# select the second device to use, no missing option available!
2010-07-02 07:30:29 +02:00
: >/tmp/.btrfs-devices
2011-02-04 14:34:11 +01:00
BTRFS_PART="${BTRFS_DEVICE}"
BTRFS_PARTS="${PARTS}"
echo "${BTRFS_PART}" >>/tmp/.btrfs-devices
BTRFS_PARTS="$(echo ${BTRFS_PARTS} | sed -e "s#${BTRFS_PART}\ _##g")"
2010-06-12 18:30:33 +02:00
RAIDNUMBER=2
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select device ${RAIDNUMBER}" 21 50 13 ${BTRFS_PARTS} 2>${ANSWER} || return 1
BTRFS_PART=$(cat ${ANSWER})
echo "${BTRFS_PART}" >>/tmp/.btrfs-devices
while [[ "${BTRFS_PART}" != "DONE" ]]; do
2010-06-12 18:30:33 +02:00
BTRFS_DONE=""
2011-02-04 14:34:11 +01:00
RAIDNUMBER=$((${RAIDNUMBER} + 1))
2013-05-07 09:56:47 +02:00
# RAID5 needs 3 devices
# RAID6, RAID10 need 4 devices!
[[ "${RAIDNUMBER}" -ge 3 && ! "${BTRFS_LEVEL}" = "raid10" && ! "${BTRFS_LEVEL}" = "raid6" && ! "${BTRFS_LEVEL}" = "raid5" ]] && BTRFS_DONE="DONE _"
[[ "${RAIDNUMBER}" -ge 4 && "${BTRFS_LEVEL}" = "raid5" ]] && BTRFS_DONE="DONE _"
[[ "${RAIDNUMBER}" -ge 5 && "${BTRFS_LEVEL}" = "raid10" || "${BTRFS_LEVEL}" = "raid6" ]] && BTRFS_DONE="DONE _"
2010-06-12 18:30:33 +02:00
# clean loop from used partition and options
2011-02-04 14:34:11 +01:00
BTRFS_PARTS="$(echo ${BTRFS_PARTS} | sed -e "s#${BTRFS_PART}\ _##g")"
2010-06-12 18:30:33 +02:00
# add more devices
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select device ${RAIDNUMBER}" 21 50 13 ${BTRFS_PARTS} ${BTRFS_DONE} 2>${ANSWER} || return 1
BTRFS_PART=$(cat ${ANSWER})
[[ "${BTRFS_PART}" = "DONE" ]] && break
echo "${BTRFS_PART}" >>/tmp/.btrfs-devices
2010-06-12 18:30:33 +02:00
done
# final step ask if everything is ok?
2014-04-09 09:21:15 +02:00
DIALOG --yesno "Would you like to create btrfs raid data like this?\n\nLEVEL:\n${BTRFS_LEVEL}\n\nDEVICES:\n$(for i in $(cat /tmp/.btrfs-devices); do echo "${i}\n"; done)" 0 0 && BTRFS_RAID_FINISH="DONE"
2010-06-12 18:30:33 +02:00
}
# prepare new btrfs device
prepare_btrfs() {
2010-07-04 17:35:42 +02:00
btrfs_raid_level || return 1
prepare_btrfs_subvolume || return 1
2010-06-20 22:18:53 +02:00
}
# prepare btrfs subvolume
2010-06-21 22:30:50 +02:00
prepare_btrfs_subvolume() {
2010-06-28 20:49:46 +02:00
DOSUBVOLUME="no"
2010-07-15 07:47:14 +02:00
BTRFS_SUBVOLUME="NONE"
2011-02-04 14:34:11 +01:00
if [[ "${SKIP_ASK_SUBVOLUME}" = "no" ]]; then
DIALOG --defaultno --yesno "Would you like to create a new subvolume on ${PART}?" 0 0 && DOSUBVOLUME="yes"
2010-07-01 11:09:06 +02:00
else
DOSUBVOLUME="yes"
fi
2011-02-04 14:34:11 +01:00
if [[ "${DOSUBVOLUME}" = "yes" ]]; then
2010-07-15 19:04:22 +02:00
BTRFS_SUBVOLUME="NONE"
2011-02-04 14:34:11 +01:00
while [[ "${BTRFS_SUBVOLUME}" = "NONE" ]]; do
DIALOG --inputbox "Enter the SUBVOLUME name for the device, keep it short\nand use no spaces or special\ncharacters." 10 65 2>${ANSWER} || return 1
BTRFS_SUBVOLUME=$(cat ${ANSWER})
2010-06-20 22:18:53 +02:00
check_btrfs_subvolume
done
else
BTRFS_SUBVOLUME="NONE"
fi
2010-06-20 19:00:41 +02:00
}
# check btrfs subvolume
check_btrfs_subvolume(){
2011-02-04 14:34:11 +01:00
[[ "${DOMKFS}" = "yes" && "${FSTYPE}" = "btrfs" ]] && DETECT_CREATE_FILESYSTEM="yes"
if [[ "${DETECT_CREATE_FILESYSTEM}" = "no" ]]; then
mount_btrfs
2011-02-04 14:34:11 +01:00
for i in $(btrfs subvolume list ${BTRFSMP} | cut -d " " -f 7); do
if [[ "$(echo ${i} | grep "${BTRFS_SUBVOLUME}"$)" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical SUBVOLUME names or an empty name! Please enter another name." 8 65
2010-07-15 07:47:14 +02:00
BTRFS_SUBVOLUME="NONE"
fi
done
umount_btrfs
else
subvolumes_in_use
2011-02-04 14:34:11 +01:00
if [[ "$(echo ${SUBVOLUME_IN_USE} | egrep "${BTRFS_SUBVOLUME}")" ]]; then
DIALOG --msgbox "ERROR: You have defined 2 identical SUBVOLUME names or an empty name! Please enter another name." 8 65
2010-07-15 07:47:14 +02:00
BTRFS_SUBVOLUME="NONE"
fi
fi
2010-06-25 22:21:17 +02:00
}
# create btrfs subvolume
2010-06-21 22:30:50 +02:00
create_btrfs_subvolume() {
2010-06-26 21:41:17 +02:00
mount_btrfs
2011-02-04 14:34:11 +01:00
btrfs subvolume create ${BTRFSMP}/${_btrfssubvolume} >${LOG}
2010-07-04 21:35:10 +02:00
# change permission from 700 to 755
# to avoid warnings during package installation
2011-02-04 14:34:11 +01:00
chmod 755 ${BTRFSMP}/${_btrfssubvolume}
2010-06-26 21:41:17 +02:00
umount_btrfs
2010-06-21 22:30:50 +02:00
}
# choose btrfs subvolume from list
2010-06-12 18:30:33 +02:00
choose_btrfs_subvolume () {
2010-06-27 23:04:56 +02:00
BTRFS_SUBVOLUME="NONE"
SUBVOLUMES_DETECTED="no"
2010-06-25 22:21:17 +02:00
SUBVOLUMES=$(find_btrfs_subvolume _)
# check if subvolumes are present
2011-02-04 14:34:11 +01:00
[[ -n "${SUBVOLUMES}" ]] && SUBVOLUMES_DETECTED="yes"
2010-07-01 12:09:25 +02:00
subvolumes_in_use
2011-02-04 14:34:11 +01:00
for i in ${SUBVOLUME_IN_USE}; do
SUBVOLUMES=$(echo ${SUBVOLUMES} | sed -e "s#${i}\ _##g")
2010-07-01 12:09:25 +02:00
done
2012-01-09 13:54:09 +01:00
if [[ -n "${SUBVOLUMES}" ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select the subvolume to mount" 21 50 13 ${SUBVOLUMES} 2>${ANSWER} || return 1
BTRFS_SUBVOLUME=$(cat ${ANSWER})
else
2011-02-04 14:34:11 +01:00
if [[ "${SUBVOLUMES_DETECTED}" = "yes" ]]; then
DIALOG --msgbox "ERROR: All subvolumes of the device are already in use. Switching to create a new one now." 8 65
SKIP_ASK_SUBVOLUME=yes
prepare_btrfs_subvolume || return 1
fi
2010-06-27 23:04:56 +02:00
fi
2010-06-12 18:30:33 +02:00
}
# btrfs subvolume menu
btrfs_subvolume() {
FILESYSTEM_FINISH=""
2011-02-04 14:34:11 +01:00
if [[ "${FSTYPE}" = "btrfs" && "${DOMKFS}" = "no" ]]; then
if [[ "${ASK_MOUNTPOINTS}" = "1" ]]; then
# create subvolume if requested
# choose btrfs subvolume if present
prepare_btrfs_subvolume || return 1
2011-02-04 14:34:11 +01:00
if [[ "${BTRFS_SUBVOLUME}" = "NONE" ]]; then
choose_btrfs_subvolume || return 1
fi
else
# use device if no subvolume is present
choose_btrfs_subvolume || return 1
fi
btrfs_compress
fi
FILESYSTEM_FINISH="yes"
}
2018-06-23 21:29:26 +02:00
# add ssd mount options
ssd_optimization() {
# ext4, jfs, xfs, btrfs, nilfs2, f2fs have ssd mount option support
2014-04-25 21:24:49 +02:00
ssd_mount_options=""
if [[ "$(echo ${_fstype} | egrep 'ext4|jfs|btrfs|xfs|nilfs2|f2fs')" ]]; then
# check all underlying devices on ssd
for i in $(${_LSBLK} NAME,TYPE ${device} -s | grep "disk$" | cut -d' ' -f 1); do
# check for ssd
if [[ "$(cat /sys/block/$(basename ${i})/queue/rotational)" == "0" ]]; then
ssd_mount_options="noatime"
fi
done
fi
}
select_filesystem() {
2010-06-27 23:04:56 +02:00
FILESYSTEM_FINISH=""
2010-08-19 09:01:41 +02:00
# don't allow vfat as / filesystem, it will not work!
# don't allow ntfs as / filesystem, this is stupid!
FSOPTS=""
2011-02-04 14:34:11 +01:00
[[ "$(which mkfs.ext2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext2 Ext2"
[[ "$(which mkfs.ext3 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext3 Ext3"
[[ "$(which mkfs.ext4 2>/dev/null)" ]] && FSOPTS="${FSOPTS} ext4 Ext4"
[[ "$(which mkfs.btrfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} btrfs Btrfs"
[[ "$(which mkfs.nilfs2 2>/dev/null)" ]] && FSOPTS="${FSOPTS} nilfs2 Nilfs2"
[[ "$(which mkfs.f2fs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} f2fs F2FS"
2011-02-04 14:34:11 +01:00
[[ "$(which mkreiserfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} reiserfs Reiser3"
[[ "$(which mkfs.xfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} xfs XFS"
[[ "$(which mkfs.jfs 2>/dev/null)" ]] && FSOPTS="${FSOPTS} jfs JFS"
2021-11-13 08:51:53 +01:00
[[ "$(which mkfs.ntfs 2>/dev/null)" && "${DO_ROOT}" = "DONE" ]] && FSOPTS="${FSOPTS} ntfs3 NTFS"
2021-09-16 07:21:39 +02:00
[[ "$(which mkfs.vfat 2>/dev/null)" && "${DO_ROOT}" = "DONE" ]] && FSOPTS="${FSOPTS} vfat FAT32"
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select a filesystem for ${PART}" 21 50 13 ${FSOPTS} 2>${ANSWER} || return 1
FSTYPE=$(cat ${ANSWER})
}
enter_mountpoint() {
2010-06-27 23:04:56 +02:00
FILESYSTEM_FINISH=""
MP=""
2011-02-04 14:34:11 +01:00
while [[ "${MP}" = "" ]]; do
DIALOG --inputbox "Enter the mountpoint for ${PART}" 8 65 "/boot" 2>${ANSWER} || return 1
MP=$(cat ${ANSWER})
if grep ":${MP}:" /tmp/.parts; then
DIALOG --msgbox "ERROR: You have defined 2 identical mountpoints! Please select another mountpoint." 8 65
MP=""
fi
done
}
# set sane values for paramaters, if not already set
2010-06-27 11:33:33 +02:00
check_mkfs_values() {
# Set values, to not confuse mkfs call!
2011-02-04 14:34:11 +01:00
[[ "${FS_OPTIONS}" = "" ]] && FS_OPTIONS="NONE"
[[ "${BTRFS_DEVICES}" = "" ]] && BTRFS_DEVICES="NONE"
[[ "${BTRFS_LEVEL}" = "" ]] && BTRFS_LEVEL="NONE"
[[ "${BTRFS_SUBVOLUME}" = "" ]] && BTRFS_SUBVOLUME="NONE"
[[ "${DOSUBVOLUME}" = "" ]] && DOSUBVOLUME="no"
[[ "${LABEL_NAME}" = "" && -n "$(${_LSBLK} LABEL ${PART})" ]] && LABEL_NAME="$(${_LSBLK} LABEL ${PART})"
2011-02-04 14:34:11 +01:00
[[ "${LABEL_NAME}" = "" ]] && LABEL_NAME="NONE"
2010-06-27 11:33:33 +02:00
}
2010-06-12 18:30:33 +02:00
create_filesystem() {
2010-06-28 20:49:46 +02:00
FILESYSTEM_FINISH=""
2010-06-12 18:30:33 +02:00
LABEL_NAME=""
2010-06-25 22:21:17 +02:00
FS_OPTIONS=""
BTRFS_DEVICES=""
BTRFS_LEVEL=""
2011-02-04 14:34:11 +01:00
DIALOG --yesno "Would you like to create a filesystem on ${PART}?\n\n(This will overwrite existing data!)" 0 0 && DOMKFS="yes"
if [[ "${DOMKFS}" = "yes" ]]; then
while [[ "${LABEL_NAME}" = "" ]]; do
2010-06-12 18:30:33 +02:00
DIALOG --inputbox "Enter the LABEL name for the device, keep it short\n(not more than 12 characters) and use no spaces or special\ncharacters." 10 65 \
"$(${_LSBLK} LABEL ${PART})" 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
LABEL_NAME=$(cat ${ANSWER})
if grep ":${LABEL_NAME}$" /tmp/.parts; then
2010-06-12 18:30:33 +02:00
DIALOG --msgbox "ERROR: You have defined 2 identical LABEL names! Please enter another name." 8 65
LABEL_NAME=""
fi
done
2011-02-04 14:34:11 +01:00
if [[ "${FSTYPE}" = "btrfs" ]]; then
2010-06-13 16:17:05 +02:00
prepare_btrfs || return 1
btrfs_compress
2010-06-12 18:30:33 +02:00
fi
2011-02-04 14:34:11 +01:00
DIALOG --inputbox "Enter additional options to the filesystem creation utility.\nUse this field only, if the defaults are not matching your needs,\nelse just leave it empty." 10 70 2>${ANSWER} || return 1
FS_OPTIONS=$(cat ${ANSWER})
2010-06-25 22:21:17 +02:00
fi
2010-06-28 20:49:46 +02:00
FILESYSTEM_FINISH="yes"
2010-06-12 18:30:33 +02:00
}
2008-10-20 22:39:25 +02:00
mountpoints() {
2010-05-24 15:39:55 +02:00
NAME_SCHEME_PARAMETER_RUN=""
2011-02-04 14:34:11 +01:00
while [[ "${PARTFINISH}" != "DONE" ]]; do
2010-05-18 23:52:30 +02:00
activate_special_devices
: >/tmp/.device-names
: >/tmp/.fstab
: >/tmp/.parts
#
# Select mountpoints
#
DIALOG --cr-wrap --msgbox "Available partitions:\n\n$(_getavailpartitions)\n" 0 0
PARTS=$(findpartitions _)
2010-05-25 16:33:02 +02:00
DO_SWAP=""
2011-02-04 14:34:11 +01:00
while [[ "${DO_SWAP}" != "DONE" ]]; do
2010-06-28 22:40:35 +02:00
FSTYPE="swap"
2011-02-04 14:34:11 +01:00
DIALOG --menu "Select the partition to use as swap" 21 50 13 NONE - ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
if [[ "${PART}" != "NONE" ]]; then
2014-04-11 19:52:30 +02:00
clear_fs_values
2011-02-04 14:34:11 +01:00
if [[ "${ASK_MOUNTPOINTS}" = "1" ]]; then
create_filesystem
else
2010-06-27 23:04:56 +02:00
FILESYSTEM_FINISH="yes"
fi
else
2010-06-27 23:04:56 +02:00
FILESYSTEM_FINISH="yes"
2010-05-25 16:33:02 +02:00
fi
2011-02-04 14:34:11 +01:00
[[ "${FILESYSTEM_FINISH}" = "yes" ]] && DO_SWAP=DONE
2010-05-25 16:33:02 +02:00
done
2010-06-28 20:49:46 +02:00
check_mkfs_values
2011-02-04 14:34:11 +01:00
if [[ "${PART}" != "NONE" ]]; then
PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
echo "${PART}:swap:swap:${DOMKFS}:${LABEL_NAME}:${FS_OPTIONS}:${BTRFS_DEVICES}:${BTRFS_LEVEL}:${BTRFS_SUBVOLUME}:${DOSUBVOLUME}:${BTRFS_COMPRESS}" >>/tmp/.parts
fi
2010-05-25 16:33:02 +02:00
DO_ROOT=""
2011-02-04 14:34:11 +01:00
while [[ "${DO_ROOT}" != "DONE" ]]; do
DIALOG --menu "Select the partition to mount as /" 21 50 13 ${PARTS} 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
PART_ROOT=${PART}
2010-05-25 16:33:02 +02:00
# Select root filesystem type
FSTYPE="$(${_LSBLK} FSTYPE ${PART})"
# clear values first!
2014-04-11 19:52:30 +02:00
clear_fs_values
check_btrfs_filesystem_creation
2011-02-04 14:34:11 +01:00
if [[ "${ASK_MOUNTPOINTS}" = "1" && "${SKIP_FILESYSTEM}" = "no" ]]; then
2010-06-27 23:04:56 +02:00
select_filesystem && create_filesystem && btrfs_subvolume
else
2010-06-27 11:33:33 +02:00
btrfs_subvolume
2010-05-25 16:33:02 +02:00
fi
2011-02-04 14:34:11 +01:00
[[ "${FILESYSTEM_FINISH}" = "yes" ]] && DO_ROOT=DONE
2010-05-25 16:33:02 +02:00
done
find_btrfs_raid_devices
2010-06-30 23:06:36 +02:00
btrfs_parts
check_mkfs_values
echo "${PART}:${FSTYPE}:/:${DOMKFS}:${LABEL_NAME}:${FS_OPTIONS}:${BTRFS_DEVICES}:${BTRFS_LEVEL}:${BTRFS_SUBVOLUME}:${DOSUBVOLUME}:${BTRFS_COMPRESS}" >>/tmp/.parts
2011-02-04 14:34:11 +01:00
! [[ "${FSTYPE}" = "btrfs" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
#
# Additional partitions
#
2011-02-04 14:34:11 +01:00
while [[ "${PART}" != "DONE" ]]; do
DO_ADDITIONAL=""
2011-02-04 14:34:11 +01:00
while [[ "${DO_ADDITIONAL}" != "DONE" ]]; do
DIALOG --menu "Select any additional partitions to mount under your new root (select DONE when finished)" 21 52 13 ${PARTS} DONE _ 2>${ANSWER} || return 1
PART=$(cat ${ANSWER})
if [[ "${PART}" != "DONE" ]]; then
FSTYPE="$(${_LSBLK} FSTYPE ${PART})"
# clear values first!
2014-04-11 19:52:30 +02:00
clear_fs_values
check_btrfs_filesystem_creation
# Select a filesystem type
2011-02-04 14:34:11 +01:00
if [[ "${ASK_MOUNTPOINTS}" = "1" && "${SKIP_FILESYSTEM}" = "no" ]]; then
2010-06-27 23:04:56 +02:00
enter_mountpoint && select_filesystem && create_filesystem && btrfs_subvolume
else
enter_mountpoint
btrfs_subvolume
fi
else
2010-06-27 23:04:56 +02:00
FILESYSTEM_FINISH="yes"
fi
2011-02-04 14:34:11 +01:00
[[ "${FILESYSTEM_FINISH}" = "yes" ]] && DO_ADDITIONAL="DONE"
done
2011-02-04 14:34:11 +01:00
if [[ "${PART}" != "DONE" ]]; then
find_btrfs_raid_devices
2010-06-30 23:06:36 +02:00
btrfs_parts
check_mkfs_values
echo "${PART}:${FSTYPE}:${MP}:${DOMKFS}:${LABEL_NAME}:${FS_OPTIONS}:${BTRFS_DEVICES}:${BTRFS_LEVEL}:${BTRFS_SUBVOLUME}:${DOSUBVOLUME}:${BTRFS_COMPRESS}" >>/tmp/.parts
2011-02-04 14:34:11 +01:00
! [[ "${FSTYPE}" = "btrfs" ]] && PARTS="$(echo ${PARTS} | sed -e "s#${PART}\ _##g")"
fi
done
2011-02-04 14:34:11 +01:00
DIALOG --yesno "Would you like to create and mount the filesytems like this?\n\nSyntax\n------\nDEVICE:TYPE:MOUNTPOINT:FORMAT:LABEL:FSOPTIONS:BTRFS_DETAILS\n\n$(for i in $(cat /tmp/.parts | sed -e 's, ,#,g'); do echo "${i}\n";done)" 0 0 && PARTFINISH="DONE"
done
# disable swap and all mounted partitions
_umountall
2011-02-04 14:34:11 +01:00
if [[ "${NAME_SCHEME_PARAMETER_RUN}" = "" ]]; then
set_device_name_scheme || return 1
fi
2012-08-14 13:48:48 +02:00
printk off
for line in $(cat /tmp/.parts); do
2011-02-04 14:34:11 +01:00
PART=$(echo ${line} | cut -d: -f 1)
FSTYPE=$(echo ${line} | cut -d: -f 2)
MP=$(echo ${line} | cut -d: -f 3)
DOMKFS=$(echo ${line} | cut -d: -f 4)
LABEL_NAME=$(echo ${line} | cut -d: -f 5)
FS_OPTIONS=$(echo ${line} | cut -d: -f 6)
BTRFS_DEVICES=$(echo ${line} | cut -d: -f 7)
BTRFS_LEVEL=$(echo ${line} | cut -d: -f 8)
BTRFS_SUBVOLUME=$(echo ${line} | cut -d: -f 9)
DOSUBVOLUME=$(echo ${line} | cut -d: -f 10)
BTRFS_COMPRESS=$(echo ${line} | cut -d: -f 11)
if [[ "${DOMKFS}" = "yes" ]]; then
if [[ "${FSTYPE}" = "swap" ]]; then
DIALOG --infobox "Creating and activating swapspace on ${PART}" 0 0
else
2012-06-06 14:33:30 +02:00
DIALOG --infobox "Creating ${FSTYPE} on ${PART},\nmounting to ${DESTDIR}${MP}" 0 0
fi
_mkfs yes ${PART} ${FSTYPE} ${DESTDIR} ${MP} ${LABEL_NAME} ${FS_OPTIONS} ${BTRFS_DEVICES} ${BTRFS_LEVEL} ${BTRFS_SUBVOLUME} ${DOSUBVOLUME} ${BTRFS_COMPRESS} || return 1
else
2011-02-04 14:34:11 +01:00
if [[ "${FSTYPE}" = "swap" ]]; then
DIALOG --infobox "Activating swapspace on ${PART}" 0 0
else
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Mounting ${FSTYPE} on ${PART} to ${DESTDIR}${MP}" 0 0
fi
_mkfs no ${PART} ${FSTYPE} ${DESTDIR} ${MP} ${LABEL_NAME} ${FS_OPTIONS} ${BTRFS_DEVICES} ${BTRFS_LEVEL} ${BTRFS_SUBVOLUME} ${DOSUBVOLUME} ${BTRFS_COMPRESS} || return 1
fi
sleep 1
done
2012-08-14 13:48:48 +02:00
printk on
DIALOG --msgbox "Partitions were successfully mounted." 0 0
2012-08-14 13:29:06 +02:00
NEXTITEM="5"
S_MKFS=1
2008-10-20 22:39:25 +02:00
}
2010-06-13 16:17:05 +02:00
# _mkfs()
# Create and mount filesystems in our destination system directory.
#
# args:
# domk: Whether to make the filesystem or use what is already there
# device: Device filesystem is on
# fstype: type of filesystem located at the device (or what to create)
# dest: Mounting location for the destination system
# mountpoint: Mount point inside the destination system, e.g. '/boot'
# returns: 1 on failure
_mkfs() {
2011-02-04 14:34:11 +01:00
local _domk=${1}
local _device=${2}
local _fstype=${3}
local _dest=${4}
local _mountpoint=${5}
local _labelname=${6}
local _fsoptions=${7}
local _btrfsdevices="$(echo ${8} | sed -e 's|#| |g')"
local _btrfslevel=${9}
2011-02-10 17:25:27 +01:00
local _btrfssubvolume=${10}
2010-06-28 20:49:46 +02:00
local _dosubvolume=${11}
local _btrfscompress=${12}
2010-06-20 19:00:41 +02:00
# correct empty entries
2011-02-04 14:34:11 +01:00
[[ "${_fsoptions}" = "NONE" ]] && _fsoptions=""
[[ "${_btrfscompress}" = "NONE" ]] && _btrfscompress=""
[[ "${_btrfssubvolume}" = "NONE" ]] && _btrfssubvolume=""
2010-06-20 19:00:41 +02:00
# add btrfs raid level, if needed
2015-01-15 14:52:34 +01:00
[[ ! "${_btrfslevel}" = "NONE" && "${_fstype}" = "btrfs" ]] && _fsoptions="${_fsoptions} -m ${_btrfslevel} -d ${_btrfslevel}"
# add btrfs options, minimum requirement linux 3.14 -O no-holes
[[ "${_fstype}" = "btrfs" ]] && _fsoptions="${_fsoptions} -O no-holes"
2010-06-13 16:17:05 +02:00
# we have two main cases: "swap" and everything else.
2011-02-04 14:34:11 +01:00
if [[ "${_fstype}" = "swap" ]]; then
swapoff ${_device} >/dev/null 2>&1
if [[ "${_domk}" = "yes" ]]; then
mkswap -L ${_labelname} ${_device} >${LOG} 2>&1
2011-02-03 21:54:43 +01:00
if [[ $? != 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error creating swap: mkswap ${_device}" 0 0
2010-06-13 16:17:05 +02:00
return 1
fi
fi
2011-02-04 14:34:11 +01:00
swapon ${_device} >${LOG} 2>&1
2011-02-03 21:54:43 +01:00
if [[ $? != 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error activating swap: swapon ${_device}" 0 0
2010-06-13 16:17:05 +02:00
return 1
fi
else
# make sure the fstype is one we can handle
local knownfs=0
2021-11-13 08:51:53 +01:00
for fs in xfs jfs reiserfs ext2 ext3 ext4 f2fs btrfs nilfs2 ntfs3 vfat; do
2011-02-04 14:34:11 +01:00
[[ "${_fstype}" = "${fs}" ]] && knownfs=1 && break
2010-06-13 16:17:05 +02:00
done
2011-02-04 14:34:11 +01:00
if [[ ${knownfs} -eq 0 ]]; then
DIALOG --msgbox "unknown fstype ${_fstype} for ${_device}" 0 0
2010-06-13 16:17:05 +02:00
return 1
fi
# if we were tasked to create the filesystem, do so
2011-02-04 14:34:11 +01:00
if [[ "${_domk}" = "yes" ]]; then
2010-06-13 16:17:05 +02:00
local ret
2011-02-04 14:34:11 +01:00
case ${_fstype} in
xfs) mkfs.xfs ${_fsoptions} -L ${_labelname} -f ${_device} >${LOG} 2>&1; ret=$? ;;
jfs) yes | mkfs.jfs ${_fsoptions} -L ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
reiserfs) yes | mkreiserfs ${_fsoptions} -l ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
2014-06-04 09:45:24 +02:00
ext2) mkfs.ext2 -F -L ${_fsoptions} ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
ext3) mke2fs -F ${_fsoptions} -L ${_labelname} -t ext3 ${_device} >${LOG} 2>&1; ret=$? ;;
ext4) mke2fs -F ${_fsoptions} -L ${_labelname} -t ext4 ${_device} >${LOG} 2>&1; ret=$? ;;
2013-06-03 17:31:11 +02:00
f2fs) mkfs.f2fs ${_fsoptions} -l ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
btrfs) mkfs.btrfs -f ${_fsoptions} -L ${_labelname} ${_btrfsdevices} >${LOG} 2>&1; ret=$? ;;
2013-10-19 12:57:35 +02:00
nilfs2) mkfs.nilfs2 -f ${_fsoptions} -L ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
2021-11-13 08:51:53 +01:00
ntfs3) mkfs.ntfs ${_fsoptions} -L ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
vfat) mkfs.vfat -F32 ${_fsoptions} -n ${_labelname} ${_device} >${LOG} 2>&1; ret=$? ;;
2010-06-13 16:17:05 +02:00
# don't handle anything else here, we will error later
esac
2011-02-04 14:34:11 +01:00
if [[ ${ret} != 0 ]]; then
DIALOG --msgbox "Error creating filesystem ${_fstype} on ${_device}" 0 0
2010-06-13 16:17:05 +02:00
return 1
fi
sleep 2
fi
2011-02-04 14:34:11 +01:00
if [[ "${_fstype}" = "btrfs" && -n "${_btrfssubvolume}" && "${_dosubvolume}" = "yes" ]]; then
2010-06-28 20:49:46 +02:00
create_btrfs_subvolume
fi
btrfs_scan
2010-06-29 07:39:07 +02:00
sleep 2
2010-06-13 16:17:05 +02:00
# create our mount directory
2011-02-04 14:34:11 +01:00
mkdir -p ${_dest}${_mountpoint}
# add ssd optimization before mounting
ssd_optimization
_mountoptions=""
2010-06-25 22:21:17 +02:00
# prepare btrfs mount options
[[ -n "${_btrfssubvolume}" ]] && _mountoptions="${_mountoptions} subvol=${_btrfssubvolume}"
[[ -n "${_btrfscompress}" ]] && _mountoptions="${_mountoptions} ${_btrfscompress}"
_mountoptions="${_mountoptions} ${ssd_mount_options}"
# eleminate spaces at beginning and end, replace other spaces with ,
_mountoptions="$(echo ${_mountoptions} | sed -e 's#^ *##g' -e 's# *$##g' | sed -e 's# #,#g')"
2010-06-13 16:17:05 +02:00
# mount the bad boy
mount -t ${_fstype} -o "${_mountoptions}" ${_device} ${_dest}${_mountpoint} >${LOG} 2>&1
2011-02-03 21:54:43 +01:00
if [[ $? != 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Error mounting ${_dest}${_mountpoint}" 0 0
2010-06-13 16:17:05 +02:00
return 1
fi
2015-01-15 18:10:16 +01:00
# btrfs needs balancing, else weird things could happen
[[ "${_fstype}" = "btrfs" ]] && btrfs balance start --full-balance ${_dest}${_mountpoint} >${LOG} 2>&1
# change permission of base directories to correct permission
# to avoid btrfs issues
2011-02-04 14:34:11 +01:00
if [[ "${_mountpoint}" = "/tmp" ]]; then
chmod 1777 ${_dest}${_mountpoint}
elif [[ "${_mountpoint}" = "/root" ]]; then
chmod 750 ${_dest}${_mountpoint}
else
2011-02-04 14:34:11 +01:00
chmod 755 ${_dest}${_mountpoint}
fi
2010-06-13 16:17:05 +02:00
fi
2011-02-08 09:45:49 +01:00
# add to .device-names for config files
2012-04-20 15:40:38 +02:00
local _fsuuid="$(getfsuuid ${_device})"
local _fslabel="$(getfslabel ${_device})"
2012-10-08 17:55:28 +02:00
if [[ "${GUID_DETECTED}" == "1" ]]; then
local _partuuid="$(getpartuuid ${_device})"
local _partlabel="$(getpartlabel ${_device})"
echo "# DEVICE DETAILS: ${_device} PARTUUID=${_partuuid} PARTLABEL=${_partlabel} UUID=${_fsuuid} LABEL=${_fslabel}" >> /tmp/.device-names
else
echo "# DEVICE DETAILS: ${_device} UUID=${_fsuuid} LABEL=${_fslabel}" >> /tmp/.device-names
fi
2010-06-13 16:17:05 +02:00
# add to temp fstab
if [[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]]; then
if [[ -n "${_fsuuid}" ]]; then
_device="UUID=${_fsuuid}"
2010-06-13 16:17:05 +02:00
fi
elif [[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]]; then
if [[ -n "${_fslabel}" ]]; then
_device="LABEL=${_fslabel}"
2010-06-13 16:17:05 +02:00
fi
2012-10-08 17:55:28 +02:00
else
if [[ "${GUID_DETECTED}" == "1" ]]; then
if [[ "${NAME_SCHEME_PARAMETER}" == "PARTUUID" ]]; then
if [[ -n "${_partuuid}" ]]; then
_device="PARTUUID=${_partuuid}"
fi
elif [[ "${NAME_SCHEME_PARAMETER}" == "PARTLABEL" ]]; then
if [[ -n "${_partlabel}" ]]; then
_device="PARTLABEL=${_partlabel}"
fi
fi
fi
2010-06-13 16:17:05 +02:00
fi
# / root is not needed in fstab, it's mounted automatically
# systemd supports detection on GPT disks:
# /boot as ESP: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
# swap: 0657fd6d-a4ab-43c4-84e5-0933c84b4f4f
# /home: 933ac7e1-2eb4-4f13-b844-0e14e2aef915
# Complex devices, like mdadm, encrypt or lvm are not supported
# _GUID_VALUE:
# get real device name from lsblk first to get GUID_VALUE from blkid
_GUID_VALUE="$(${_BLKID} -p -i -s PART_ENTRY_TYPE -o value $(${_LSBLK} NAME,UUID,LABEL,PARTLABEL,PARTUUID | grep $(echo ${_device} | cut -d"=" -f2) | cut -d" " -f 1))"
if ! [[ "${_GUID_VALUE}" == "933ac7e1-2eb4-4f13-b844-0e14e2aef915" && "${_mountpoint}" == "/home" || "${_GUID_VALUE}" == "0657fd6d-a4ab-43c4-84e5-0933c84b4f4f" && "${_mountpoint}" == "swap" || "${_GUID_VALUE}" == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" && "${_mountpoint}" == "/boot" && "${_DETECTED_UEFI_BOOT}" == "1" || "${_mountpoint}" == "/" ]]; then
if [[ "${_mountoptions}" == "" ]]; then
echo -n "${_device} ${_mountpoint} ${_fstype} defaults 0 " >>/tmp/.fstab
else
echo -n "${_device} ${_mountpoint} ${_fstype} defaults,${_mountoptions} 0 " >>/tmp/.fstab
fi
2014-04-10 16:19:25 +02:00
if [[ "${_fstype}" = "swap" || "${_fstype}" = "btrfs" ]]; then
echo "0" >>/tmp/.fstab
else
echo "1" >>/tmp/.fstab
fi
2010-06-13 16:17:05 +02:00
fi
2018-06-25 15:51:41 +02:00
unset _mountoptions
unset _btrfssubvolume
unset _btrfscompress
2010-06-13 16:17:05 +02:00
}
2008-10-20 22:39:25 +02:00
getsource() {
S_SRC=0
if [[ "${MODE}" = "network" ]]; then
2010-08-11 12:17:29 +02:00
select_mirror || return 1
fi
S_SRC=1
2008-10-20 22:39:25 +02:00
}
# select_mirror()
2011-02-04 14:34:11 +01:00
# Prompt user for preferred mirror and set ${SYNC_URL}
2008-10-20 22:39:25 +02:00
#
# args: none
# returns: nothing
select_mirror() {
NEXTITEM="4"
## Download updated mirrorlist, if possible (only on x86_64)
if [[ "${RUNNING_ARCH}" == "x86_64" ]]; then
dialog --infobox "Downloading latest mirrorlist ..." 0 0
${DLPROG} -q "https://www.archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on" -O /tmp/pacman_mirrorlist.txt -o ${LOG} 2>/dev/null
if [[ "$(grep '#Server = http:' /tmp/pacman_mirrorlist.txt)" ]]; then
mv "${MIRRORLIST}" "${MIRRORLIST}.bak"
cp /tmp/pacman_mirrorlist.txt "${MIRRORLIST}"
fi
fi
# FIXME: this regex doesn't honor commenting
2013-07-12 10:57:02 +02:00
MIRRORS=$(egrep -o '((http)|(https))://[^/]*' "${MIRRORLIST}" | sed 's|$| _|g')
DIALOG --menu "Select a mirror" 14 55 7 \
2011-02-04 14:34:11 +01:00
${MIRRORS} \
"Custom" "_" 2>${ANSWER} || return 1
local _server=$(cat ${ANSWER})
if [[ "${_server}" = "Custom" ]]; then
2013-07-12 10:57:02 +02:00
DIALOG --inputbox "Enter the full URL to repositories." 8 65 \
"" 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
SYNC_URL=$(cat ${ANSWER})
else
# Form the full URL for our mirror by grepping for the server name in
# our mirrorlist and pulling the full URL out. Substitute 'core' in
# for the repository name, and ensure that if it was listed twice we
# only return one line for the mirror.
2011-02-04 14:34:11 +01:00
SYNC_URL=$(egrep -o "${_server}.*" "${MIRRORLIST}" | head -n1)
fi
2011-02-04 14:34:11 +01:00
echo "Using mirror: ${SYNC_URL}" >${LOG}
2022-01-08 20:34:12 +01:00
echo "Server = "${SYNC_URL}"" >> /etc/pacman.d/mirrorlist
if [[ "${DOTESTING}" == "yes" ]]; then
echo "[testing]" >> /etc/pacman.conf
echo "Include = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
echo "[community-testing]" >> /etc/pacman.conf
echo "Include = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
fi
2008-10-20 22:39:25 +02:00
}
# dotesting()
# enable testing repository on network install
dotesting() {
DOTESTING=""
DIALOG --defaultno --yesno "Do you want to enable [testing] repository?\n\nOnly enable this if you need latest available packages for testing purposes!" 8 60 && DOTESTING="yes"
}
2010-02-22 07:40:53 +01:00
# configures pacman and syncs db on destination system
# params: none
# returns: 1 on error
prepare_pacman() {
# Set up the necessary directories for pacman use
2011-02-04 14:34:11 +01:00
[[ ! -d "${DESTDIR}/var/cache/pacman/pkg" ]] && mkdir -m 755 -p "${DESTDIR}/var/cache/pacman/pkg"
[[ ! -d "${DESTDIR}/var/lib/pacman" ]] && mkdir -m 755 -p "${DESTDIR}/var/lib/pacman"
DIALOG --infobox "Refreshing package database..." 6 45
2011-02-04 14:34:11 +01:00
${PACMAN} -Sy >${LOG} 2>&1 || return 1
2011-02-03 21:54:43 +01:00
if [[ $? -ne 0 ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --msgbox "Pacman preparation failed! Check ${LOG} for errors." 6 60
2010-03-06 10:13:54 +01:00
return 1
fi
return 0
}
# Set PACKAGES parameter before running to install wanted packages
run_pacman(){
# create chroot environment on target system
# code straight from mkarchroot
chroot_mount
# execute pacman in a subshell so we can follow its progress
# pacman output goes /tmp/pacman.log
# /tmp/setup-pacman-running acts as a lockfile
( \
echo "Installing Packages..." >/tmp/pacman.log ; \
echo >>/tmp/pacman.log ; \
touch /tmp/setup-pacman-running ; \
2011-02-04 14:34:11 +01:00
${PACMAN} -S ${PACKAGES} 2>&1 >> /tmp/pacman.log ; \
echo $? > /tmp/.pacman-retcode ; \
2011-02-03 21:54:43 +01:00
if [[ $(cat /tmp/.pacman-retcode) -ne 0 ]]; then
echo -e "\nPackage Installation FAILED." >>/tmp/pacman.log
else
echo -e "\nPackage Installation Complete." >>/tmp/pacman.log
fi
rm /tmp/setup-pacman-running
) &
# display pacman output while it's running
sleep 2
2011-02-04 14:34:11 +01:00
dialog --backtitle "${TITLE}" --title " Installing... Please Wait " \
--no-kill --tailboxbg "/tmp/pacman.log" 18 70 2>${ANSWER}
2011-02-03 21:54:43 +01:00
while [[ -f /tmp/setup-pacman-running ]]; do
2013-06-07 08:53:17 +02:00
/usr/bin/true
done
2011-02-04 14:34:11 +01:00
kill $(cat ${ANSWER})
# pacman finished, display scrollable output
local _result=''
2011-02-03 21:54:43 +01:00
if [[ $(cat /tmp/.pacman-retcode) -ne 0 ]]; then
_result="Installation Failed (see errors below)"
else
_result="Installation Complete"
fi
rm /tmp/.pacman-retcode
2011-02-04 14:34:11 +01:00
DIALOG --title "${_result}" --exit-label "Continue" \
--textbox "/tmp/pacman.log" 18 70 || return 1
# ensure the disk is synced
sync
2010-02-21 22:42:23 +01:00
chroot_umount
}
# install_packages()
# performs package installation to the target system
#
install_packages() {
destdir_mounts || return 1
if [[ "${S_MKFS}" != "1" && "${S_MKFSAUTO}" != "1" ]]; then
getdest
fi
prepare_pacman
PACKAGES=""
DIALOG --yesno "Next step will install base, linux, linux-firmware, netctl and filesystem tools for a minimal system.\n\nDo you wish to continue?" 10 50 || return 1
PACKAGES="base linux linux-firmware"
# Add packages which are not in core repository
2012-09-13 12:17:27 +02:00
if [[ -n "$(pgrep dhclient)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dhclient)" ]] && PACKAGES="${PACKAGES} dhclient"
fi
# Add filesystem packages
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep ntfs)" ]]; then
2011-02-04 14:34:11 +01:00
! [[ "$(echo ${PACKAGES} | grep -w ntfs-3g)" ]] && PACKAGES="${PACKAGES} ntfs-3g"
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep btrfs)" ]]; then
2012-01-20 18:24:16 +01:00
! [[ "$(echo ${PACKAGES} | grep -w btrfs-progs)" ]] && PACKAGES="${PACKAGES} btrfs-progs"
2010-06-06 17:22:25 +02:00
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep nilfs2)" ]]; then
2011-02-04 14:34:11 +01:00
! [[ "$(echo ${PACKAGES} | grep -w nilfs-utils)" ]] && PACKAGES="${PACKAGES} nilfs-utils"
2010-08-02 21:34:30 +02:00
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep ext)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w e2fsprogs)" ]] && PACKAGES="${PACKAGES} e2fsprogs"
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep reiserfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w reiserfsprogs)" ]] && PACKAGES="${PACKAGES} reiserfsprogs"
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep xfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w xfsprogs)" ]] && PACKAGES="${PACKAGES} xfsprogs"
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep jfs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w jfsutils)" ]] && PACKAGES="${PACKAGES} jfsutils"
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep f2fs)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w f2fs-tools)" ]] && PACKAGES="${PACKAGES} f2fs-tools"
fi
2013-07-17 08:37:17 +02:00
if [[ "$(${_LSBLK} FSTYPE | grep vfat)" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dosfstools)" ]] && PACKAGES="${PACKAGES} dosfstools"
fi
if ! [[ "$(dmraid_devices)" = "" ]]; then
! [[ "$(echo ${PACKAGES} | grep -w dmraid)" ]] && PACKAGES="${PACKAGES} dmraid"
fi
### HACK:
# always add systemd-sysvcompat components
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ systemd-sysvcompat\ # #g")"
2013-02-02 09:13:17 +01:00
PACKAGES="${PACKAGES} systemd-sysvcompat"
2014-11-12 09:36:42 +01:00
### HACK:
# always add intel-ucode
if [[ "${RUNNING_ARCH}" == "x86_64" ]]; then
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ intel-ucode\ # #g")"
PACKAGES="${PACKAGES} intel-ucode"
fi
# always add amd-ucode
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ amd-ucode\ # #g")"
PACKAGES="${PACKAGES} amd-ucode"
### HACK:
# always add netctl with optdepends
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ netctl\ # #g")"
PACKAGES="${PACKAGES} netctl"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ dhcpd\ # #g")"
PACKAGES="${PACKAGES} dhcpcd"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ wpa_supplicant\ # #g")"
PACKAGES="${PACKAGES} wpa_supplicant"
### HACK:
# always add lvm2, cryptsetup and mdadm
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ lvm2\ # #g")"
PACKAGES="${PACKAGES} lvm2"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ cryptsetup\ # #g")"
PACKAGES="${PACKAGES} cryptsetup"
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ mdadm\ # #g")"
PACKAGES="${PACKAGES} mdadm"
### HACK: circular depends are possible in base, install filesystem first!
PACKAGES="$(echo ${PACKAGES} | sed -e "s#\ filesystem\ # #g")"
PACKAGES="filesystem ${PACKAGES}"
DIALOG --infobox "Package installation will begin in 3 seconds. You can watch the output in the progress window. Please be patient." 0 0
sleep 3
run_pacman
S_INSTALL=1
NEXTITEM="6"
2010-02-21 22:42:23 +01:00
chroot_mount
# automagic time!
# any automatic configuration should go here
DIALOG --infobox "Writing base configuration..." 6 40
auto_fstab
auto_ssd
auto_mdadm
2009-04-19 17:19:37 +02:00
auto_luks
auto_pacman
auto_testing
# tear down the chroot environment
chroot_umount
}
# auto_fstab()
# preprocess fstab file
# comments out old fields and inserts new ones
# according to partitioning/formatting stage
#
auto_fstab(){
# Modify fstab
2011-02-04 14:34:11 +01:00
if [[ "${S_MKFS}" = "1" || "${S_MKFSAUTO}" = "1" ]]; then
2011-02-03 21:54:43 +01:00
if [[ -f /tmp/.device-names ]]; then
2011-02-04 14:34:11 +01:00
sort /tmp/.device-names >>${DESTDIR}/etc/fstab
fi
2011-02-03 21:54:43 +01:00
if [[ -f /tmp/.fstab ]]; then
2013-10-15 18:10:35 +02:00
# clean fstab first from entries
sed -i -e '/^\#/!d' ${DESTDIR}/etc/fstab
2011-02-04 14:34:11 +01:00
sort /tmp/.fstab >>${DESTDIR}/etc/fstab
fi
fi
2008-10-20 22:39:25 +02:00
}
# auto_ssd()
# add udev rule for ssd disks using the deadline scheduler by default
# add sysctl file for swaps
auto_ssd () {
2021-09-21 11:43:54 +02:00
[[ ! -f ${DESTDIR}/etc/udev/rules.d/60-ioschedulers.rules ]] && cp /etc/udev/rules.d/60-ioschedulers.rules ${DESTDIR}/etc/udev/rules.d/60-ioschedulers.rules
[[ ! -f ${DESTDIR}/etc/sysctl.d/99-sysctl.conf ]] && cp /etc/sysctl.d/99-sysctl.conf ${DESTDIR}/etc/sysctl.d/99-sysctl.conf
}
# auto_mdadm()
# add mdadm setup to existing /etc/mdadm.conf
auto_mdadm()
{
if [[ -e ${DESTDIR}/etc/mdadm.conf ]]; then
2011-02-03 21:54:43 +01:00
if [[ "$(cat /proc/mdstat | grep ^md)" ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --infobox "Adding raid setup to ${DESTDIR}/etc/mdadm.conf ..." 4 40
mdadm -Ds >> ${DESTDIR}/etc/mdadm.conf
fi
fi
}
# auto_network()
# configures network on host system according to installer
# settings if user wishes to do so
#
auto_network()
{
# exit if network wasn't configured in installer
2011-02-04 14:34:11 +01:00
if [[ ${S_NET} -eq 0 ]]; then
return 1
fi
2013-02-22 20:32:29 +01:00
# copy netctl profiles
2013-03-25 11:25:15 +01:00
[[ -d ${DESTDIR}/etc/netctl ]] && cp /etc/netctl/* ${DESTDIR}/etc/netctl/ 2>/dev/null
2013-02-22 20:32:29 +01:00
# enable netctl profiles
for i in $(echo /etc/netctl/*); do
[[ -f $i ]] && chroot ${DESTDIR} /usr/bin/netctl enable $(basename $i)
2012-07-27 12:20:55 +02:00
done
# copy proxy settings
2011-02-04 14:34:11 +01:00
if [[ "${PROXY_HTTP}" != "" ]]; then
echo "export http_proxy=${PROXY_HTTP}" >> ${DESTDIR}/etc/profile.d/proxy.sh;
chmod a+x ${DESTDIR}/etc/profile.d/proxy.sh
fi
2011-02-04 14:34:11 +01:00
if [[ "${PROXY_FTP}" != "" ]]; then
echo "export ftp_proxy=${PROXY_FTP}" >> ${DESTDIR}/etc/profile.d/proxy.sh;
chmod a+x ${DESTDIR}/etc/profile.d/proxy.sh
fi
}
# Pacman signature check is enabled by default
# add gnupg pacman files to installed system
# in order to have a working pacman on installed system
auto_pacman()
{
if ! [[ -d ${DESTDIR}/etc/pacman.d/gnupg ]]; then
DO_PACMAN_GPG=""
DIALOG --yesno "Would you like to copy pacman's GPG files to installed system?\nDuring boot pacman GPG entropy was generated by haveged,\nif you need your own entropy answer NO." 0 0 && DO_PACMAN_GPG="yes"
if [[ "${DO_PACMAN_GPG}" = "yes" ]]; then
DIALOG --infobox "Copy /etc/pacman.d/gnupg directory to ${DESTDIR}/etc/pacman.d/gnupg ..." 0 0
cp -ar /etc/pacman.d/gnupg ${DESTDIR}/etc/pacman.d 2>&1
fi
fi
}
# If [testing] repository was enabled during installation,
# enable it on installed system too!
auto_testing()
{
if [[ "${DOTESTING}" == "yes" ]]; then
sed -i -e '/^#\[testing\]/ { n ; s/^#// }' ${DESTDIR}/etc/pacman.conf
sed -i -e '/^#\[community-testing\]/ { n ; s/^#// }' ${DESTDIR}/etc/pacman.conf
sed -i -e 's:^#\[testing\]:\[testing\]:g' -e 's:^#\[community-testing\]:\[community-testing\]:g' ${DESTDIR}/etc/pacman.conf
fi
}
# donetwork()
# Hand-hold through setting up networking
#
# args: none
# returns: 1 on failure
2008-10-20 22:39:25 +02:00
donetwork() {
2012-07-25 21:40:32 +02:00
NETPARAMETERS=""
while [[ "${NETPARAMETERS}" = "" ]]; do
# select network interface
INTERFACE=
S_DHCP=
ifaces=$(net_interfaces)
2012-07-25 21:40:32 +02:00
while [[ "${INTERFACE}" = "" ]]; do
DIALOG --ok-label "Select" --menu "Select a network interface" 14 55 7 ${ifaces} 2>${ANSWER}
case $? in
1) return 1 ;;
0) INTERFACE=$(cat ${ANSWER}) ;;
esac
done
# wireless switch
CONNECTION=""
WLAN_HIDDEN=""
WLAN_ESSID=""
WLAN_SECURITY=""
WLAN_KEY=""
2012-07-26 11:25:04 +02:00
DIALOG --defaultno --yesno "Is your network device wireless?" 5 40
2012-07-25 21:40:32 +02:00
if [[ $? -eq 0 ]]; then
CONNECTION="wireless"
2012-07-26 11:25:04 +02:00
DIALOG --inputbox "Enter your ESSID" 7 40 "MyNetwork" 2>${ANSWER} || return 1
2012-07-25 21:40:32 +02:00
WLAN_ESSID=$(cat ${ANSWER})
2012-07-26 11:25:04 +02:00
DIALOG --defaultno --yesno "Is your wireless network hidden?" 5 40
2012-07-25 21:40:32 +02:00
[[ $? -eq 0 ]] && WLAN_HIDDEN="yes"
2012-07-26 11:25:04 +02:00
DIALOG --yesno "Is your wireless network encrypted?" 5 40
2012-07-25 21:40:32 +02:00
if [[ $? -eq 0 ]]; then
while [[ "${WLAN_SECURITY}" = "" ]]; do
2012-07-26 11:25:04 +02:00
DIALOG --ok-label "Select" --menu "Select encryption type" 9 40 7 \
2012-07-25 21:40:32 +02:00
"wep" "WEP encryption" \
"wpa" "WPA encryption" 2>${ANSWER}
case $? in
1) return 1 ;;
0) WLAN_SECURITY=$(cat ${ANSWER}) ;;
esac
done
2013-03-23 12:18:31 +01:00
DIALOG --inputbox "Enter your KEY" 5 40 "WirelessKey" 2>${ANSWER} || return 1
2012-07-25 21:40:32 +02:00
WLAN_KEY=$(cat ${ANSWER})
else
2013-02-22 20:32:29 +01:00
WLAN_SECURITY="none"
2012-07-25 21:40:32 +02:00
fi
else
CONNECTION="ethernet"
fi
2012-07-25 21:40:32 +02:00
# dhcp switch
IP=""
DHCLIENT=""
2012-07-26 11:25:04 +02:00
DIALOG --yesno "Do you want to use DHCP?" 5 40
2012-07-25 21:40:32 +02:00
if [[ $? -eq 0 ]]; then
IP="dhcp"
2012-07-26 11:25:04 +02:00
DIALOG --defaultno --yesno "Do you want to use dhclient instead of dhcpcd?" 5 55
2012-07-26 09:50:44 +02:00
[[ $? -eq 0 ]] && DHCLIENT="yes"
2012-07-25 21:40:32 +02:00
S_DHCP=1
else
IP="static"
2013-02-22 20:32:29 +01:00
DIALOG --inputbox "Enter your IP address and netmask" 7 40 "192.168.1.23/24" 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
IPADDR=$(cat ${ANSWER})
2012-07-26 12:45:33 +02:00
DIALOG --inputbox "Enter your gateway" 7 40 "192.168.1.1" 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
GW=$(cat ${ANSWER})
2012-07-26 12:45:33 +02:00
DIALOG --inputbox "Enter your DNS server IP" 7 40 "192.168.1.1" 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
DNS=$(cat ${ANSWER})
fi
2013-02-22 20:32:29 +01:00
DIALOG --yesno "Are these settings correct?\n\nInterface: ${INTERFACE}\nConnection: ${CONNECTION}\nESSID: ${WLAN_ESSID}\nHidden: ${WLAN_HIDDEN}\nEncryption: ${WLAN_SECURITY}\nKey: ${WLAN_KEY}\ndhcp or static: ${IP}\nUse dhclient: ${DHCLIENT}\nIP address: ${IPADDR}\nGateway: ${GW}\nDNS server: ${DNS}" 0 0
2012-07-25 21:40:32 +02:00
case $? in
1) ;;
0) NETPARAMETERS="1" ;;
esac
done
# profile name
NETWORK_PROFILE=""
2012-07-26 12:45:33 +02:00
DIALOG --inputbox "Enter your network profile name" 7 40 "${INTERFACE}-${CONNECTION}" 2>${ANSWER} || return 1
2013-02-22 20:32:29 +01:00
NETWORK_PROFILE=/etc/netctl/$(cat ${ANSWER})
2012-07-26 09:50:44 +02:00
# write profile
2013-02-22 20:32:29 +01:00
echo "Connection=${CONNECTION}" >${NETWORK_PROFILE}
echo "Description='$NETWORK_PROFILE generated by archboot setup'" >>${NETWORK_PROFILE}
echo "Interface=${INTERFACE}" >>${NETWORK_PROFILE}
2012-07-26 09:50:44 +02:00
if [[ "${CONNECTION}" = "wireless" ]]; then
2013-02-22 20:32:29 +01:00
echo "Security=${WLAN_SECURITY}" >>${NETWORK_PROFILE}
2012-07-26 12:45:33 +02:00
echo "ESSID='${WLAN_ESSID}'" >>${NETWORK_PROFILE}
2013-02-22 20:32:29 +01:00
echo "Key='${WLAN_KEY}'" >>${NETWORK_PROFILE}
[[ "${WLAN_HIDDEN}" = "yes" ]] && echo "Hidden=yes" >>${NETWORK_PROFILE}
2012-07-26 09:50:44 +02:00
fi
2013-02-22 20:32:29 +01:00
echo "IP=${IP}" >>${NETWORK_PROFILE}
2012-07-26 09:50:44 +02:00
if [[ "${IP}" = "dhcp" ]]; then
2013-02-22 20:51:06 +01:00
[[ "${DHCLIENT}" = "yes" ]] && echo "DHCPClient=dhclient" >>${NETWORK_PROFILE}
2012-07-26 09:50:44 +02:00
else
2013-02-22 20:32:29 +01:00
echo "Address='${IPADDR}'" >>${NETWORK_PROFILE}
echo "Gateway='${GW}'" >>${NETWORK_PROFILE}
2012-07-26 12:45:33 +02:00
echo "DNS=('${DNS}')" >>${NETWORK_PROFILE}
fi
# bring down interface first
systemctl stop dhcpcd@${INTERFACE}.service
ip link set dev ${INTERFACE} down
2013-02-22 20:32:29 +01:00
# run netctl
netctl restart $(basename ${NETWORK_PROFILE}) >${LOG}
2012-07-26 12:45:33 +02:00
if [[ $? -gt 0 ]]; then
DIALOG --msgbox "Error occured while running netctl. (see 'journalctl -xn' for output)" 0 0
2012-07-26 12:45:33 +02:00
return 1
2012-07-26 09:50:44 +02:00
fi
2012-07-25 21:40:32 +02:00
# http/ftp proxy settings
2012-07-26 12:45:33 +02:00
DIALOG --inputbox "Enter your HTTP proxy server, for example:\nhttp://name:port\nhttp://ip:port\nhttp://username:password@ip:port\n\n Leave the field empty if no proxy is needed to install." 13 65 "" 2>${ANSWER} || return 1
2012-07-25 21:40:32 +02:00
PROXY_HTTP=$(cat ${ANSWER})
2012-07-26 12:45:33 +02:00
DIALOG --inputbox "Enter your FTP proxy server, for example:\nhttp://name:port\nhttp://ip:port\nhttp://username:password@ip:port\n\n Leave the field empty if no proxy is needed to install." 13 65 "" 2>${ANSWER} || return 1
2012-07-25 21:40:32 +02:00
PROXY_FTP=$(cat ${ANSWER})
if [[ "${PROXY_HTTP}" = "" ]]; then
unset http_proxy
else
export http_proxy=${PROXY_HTTP}
fi
if [[ "${PROXY_FTP}" = "" ]]; then
unset ftp_proxy
else
export ftp_proxy=${PROXY_FTP}
fi
# add sleep here dhcp can need some time to get link
2021-09-15 07:41:10 +02:00
DIALOG --infobox "Please wait 5 seconds for network link to come up ..." 0 0
sleep 5
2012-07-26 14:33:41 +02:00
NEXTITEM="2"
S_NET=1
2008-10-20 22:39:25 +02:00
}
getrootfstype() {
ROOTFS="$(getfstype ${PART_ROOT})"
2008-12-29 20:19:31 +01:00
}
getrootflags() {
ROOTFLAGS=""
2013-08-10 19:39:23 +02:00
ROOTFLAGS="$(findmnt -m -n -o options -T ${DESTDIR})"
# add subvolume for btrfs
if [[ "${ROOTFS}" == "btrfs" ]]; then
2014-04-12 10:26:16 +02:00
[[ "$(findmnt -m -n -o SOURCE -T ${DESTDIR} | grep "\[")" ]] && ROOTFLAGS="${ROOTFLAGS},subvol=$(basename "$(findmnt -m -n -o SOURCE -T ${DESTDIR} | cut -d "]" -f1)")"
fi
[[ -n "${ROOTFLAGS}" ]] && ROOTFLAGS="rootflags=${ROOTFLAGS}"
}
2009-01-31 22:31:37 +01:00
getraidarrays() {
2009-04-19 17:19:37 +02:00
RAIDARRAYS=""
2011-02-04 14:34:11 +01:00
if ! [[ "$(grep ^ARRAY ${DESTDIR}/etc/mdadm.conf)" ]]; then
RAIDARRAYS="$(echo -n $(cat /proc/mdstat 2>/dev/null | grep ^md | sed -e 's#\[[0-9]\]##g' -e 's# :.* raid[0-9]##g' -e 's#md#md=#g' -e 's# #,/dev/#g' -e 's#_##g'))"
fi
2009-01-31 22:31:37 +01:00
}
2009-04-19 17:19:37 +02:00
getcryptsetup() {
CRYPTSETUP=""
2011-02-04 14:34:11 +01:00
if ! [[ "$(cryptsetup status $(basename ${PART_ROOT}) | grep inactive)" ]]; then
2009-06-28 22:40:06 +02:00
#avoid clash with dmraid here
2011-02-04 14:34:11 +01:00
if [[ "$(cryptsetup status $(basename ${PART_ROOT}))" ]]; then
if [[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]]; then
CRYPTDEVICE="UUID=$(echo $(${_LSBLK} UUID $(cryptsetup status $(basename ${PART_ROOT}) | grep device: | sed -e 's#device:##g')))"
elif [[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]]; then
CRYPTDEVICE="LABEL=$(echo $(${_LSBLK} LABEL $(cryptsetup status $(basename ${PART_ROOT}) | grep device: | sed -e 's#device:##g')))"
else
2011-02-04 14:34:11 +01:00
CRYPTDEVICE="$(echo $(cryptsetup status $(basename ${PART_ROOT}) | grep device: | sed -e 's#device:##g'))"
fi
2011-02-04 14:34:11 +01:00
CRYPTNAME="$(basename ${PART_ROOT})"
CRYPTSETUP="cryptdevice=${CRYPTDEVICE}:${CRYPTNAME}"
2009-06-28 22:40:06 +02:00
fi
2009-04-19 17:19:37 +02:00
fi
}
2012-10-08 17:55:28 +02:00
getrootpartuuid() {
_rootpart="${PART_ROOT}"
_partuuid="$(getpartuuid ${PART_ROOT})"
if [[ -n "${_partuuid}" ]]; then
_rootpart="PARTUUID=${_partuuid}"
fi
}
getrootpartlabel() {
_rootpart="${PART_ROOT}"
_partlabel="$(getpartlabel ${PART_ROOT})"
if [[ -n "${_partlabel}" ]]; then
_rootpart="PARTLABEL=${_partlabel}"
fi
}
getrootfsuuid() {
2011-02-04 14:34:11 +01:00
_rootpart="${PART_ROOT}"
_fsuuid="$(getfsuuid ${PART_ROOT})"
if [[ -n "${_fsuuid}" ]]; then
_rootpart="UUID=${_fsuuid}"
2010-03-06 20:55:55 +01:00
fi
}
getrootfslabel() {
2011-02-04 14:34:11 +01:00
_rootpart="${PART_ROOT}"
_fslabel="$(getfslabel ${PART_ROOT})"
if [[ -n "${_fslabel}" ]]; then
_rootpart="LABEL=${_fslabel}"
2010-05-24 15:39:55 +02:00
fi
}
## Setup kernel cmdline parameters to be added to bootloader configs
bootloader_kernel_parameters() {
2012-10-08 17:55:28 +02:00
if [[ "${GUID_DETECTED}" == "1" ]]; then
[[ "${NAME_SCHEME_PARAMETER}" == "PARTUUID" ]] && getrootpartuuid
[[ "${NAME_SCHEME_PARAMETER}" == "PARTLABEL" ]] && getrootpartlabel
fi
[[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]] && getrootfsuuid
[[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]] && getrootfslabel
[[ "${_rootpart}" == "" ]] && _rootpart="${PART_ROOT}"
2014-04-11 19:56:25 +02:00
_KERNEL_PARAMS_COMMON_UNMOD="root=${_rootpart} rootfstype=${ROOTFS} rw ${ROOTFLAGS} ${RAIDARRAYS} ${CRYPTSETUP} cgroup_disable=memory"
2013-08-10 19:39:23 +02:00
_KERNEL_PARAMS_BIOS_UNMOD="${_KERNEL_PARAMS_COMMON_UNMOD}"
_KERNEL_PARAMS_UEFI_UNMOD="${_KERNEL_PARAMS_COMMON_UNMOD} add_efi_memmap"
_KERNEL_PARAMS_BIOS_MOD="$(echo "${_KERNEL_PARAMS_BIOS_UNMOD}" | sed -e 's# # #g' | sed -e 's# # #g')"
_KERNEL_PARAMS_UEFI_MOD="$(echo "${_KERNEL_PARAMS_UEFI_UNMOD}" | sed -e 's# # #g' | sed -e 's# # #g')"
}
# basic checks needed for all bootloaders
common_bootloader_checks() {
activate_special_devices
getrootfstype
getraidarrays
getcryptsetup
getrootflags
bootloader_kernel_parameters
2010-06-10 19:54:23 +02:00
}
2010-06-04 15:49:31 +02:00
# look for a separately-mounted /boot partition
2010-07-15 21:24:55 +02:00
check_bootpart() {
2010-06-04 15:49:31 +02:00
subdir=""
2012-01-09 13:54:09 +01:00
bootdev="$(mount | grep "${DESTDIR}/boot " | cut -d' ' -f 1)"
if [[ "${bootdev}" == "" ]]; then
subdir="/boot"
bootdev="${PART_ROOT}"
2010-06-04 15:49:31 +02:00
fi
}
2010-08-02 21:34:30 +02:00
# check for nilfs2 bootpart and abort if detected
abort_nilfs_bootpart() {
FSTYPE="$(${_LSBLK} FSTYPE ${bootdev})"
2011-02-04 14:34:11 +01:00
if [[ "${FSTYPE}" = "nilfs2" ]]; then
2010-08-02 21:34:30 +02:00
DIALOG --msgbox "Error:\nYour selected bootloader cannot boot from nilfs2 partition with /boot on it." 0 0
return 1
fi
}
2013-05-07 12:02:34 +02:00
# check for f2fs bootpart and abort if detected
abort_f2fs_bootpart() {
FSTYPE="$(${_LSBLK} FSTYPE ${bootdev})"
2013-05-07 12:02:34 +02:00
if [[ "${FSTYPE}" = "f2fs" ]]; then
DIALOG --msgbox "Error:\nYour selected bootloader cannot boot from f2fs partition with /boot on it." 0 0
return 1
fi
}
uefi_mount_efivarfs() {
## Mount efivarfs if it is not already mounted
if [[ ! "$(mount | grep /sys/firmware/efi/efivars)" ]]; then
modprobe -q efivarfs
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
}
detect_uefi_secure_boot() {
export _DETECTED_UEFI_SECURE_BOOT="0"
if [[ "${_DETECTED_UEFI_BOOT}" == "1" ]]; then
uefi_mount_efivarfs
2021-10-16 00:17:02 +02:00
_SECUREBOOT_VAR_VALUE="$(efivar -n 8be4df61-93ca-11d2-aa0d-00e098032b8c-SecureBoot | tail -n -1 | awk '{print $2}')"
_SETUPMODE_VAR_VALUE="$(efivar -n 8be4df61-93ca-11d2-aa0d-00e098032b8c-SetupMode | tail -n -1 | awk '{print $2}')"
if [[ "${_SECUREBOOT_VAR_VALUE}" == "01" ]] && [[ "${_SETUPMODE_VAR_VALUE}" == "00" ]]; then
export _DETECTED_UEFI_SECURE_BOOT="1"
fi
fi
}
detect_uefi_boot() {
export _DETECTED_UEFI_BOOT="0"
2014-05-15 09:34:54 +02:00
[[ -e "/sys/firmware/efi" ]] && _DETECTED_UEFI_BOOT="1"
detect_uefi_secure_boot
2013-09-09 15:18:29 +02:00
}
do_uefi_setup_env_vars() {
2022-01-05 14:45:36 +01:00
if [[ "${RUNNING_ARCH}" == "x86_64" ]]; then
2014-05-15 09:34:54 +02:00
if [[ "$(grep '_IA32_UEFI=1' /proc/cmdline 1>/dev/null)" ]]; then
export _EFI_MIXED="1"
export _UEFI_ARCH="IA32"
export _SPEC_UEFI_ARCH="ia32"
else
export _EFI_MIXED="0"
export _UEFI_ARCH="X64"
export _SPEC_UEFI_ARCH="x64"
fi
fi
2022-01-05 14:45:36 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
export _EFI_MIXED="0"
export _UEFI_ARCH="AA64"
export _SPEC_UEFI_ARCH="aa64"
fi
2017-11-27 09:29:13 +01:00
}
do_uefi_common() {
do_uefi_setup_env_vars
PACKAGES=""
[[ ! -f "${DESTDIR}/usr/bin/mkfs.vfat" ]] && PACKAGES="${PACKAGES} dosfstools"
[[ ! -f "${DESTDIR}/usr/bin/efivar" ]] && PACKAGES="${PACKAGES} efivar"
[[ ! -f "${DESTDIR}/usr/bin/efibootmgr" ]] && PACKAGES="${PACKAGES} efibootmgr"
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
2021-10-16 00:08:11 +02:00
[[ ! -f "${DESTDIR}/usr/bin/mokutil" ]] && PACKAGES="${PACKAGES} mokutil"
2021-10-18 09:25:46 +02:00
[[ ! -f "${DESTDIR}/usr/bin/efi-readvar" ]] && PACKAGES="${PACKAGES} efitools"
2021-10-18 10:51:06 +02:00
[[ ! -f "${DESTDIR}/usr/bin/sbsign" ]] && PACKAGES="${PACKAGES} sbsigntools"
fi
! [[ "${PACKAGES}" == "" ]] && run_pacman
unset PACKAGES
check_efisys_part
}
do_uefi_efibootmgr() {
uefi_mount_efivarfs
2021-10-16 00:08:11 +02:00
if [[ "$(/usr/bin/efivar -l)" ]]; then
cat << EFIBEOF > "/tmp/efibootmgr_run.sh"
#!/usr/bin/env bash
2013-08-31 12:34:46 +02:00
_EFIBOOTMGR_LOADER_PARAMETERS="${_EFIBOOTMGR_LOADER_PARAMETERS}"
2012-10-30 17:23:11 +01:00
for _bootnum in \$(efibootmgr | grep '^Boot[0-9]' | fgrep -i "${_EFIBOOTMGR_LABEL}" | cut -b5-8) ; do
2013-08-31 12:34:46 +02:00
efibootmgr --quiet --bootnum "\${_bootnum}" --delete-bootnum
done
if [[ "\${_EFIBOOTMGR_LOADER_PARAMETERS}" != "" ]]; then
2021-10-17 22:42:25 +02:00
efibootmgr --quiet --create --disk "${_EFIBOOTMGR_DISC}" --part "${_EFIBOOTMGR_PART_NUM}" --loader "${_EFIBOOTMGR_LOADER_PATH}" --label "${_EFIBOOTMGR_LABEL}" --unicode "\${_EFIBOOTMGR_LOADER_PARAMETERS}" -e "3"
2013-09-09 15:18:29 +02:00
else
2021-10-17 22:42:25 +02:00
efibootmgr --quiet --create --disk "${_EFIBOOTMGR_DISC}" --part "${_EFIBOOTMGR_PART_NUM}" --loader "${_EFIBOOTMGR_LOADER_PATH}" --label "${_EFIBOOTMGR_LABEL}" -e "3"
fi
EFIBEOF
2021-10-16 00:08:11 +02:00
chmod a+x "/tmp/efibootmgr_run.sh"
/tmp/efibootmgr_run.sh &>"/tmp/efibootmgr_run.log"
else
DIALOG --msgbox "Boot entry could not be created. Check whether you have booted in UEFI boot mode and create a boot entry for ${UEFISYS_MOUNTPOINT}/${_EFIBOOTMGR_LOADER_PATH} using efibootmgr." 0 0
fi
unset _EFIBOOTMGR_LABEL
unset _EFIBOOTMGR_DISC
unset _EFIBOOTMGR_PART_NUM
unset _EFIBOOTMGR_LOADER_PATH
unset _EFIBOOTMGR_LOADER_PARAMETERS
}
do_apple_efi_hfs_bless() {
## Grub upstream bzr mactel branch => http://bzr.savannah.gnu.org/lh/grub/branches/mactel/changes
## Fedora's mactel-boot => https://bugzilla.redhat.com/show_bug.cgi?id=755093
DIALOG --msgbox "TODO: Apple Mac EFI Bootloader Setup" 0 0
}
do_uefi_bootmgr_setup() {
_uefisysdev="$(findmnt -vno SOURCE "${DESTDIR}/${UEFISYS_MOUNTPOINT}")"
_DISC="$(${_LSBLK} KNAME "${_uefisysdev}")"
UEFISYS_PART_NUM="$(${_BLKID} -p -i -s PART_ENTRY_NUMBER -o value "${_uefisysdev}")"
_BOOTMGR_DISC="${_DISC}"
_BOOTMGR_PART_NUM="${UEFISYS_PART_NUM}"
if [[ "$(cat "/sys/class/dmi/id/sys_vendor")" == 'Apple Inc.' ]] || [[ "$(cat "/sys/class/dmi/id/sys_vendor")" == 'Apple Computer, Inc.' ]]; then
do_apple_efi_hfs_bless
else
## For all the non-Mac UEFI systems
_EFIBOOTMGR_LABEL="${_BOOTMGR_LABEL}"
_EFIBOOTMGR_DISC="${_BOOTMGR_DISC}"
_EFIBOOTMGR_PART_NUM="${_BOOTMGR_PART_NUM}"
_EFIBOOTMGR_LOADER_PATH="${_BOOTMGR_LOADER_PATH}"
_EFIBOOTMGR_LOADER_PARAMETERS="${_BOOTMGR_LOADER_PARAMETERS}"
do_uefi_efibootmgr
fi
unset _BOOTMGR_LABEL
unset _BOOTMGR_DISC
unset _BOOTMGR_PART_NUM
unset _BOOTMGR_LOADER_PATH
unset _BOOTMGR_LOADER_PARAMETERS
}
do_uefi_secure_boot_efitools() {
do_uefi_common
# install helper tools and create entries in UEFI boot manager, if not present
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
chroot_mount
2021-10-18 09:25:46 +02:00
if [[ ! -f "${UEFISYS_MOUNTPOINT}/EFI/BOOT/HashTool.efi" ]]; then
chroot "${DESTDIR}" cp "/usr/share/efitools/efi/HashTool.efi" "${UEFISYS_MOUNTPOINT}/EFI/BOOT/HashTool.efi"
_BOOTMGR_LABEL="HashTool (Secure Boot)"
_BOOTMGR_LOADER_DIR="/EFI/BOOT/HashTool.efi"
do_uefi_bootmgr_setup
fi
2021-10-18 09:25:46 +02:00
if [[ ! -f "${UEFISYS_MOUNTPOINT}/EFI/BOOT/KeyTool.efi" ]]; then
chroot "${DESTDIR}" cp "/usr/share/efitools/efi/KeyTool.efi" "${UEFISYS_MOUNTPOINT}/EFI/BOOT/KeyTool.efi"
_BOOTMGR_LABEL="KeyTool (Secure Boot)"
_BOOTMGR_LOADER_DIR="/EFI/BOOT/KeyTool.efi"
do_uefi_bootmgr_setup
fi
chroot_umount
fi
}
2021-10-16 23:14:46 +02:00
do_secureboot_keys() {
CN=""
MOK_PW=""
KEYDIR=""
while [[ "${KEYDIR}" = "" ]]; do
DIALOG --inputbox "Setup keys:\nEnter the directory to store the keys on ${DESTDIR}.\nPlease leave the leading slash \"/\"." 8 65 "etc/secureboot/keys" 2>${ANSWER} || KEYDIR=""
2021-10-16 23:14:46 +02:00
KEYDIR=$(cat ${ANSWER})
done
if [[ ! -d "${DESTDIR}/${KEYDIR}" ]]; then
while [[ "${CN}" = "" ]]; do
DIALOG --inputbox "Setup keys:\nEnter a common name(CN) for your keys, eg. Your Name" 8 65 "" 2>${ANSWER} || CN=""
CN=$(cat ${ANSWER})
done
secureboot-keys.sh -name="${CN}" "${DESTDIR}/${KEYDIR}" > ${LOG} 2>&1 || return 1
2021-10-19 16:56:30 +02:00
DIALOG --msgbox "Setup keys created:\nCommon name(CN) ${CN} used for your keys in ${DESTDIR}/${KEYDIR} " 8 65
else
2021-10-18 09:25:46 +02:00
DIALOG --msgbox "Setup keys:\n-Directory ${DESTDIR}/${KEYDIR} exists\n-assuming keys are already created\n-trying to use existing keys now" 8 65 ""
fi
2021-10-16 23:14:46 +02:00
}
do_mok_sign () {
UEFI_BOOTLOADER_DIR="${UEFISYS_MOUNTPOINT}/EFI/BOOT"
INSTALL_MOK=""
2021-10-16 23:14:46 +02:00
MOK_PW=""
DIALOG --yesno "Do you want to install the MOK certificate to the UEFI keys?" 0 0 && INSTALL_MOK="1"
if [[ "${INSTALL_MOK}" == "1" ]]; then
while [[ "${MOK_PW}" = "" ]]; do
DIALOG --insecure --passwordbox "Enter a one time MOK password for SHIM on reboot:" 8 65 2>${ANSWER} || return 1
PASS=$(cat ${ANSWER})
DIALOG --insecure --passwordbox "Retype one time MOK password:" 8 65 2>${ANSWER} || return 1
PASS2=$(cat ${ANSWER})
if [[ "${PASS}" = "${PASS2}" ]]; then
MOK_PW=${PASS}
2021-10-18 09:25:46 +02:00
echo ${MOK_PW} > /tmp/.password
echo ${MOK_PW} >> /tmp/.password
MOK_PW=/tmp/.password
else
DIALOG --msgbox "Password didn't match, please enter again." 8 65
fi
done
2021-10-18 09:25:46 +02:00
mokutil -i ${DESTDIR}/${KEYDIR}/MOK/MOK.cer < ${MOK_PW} > ${LOG}
rm /tmp/.password
DIALOG --msgbox "MOK keys have been installed successfully." 8 65
fi
SIGN_MOK=""
DIALOG --yesno "Do you want to sign /boot/${VMLINUZ} and ${UEFI_BOOTLOADER_DIR}/grub${_SPEC_UEFI_ARCH}.efi with the MOK certificate?" 0 0 && SIGN_MOK="1"
if [[ "${SIGN_MOK}" == "1" ]]; then
chroot_mount
2021-10-18 10:14:21 +02:00
chroot "${DESTDIR}" sbsign --key /${KEYDIR}/MOK/MOK.key --cert /${KEYDIR}/MOK/MOK.crt --output /boot/${VMLINUZ} /boot/${VMLINUZ} > ${LOG}
chroot "${DESTDIR}" sbsign --key /${KEYDIR}/MOK/MOK.key --cert /${KEYDIR}/MOK/MOK.crt --output ${UEFI_BOOTLOADER_DIR}/grub${_SPEC_UEFI_ARCH}.efi ${UEFI_BOOTLOADER_DIR}/grub${_SPEC_UEFI_ARCH}.efi > ${LOG}
chroot_umount
DIALOG --msgbox "/boot/${VMLINUZ} and ${UEFI_BOOTLOADER_DIR}/grub${_SPEC_UEFI_ARCH}.efi\nbeen signed successfully." 8 65
fi
2021-10-16 23:14:46 +02:00
}
do_pacman_sign() {
SIGN_KERNEL=""
DIALOG --yesno "Do you want to install a pacman hook for automatic signing /boot/${VMLINUZ} on updates?" 0 0 && SIGN_KERNEL="1"
if [[ "${SIGN_KERNEL}" == "1" ]]; then
[[ ! -d "${DESTDIR}/etc/pacman.d/hooks" ]] && mkdir -p ${DESTDIR}/etc/pacman.d/hooks/
HOOKNAME="${DESTDIR}/etc/pacman.d/hooks/999-sign_kernel_for_secureboot.hook"
cat << EOF > ${HOOKNAME}
2021-10-16 23:14:46 +02:00
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = linux
[Action]
Description = Signing kernel with Machine Owner Key for Secure Boot
When = PostTransaction
2021-10-18 10:55:52 +02:00
Exec = /usr/bin/find /boot/ -maxdepth 1 -name 'vmlinuz-*' -exec /usr/bin/sh -c 'if ! /usr/bin/sbverify --list {} 2>/dev/null | /usr/bin/grep -q "signature certificates"; then /usr/bin/sbsign --key /${KEYDIR}/MOK/MOK.key --cert /${KEYDIR}/MOK/MOK.crt --output {} {}; fi' ;
2021-10-16 23:14:46 +02:00
Depends = sbsigntools
Depends = findutils
Depends = grep
EOF
DIALOG --msgbox "Pacman hook for automatic signing has been installed successfully:\n${HOOKNAME}" 8 75
fi
2021-10-16 23:14:46 +02:00
}
2013-06-22 20:25:34 +02:00
do_efistub_copy_to_efisys() {
2013-06-22 20:25:34 +02:00
if [[ "${UEFISYS_MOUNTPOINT}" != "/boot" ]]; then
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
_EFISTUB_KERNEL="linux/arch/${VMLINUZ_EFISTUB}.efi"
else
_EFISTUB_KERNEL="linux/arch/${VMLINUZ}.efi"
fi
_EFISTUB_INITRAMFS="linux/arch/${INITRAMFS}"
2013-08-22 17:48:20 +02:00
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/"
2012-09-26 12:51:22 +02:00
2013-06-22 20:25:34 +02:00
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img"
2013-06-22 20:25:34 +02:00
cp -f "${DESTDIR}/boot/${VMLINUZ}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}"
cp -f "${DESTDIR}/boot/${INITRAMFS}.img" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img"
cp -f "${DESTDIR}/boot/${INITRAMFS}-fallback.img" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img"
#######################
cat << CONFEOF > "${DESTDIR}/etc/systemd/system/efistub_copy.path"
[Unit]
Description=Copy EFISTUB Kernel and Initramfs files to EFI SYSTEM PARTITION
[Path]
2013-03-16 22:10:26 +01:00
PathChanged=/boot/${VMLINUZ}
2014-11-12 14:21:14 +01:00
PathChanged=/boot/${INTEL_UCODE}
PathChanged=/boot/${AMD_UCODE}
2013-03-16 22:10:26 +01:00
PathChanged=/boot/${INITRAMFS}.img
PathChanged=/boot/${INITRAMFS}-fallback.img
Unit=efistub_copy.service
[Install]
WantedBy=multi-user.target
CONFEOF
2013-06-22 20:25:34 +02:00
cat << CONFEOF > "${DESTDIR}/etc/systemd/system/efistub_copy.service"
[Unit]
Description=Copy EFISTUB Kernel and Initramfs files to EFI SYSTEM PARTITION
[Service]
Type=oneshot
ExecStart=/usr/bin/cp -f /boot/${VMLINUZ} ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}
2014-11-12 14:21:14 +01:00
ExecStart=/usr/bin/cp -f /boot/${INTEL_UCODE} ${UEFISYS_MOUNTPOINT}/EFI/arch/${INTEL_UCODE}
ExecStart=/usr/bin/cp -f /boot/${AMD_UCODE} ${UEFISYS_MOUNTPOINT}/EFI/arch/${AMD_UCODE}
ExecStart=/usr/bin/cp -f /boot/${INITRAMFS}.img ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img
ExecStart=/usr/bin/cp -f /boot/${INITRAMFS}-fallback.img ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img
CONFEOF
2013-06-22 20:25:34 +02:00
chroot "${DESTDIR}" /usr/bin/systemctl enable efistub_copy.path
fi
###########################
_bootdev="$(findmnt -vno SOURCE "${DESTDIR}/boot")"
2018-06-25 11:43:13 +02:00
_uefisysdev="$(findmnt -vno SOURCE "${DESTDIR}/${UEFISYS_MOUNTPOINT}")"
2013-06-22 20:25:34 +02:00
UEFISYS_PART_FS_UUID="$(getfsuuid "${_uefisysdev}")"
UEFISYS_PART_FS_LABEL="$(getfslabel "${_uefisysdev}")"
UEFISYS_PART_GPT_GUID="$(getpartuuid "${_uefisysdev}")"
UEFISYS_PART_GPT_LABEL="$(getpartlabel "${_uefisysdev}")"
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
2022-01-05 15:56:49 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
_KERNEL_NORMAL="/${VMLINUZ_EFISTUB}"
2022-01-05 15:56:49 +01:00
else
_KERNEL_NORMAL="/${VMLINUZ}"
_INITRD_INTEL_UCODE="/${INTEL_UCODE}"
fi
_INITRD_AMD_UCODE="/${AMD_UCODE}"
2013-06-22 20:25:34 +02:00
_INITRD_NORMAL="/${INITRAMFS}.img"
2013-06-22 20:25:34 +02:00
_INITRD_FALLBACK_NORMAL="/${INITRAMFS}-fallback.img"
else
2022-01-05 15:56:49 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
_KERNEL_NORMAL="/EFI/arch/${VMLINUZ_EFISTUB}"
2022-01-05 15:56:49 +01:00
else
_KERNEL_NORMAL="/EFI/arch/${_EFISTUB_KERNEL}"
_INITRD_INTEL_UCODE="/EFI/arch/${INTEL_UCODE}"
fi
_INITRD_AMD_UCODE="/EFI/arch/${AMD_UCODE}"
2014-11-12 14:18:16 +01:00
2013-06-22 20:25:34 +02:00
_INITRD_NORMAL="/EFI/arch/${_EFISTUB_INITRAMFS}.img"
2013-06-22 20:25:34 +02:00
_INITRD_FALLBACK_NORMAL="/EFI/arch/${_EFISTUB_INITRAMFS}-fallback.img"
fi
}
do_efistub_uefi() {
do_uefi_common
2013-07-04 08:42:20 +02:00
bootdev=""
grubdev=""
complexuuid=""
FAIL_COMPLEX=""
USE_DMRAID=""
RAID_ON_LVM=""
common_bootloader_checks
do_efistub_copy_to_efisys
###################################
2013-07-04 08:46:46 +02:00
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
_CONTINUE="1"
else
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL}" ]] && [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img" ]]; then
DIALOG --msgbox "The EFISTUB Kernel and initramfs have been copied to ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_KERNEL} and ${UEFISYS_MOUNTPOINT}/EFI/arch/${_EFISTUB_INITRAMFS}.img respectively." 0 0
2013-07-04 08:46:46 +02:00
_CONTINUE="1"
else
DIALOG --msgbox "Error setting up EFISTUB kernel and initramfs in ${UEFISYS_MOUNTPOINT}." 0 0
2013-07-04 08:46:46 +02:00
_CONTINUE="0"
fi
fi
2022-01-05 15:46:07 +01:00
if [[ "${_CONTINUE}" == "1" ]]; then
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
do_systemd_boot_uefi
else
DIALOG --menu "Select which UEFI Boot Manager to install, to provide a menu for the EFISTUB kernels?" 11 55 3 \
"Systemd-boot" "Systemd-boot for ${UEFI_ARCH} UEFI" \
"rEFInd" "rEFInd for ${UEFI_ARCH} UEFI" \
"NONE" "No Boot Manager" 2>${ANSWER} || CANCEL=1
case $(cat ${ANSWER}) in
"Systemd-boot") do_systemd_boot_uefi ;;
"rEFInd") do_refind_uefi;;
"NONE") return 0 ;;
esac
fi
fi
}
do_systemd_boot_uefi() {
DIALOG --msgbox "Setting up Systemd-boot now ..." 0 0
2013-09-09 15:18:29 +02:00
# create directory structure, if it doesn't exist
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries"
2013-07-04 08:42:20 +02:00
cat << GUMEOF > "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-main.conf"
2013-06-22 20:25:34 +02:00
title Arch Linux
linux ${_KERNEL_NORMAL}
GUMEOF
if [[ "${RUNNING_ARCH}" == "x86_64" ]]; then
cat << GUMEOF >> "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-main.conf"
2014-11-12 14:18:16 +01:00
initrd ${_INITRD_INTEL_UCODE}
GUMEOF
fi
cat << GUMEOF >> "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-main.conf"
initrd ${_INITRD_AMD_UCODE}
2013-06-22 20:25:34 +02:00
initrd ${_INITRD_NORMAL}
options ${_KERNEL_PARAMS_UEFI_MOD}
GUMEOF
2013-07-04 08:42:20 +02:00
cat << GUMEOF > "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-fallback.conf"
2013-06-22 20:25:34 +02:00
title Arch Linux Fallback
linux ${_KERNEL_NORMAL}
GUMEOF
if [[ "${RUNNING_ARCH}" == "x86_64" ]]; then
cat << GUMEOF >> "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-fallback.conf"
2014-11-12 14:18:16 +01:00
initrd ${_INITRD_INTEL_UCODE}
GUMEOF
fi
cat << GUMEOF >> "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-fallback.conf"
initrd ${_INITRD_AMD_UCODE}
2013-06-22 20:25:34 +02:00
initrd ${_INITRD_FALLBACK_NORMAL}
options ${_KERNEL_PARAMS_UEFI_MOD}
GUMEOF
2013-07-04 08:42:20 +02:00
cat << GUMEOF > "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/loader.conf"
2012-10-30 17:23:11 +01:00
timeout 5
default archlinux-core-main
GUMEOF
uefi_mount_efivarfs
chroot_mount
chroot "${DESTDIR}" "/usr/bin/bootctl" --path="${UEFISYS_MOUNTPOINT}" install
chroot "${DESTDIR}" "/usr/bin/bootctl" --path="${UEFISYS_MOUNTPOINT}" update
chroot_umount
2013-03-16 22:10:26 +01:00
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/systemd/systemd-boot${_SPEC_UEFI_ARCH}.efi" ]]; then
DIALOG --msgbox "You will now be put into the editor to edit loader.conf and Systemd-boot menu entry files . After you save your changes, exit the editor." 0 0
geteditor || return 1
2013-07-04 08:42:20 +02:00
"${EDITOR}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-main.conf"
"${EDITOR}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/entries/archlinux-core-fallback.conf"
2013-03-16 22:10:26 +01:00
"${EDITOR}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/loader/loader.conf"
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
_UEFISYS_EFI_BOOT_DIR="1"
else
DIALOG --defaultno --yesno "Do you want to copy ${UEFISYS_MOUNTPOINT}/EFI/systemd/systemd-boot${_SPEC_UEFI_ARCH}.efi to ${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi ?\n\nThis might be needed in some systems where efibootmgr may not work due to firmware issues." 0 0 && _UEFISYS_EFI_BOOT_DIR="1"
fi
if [[ "${_UEFISYS_EFI_BOOT_DIR}" == "1" ]]; then
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi" || true
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/systemd/systemd-boot${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
fi
else
DIALOG --msgbox "Error installing Systemd-boot..." 0 0
fi
}
do_refind_uefi() {
2013-06-07 08:53:43 +02:00
DIALOG --msgbox "Setting up rEFInd now ..." 0 0
if [[ ! -f "${DESTDIR}/usr/bin/refind-install" ]]; then
DIALOG --infobox "Couldn't find ${DESTDIR}/usr/bin/refind-install, installing refind pkg in 3 seconds ..." 0 0
sleep 3
2020-07-18 15:10:43 +02:00
PACKAGES="refind"
run_pacman
unset PACKAGES
fi
2013-08-22 17:41:19 +02:00
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/"
cp -f "${DESTDIR}/usr/share/refind/refind_${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi"
2013-03-16 22:10:26 +01:00
cp -r "${DESTDIR}/usr/share/refind/icons" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/icons"
cp -r "${DESTDIR}/usr/share/refind/fonts" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/fonts"
2012-09-26 12:51:22 +02:00
2013-08-22 17:41:19 +02:00
! [[ -d "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools" ]] && mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools/"
cp -rf "${DESTDIR}/usr/share/refind/drivers_${_SPEC_UEFI_ARCH}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools/drivers_${_SPEC_UEFI_ARCH}"
mv "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/tools/drivers_${_SPEC_UEFI_ARCH}"/ext2_x64.{,_}efi
2013-03-16 22:10:26 +01:00
_REFIND_CONFIG="${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind.conf"
cp -f "${DESTDIR}/usr/share/refind/refind.conf-sample" "${_REFIND_CONFIG}"
2012-09-28 11:09:50 +02:00
sed 's|^#resolution 1024 768|resolution 1024 768|g' -i "${_REFIND_CONFIG}"
sed 's|^#scan_driver_dirs EFI/tools/drivers,drivers|scan_driver_dirs EFI/tools/drivers_${_SPEC_UEFI_ARCH}|g' -i "${_REFIND_CONFIG}"
sed 's|^#scanfor internal,external,optical,manual|scanfor manual,internal,external,optical|g' -i "${_REFIND_CONFIG}"
2013-01-30 18:14:03 +01:00
sed 's|^#also_scan_dirs boot,ESP2:EFI/linux/kernels|also_scan_dirs boot|g' -i "${_REFIND_CONFIG}"
sed 's|^#scan_all_linux_kernels|scan_all_linux_kernels|g' -i "${_REFIND_CONFIG}"
2013-07-04 08:42:20 +02:00
if [[ "${UEFISYS_MOUNTPOINT}" == "/boot" ]]; then
_REFIND_LINUX_CONF="${DESTDIR}/${UEFISYS_MOUNTPOINT}/refind_linux.conf"
else
2013-07-04 08:42:20 +02:00
_REFIND_LINUX_CONF="${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/arch/refind_linux.conf"
fi
cat << REFINDEOF > "${_REFIND_LINUX_CONF}"
"Boot with Defaults" "${_KERNEL_PARAMS_UEFI_MOD} initrd=${_INITRD_INTEL_UCODE} initrd=${_INITRD_AMD_UCODE} initrd=${_INITRD_NORMAL}"
"Boot with fallback initramfs" "${_KERNEL_PARAMS_UEFI_MOD} initrd=${_INITRD_INTEL_UCODE} initrd=${_INITRD_AMD_UCODE} initrd=${_INITRD_FALLBACK_NORMAL}"
REFINDEOF
2013-03-16 22:10:26 +01:00
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi" ]]; then
_BOOTMGR_LABEL="rEFInd"
2021-10-17 22:42:25 +02:00
_BOOTMGR_LOADER_DIR="/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi"
do_uefi_bootmgr_setup
2020-07-18 15:10:43 +02:00
DIALOG --msgbox "refind has been setup successfully." 0 0
2013-07-04 08:42:20 +02:00
DIALOG --msgbox "You will now be put into the editor to edit refind.conf and refind_linux.conf . After you save your changes, exit the editor." 0 0
geteditor || return 1
"${EDITOR}" "${_REFIND_CONFIG}"
DIALOG --defaultno --yesno "Do you want to copy ${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi to ${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi ?\n\nThis might be needed in some systems where efibootmgr may not work due to firmware issues." 0 0 && _UEFISYS_EFI_BOOT_DIR="1"
if [[ "${_UEFISYS_EFI_BOOT_DIR}" == "1" ]]; then
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi" || true
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/refind.conf" || true
rm -rf "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/icons" || true
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/refind_${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
cp -f "${_REFIND_CONFIG}" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/refind.conf"
cp -rf "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/refind/icons" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/icons"
fi
else
2020-07-18 15:10:43 +02:00
DIALOG --msgbox "Error setting up refind." 0 0
fi
}
do_grub_common_before() {
##### Check whether the below limitations still continue with ver 2.00~beta4
2012-06-25 11:34:07 +02:00
### Grub(2) restrictions:
## - Encryption is not recommended for grub(2) /boot!
2012-01-09 13:54:09 +01:00
bootdev=""
grubdev=""
complexuuid=""
FAIL_COMPLEX=""
USE_DMRAID=""
RAID_ON_LVM=""
common_bootloader_checks
2013-05-07 12:02:34 +02:00
abort_f2fs_bootpart || return 1
2012-01-09 13:54:09 +01:00
2011-02-13 17:39:53 +01:00
if ! [[ "$(dmraid -r | grep ^no )" ]]; then
DIALOG --yesno "Setup detected dmraid device.\nDo you want to install grub on this device?" 0 0 && USE_DMRAID="1"
fi
2022-01-05 14:45:36 +01:00
if [[ ! -d "${DESTDIR}/usr/lib/grub" ]]; then
2022-01-05 14:49:33 +01:00
DIALOG --infobox "Couldn't find ${DESTDIR}/usr/lib/grub, installing grub pkg in 3 seconds ..." 0 0
sleep 3
2013-08-22 16:42:38 +02:00
PACKAGES="grub"
run_pacman
# reset PACKAGES after installing
unset PACKAGES
fi
}
do_grub_config() {
chroot_mount
########
2011-02-07 17:07:41 +01:00
2013-08-21 11:52:07 +02:00
BOOT_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/boot" 2>/dev/null)"
BOOT_PART_FS_LABEL="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_label" "/boot" 2>/dev/null)"
BOOT_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/boot" 2>/dev/null)"
BOOT_PART_FS="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs" "/boot" 2>/dev/null)"
2011-02-07 17:07:41 +01:00
2013-08-21 11:52:07 +02:00
BOOT_PART_DRIVE="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="drive" "/boot" 2>/dev/null)"
########
2013-08-21 11:52:07 +02:00
ROOT_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/" 2>/dev/null)"
ROOT_PART_FS_LABEL="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_label" "/" 2>/dev/null)"
ROOT_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/" 2>/dev/null)"
ROOT_PART_FS="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs" "/" 2>/dev/null)"
2013-08-21 11:52:07 +02:00
ROOT_PART_DEVICE="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="device" "/" 2>/dev/null)"
########
2013-08-21 11:52:07 +02:00
USR_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/usr" 2>/dev/null)"
USR_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/usr" 2>/dev/null)"
USR_PART_FS="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs" "/usr" 2>/dev/null)"
########
2011-06-16 17:49:18 +02:00
2012-06-25 11:34:07 +02:00
if [[ "${GRUB_UEFI}" == "1" ]]; then
2013-08-21 11:52:07 +02:00
UEFISYS_PART_FS_UUID="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="fs_uuid" "/${UEFISYS_MOUNTPOINT}" 2>/dev/null)"
UEFISYS_PART_HINTS_STRING="$(chroot "${DESTDIR}" /usr/bin/grub-probe --target="hints_string" "/${UEFISYS_MOUNTPOINT}" 2>/dev/null)"
fi
########
2012-04-23 15:17:42 +02:00
if [[ "$(${_BLKID} -p -i -o value -s PART_ENTRY_SCHEME ${ROOT_PART_DEVICE})" == 'gpt' ]]; then
2013-07-17 10:24:14 +02:00
ROOT_PART_GPT_GUID="$(${_LSBLK} PARTUUID ${ROOT_PART_DEVICE})"
ROOT_PART_GPT_LABEL="$(${_LSBLK} PARTLABEL ${ROOT_PART_DEVICE})"
2012-01-09 13:54:09 +01:00
fi
2011-06-16 17:49:18 +02:00
########
2011-10-27 09:51:17 +02:00
if [[ "${ROOT_PART_FS_UUID}" == "${BOOT_PART_FS_UUID}" ]]; then
subdir="/boot"
2021-09-15 12:23:03 +02:00
# on btrfs we need to check on subvol
2021-09-15 12:29:29 +02:00
if [[ $(mount | grep "${DESTDIR} " | grep btrfs | grep subvol) ]]; then
2021-09-15 12:35:49 +02:00
subdir="/$(echo $(btrfs subvolume show "${DESTDIR}/" | grep Name | cut -d ":" -f2))"/boot
2021-09-15 12:23:03 +02:00
fi
2012-04-19 17:23:56 +02:00
else
subdir=""
2021-09-15 12:23:03 +02:00
# on btrfs we need to check on subvol
2021-10-16 00:08:11 +02:00
if [[ $(mount | grep "${DESTDIR}/boot " | grep btrfs | grep subvol) ]]; then
2021-09-15 12:35:49 +02:00
subdir="/$(echo $(btrfs subvolume show "${DESTDIR}/boot" | grep Name | cut -d ":" -f2))"
2021-09-15 12:23:03 +02:00
fi
fi
########
2011-02-07 17:07:41 +01:00
2012-09-26 12:51:22 +02:00
## Move old config file, if any
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
GRUB_CFG="grub${_SPEC_UEFI_ARCH}.cfg"
else
GRUB_CFG="grub.cfg"
fi
2021-10-19 17:25:56 +02:00
[[ -f "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}" ]] && mv "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}" "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}.bak" || true
2011-02-07 17:07:41 +01:00
## Ignore if the insmod entries are repeated - there are possibilities of having /boot in one disk and root-fs in altogether different disk
## with totally different configuration.
cat << EOF > "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
if [ "\${grub_platform}" == "efi" ]; then
set _UEFI_ARCH="\${grub_cpu}"
if [ "\${grub_cpu}" == "x86_64" ]; then
set _SPEC_UEFI_ARCH="x64"
fi
if [ "\${grub_cpu}" == "i386" ]; then
set _SPEC_UEFI_ARCH="ia32"
fi
2022-01-05 14:45:36 +01:00
if [ "\${grub_cpu}" == "aarch64" ]; then
set _SPEC_UEFI_ARCH="aa64"
fi
fi
EOF
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
insmod part_gpt
insmod part_msdos
2011-02-07 17:07:41 +01:00
# Include fat fs module - required for uefi systems.
insmod fat
2011-02-07 17:07:41 +01:00
insmod ${BOOT_PART_FS}
insmod ${ROOT_PART_FS}
insmod ${USR_PART_FS}
2011-02-07 17:07:41 +01:00
insmod search_fs_file
2011-02-07 17:07:41 +01:00
insmod search_fs_uuid
insmod search_label
2011-02-07 17:07:41 +01:00
insmod linux
insmod chain
set pager="1"
# set debug="all"
set locale_dir="\${prefix}/locale"
EOF
2011-02-07 17:07:41 +01:00
[[ "${USE_RAID}" == "1" ]] && echo "insmod raid" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
! [[ "${RAID_ON_LVM}" == "" ]] && echo "insmod lvm" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
2011-02-07 17:07:41 +01:00
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
2012-03-03 08:25:46 +01:00
if [ -e "\${prefix}/\${grub_cpu}-\${grub_platform}/all_video.mod" ]; then
insmod all_video
else
if [ "\${grub_platform}" == "efi" ]; then
insmod efi_gop
insmod efi_uga
fi
if [ "\${grub_platform}" == "pc" ]; then
insmod vbe
insmod vga
fi
insmod video_bochs
insmod video_cirrus
fi
insmod font
search --fs-uuid --no-floppy --set=usr_part ${USR_PART_HINTS_STRING} ${USR_PART_FS_UUID}
search --fs-uuid --no-floppy --set=root_part ${ROOT_PART_HINTS_STRING} ${ROOT_PART_FS_UUID}
if [ -e "\${prefix}/fonts/unicode.pf2" ]; then
set _fontfile="\${prefix}/fonts/unicode.pf2"
else
if [ -e "(\${root_part})/usr/share/grub/unicode.pf2" ]; then
set _fontfile="(\${root_part})/usr/share/grub/unicode.pf2"
else
if [ -e "(\${usr_part})/share/grub/unicode.pf2" ]; then
set _fontfile="(\${usr_part})/share/grub/unicode.pf2"
fi
fi
fi
if loadfont "\${_fontfile}" ; then
insmod gfxterm
2011-10-27 09:51:17 +02:00
set gfxmode="auto"
terminal_input console
terminal_output gfxterm
fi
EOF
2011-02-07 17:07:41 +01:00
echo "" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
sort "/tmp/.device-names" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
echo "" >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
2011-02-07 17:07:41 +01:00
if [[ "${NAME_SCHEME_PARAMETER}" == "PARTUUID" ]] || [[ "${NAME_SCHEME_PARAMETER}" == "FSUUID" ]] ; then
GRUB_ROOT_DRIVE="search --fs-uuid --no-floppy --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID}"
else
if [[ "${NAME_SCHEME_PARAMETER}" == "PARTLABEL" ]] || [[ "${NAME_SCHEME_PARAMETER}" == "FSLABEL" ]] ; then
GRUB_ROOT_DRIVE="search --label --no-floppy --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_LABEL}"
else
GRUB_ROOT_DRIVE="set root="${BOOT_PART_DRIVE}""
fi
fi
2011-06-16 17:49:18 +02:00
if [[ "${GRUB_UEFI}" == "1" ]]; then
LINUX_UNMOD_COMMAND="linux ${subdir}/${VMLINUZ} ${_KERNEL_PARAMS_UEFI_MOD}"
else
LINUX_UNMOD_COMMAND="linux ${subdir}/${VMLINUZ} ${_KERNEL_PARAMS_BIOS_MOD}"
fi
2011-02-07 17:07:41 +01:00
LINUX_MOD_COMMAND=$(echo "${LINUX_UNMOD_COMMAND}" | sed -e 's# # #g' | sed -e 's# # #g')
## create default kernel entry
2012-09-26 12:51:22 +02:00
NUMBER="0"
2022-01-05 15:21:30 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
# (${NUMBER}) Arch Linux
menuentry "Arch Linux" {
set gfxpayload="keep"
${GRUB_ROOT_DRIVE}
${LINUX_MOD_COMMAND}
initrd ${subdir}/${AMD_UCODE} ${subdir}/${INITRAMFS}.img
}
EOF
NUMBER=$((${NUMBER}+1))
2012-09-26 12:51:22 +02:00
2022-01-05 15:21:30 +01:00
## create kernel fallback entry
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
# (${NUMBER}) Arch Linux Fallback
menuentry "Arch Linux Fallback" {
set gfxpayload="keep"
${GRUB_ROOT_DRIVE}
${LINUX_MOD_COMMAND}
initrd ${subdir}/${AMD_UCODE} ${subdir}/${INITRAMFS}-fallback.img
}
EOF
else
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
2011-02-07 17:07:41 +01:00
# (${NUMBER}) Arch Linux
menuentry "Arch Linux" {
set gfxpayload="keep"
2011-02-07 17:07:41 +01:00
${GRUB_ROOT_DRIVE}
${LINUX_MOD_COMMAND}
initrd ${subdir}/${INTEL_UCODE} ${subdir}/${AMD_UCODE} ${subdir}/${INITRAMFS}.img
2011-02-07 17:07:41 +01:00
}
EOF
NUMBER=$((${NUMBER}+1))
## create kernel fallback entry
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
2011-02-07 17:07:41 +01:00
2011-02-08 23:38:06 +01:00
# (${NUMBER}) Arch Linux Fallback
menuentry "Arch Linux Fallback" {
set gfxpayload="keep"
2011-02-07 17:07:41 +01:00
${GRUB_ROOT_DRIVE}
${LINUX_MOD_COMMAND}
initrd ${subdir}/${INTEL_UCODE} ${subdir}/${AMD_UCODE} ${subdir}/${INITRAMFS}-fallback.img
2011-02-07 17:07:41 +01:00
}
EOF
2011-02-04 14:34:11 +01:00
NUMBER=$((${NUMBER}+1))
2011-02-07 17:07:41 +01:00
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
2011-02-07 17:07:41 +01:00
if [ "\${grub_platform}" == "efi" ]; then
## UEFI Shell 2.0
#menuentry "UEFI Shell \${_UEFI_ARCH} v2" {
# search --fs-uuid --no-floppy --set=root ${UEFISYS_PART_HINTS_STRING} ${UEFISYS_PART_FS_UUID}
# chainloader /EFI/tools/shell\${_SPEC_UEFI_ARCH}_v2.efi
#}
## UEFI Shell 1.0
#menuentry "UEFI Shell \${_UEFI_ARCH} v1" {
# search --fs-uuid --no-floppy --set=root ${UEFISYS_PART_HINTS_STRING} ${UEFISYS_PART_FS_UUID}
# chainloader /EFI/tools/shell\${_SPEC_UEFI_ARCH}_v1.efi
#}
fi
2011-02-07 17:07:41 +01:00
EOF
NUMBER=$((${NUMBER}+1))
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
if [ "\${grub_platform}" == "efi" ]; then
if [ "\${grub_cpu}" == "x86_64" ]; then
## Microsoft Windows 10/11 via x86_64 UEFI
#menuentry \"Microsoft Windows 10/11 x86_64 UEFI-GPT\" {
# insmod part_gpt
# insmod fat
# insmod search_fs_uuid
# insmod chain
# search --fs-uuid --no-floppy --set=root ${UEFISYS_PART_HINTS_STRING} ${UEFISYS_PART_FS_UUID}
# chainloader /EFI/Microsoft/Boot/bootmgfw.efi
#}
fi
fi
EOF
NUMBER=$((${NUMBER}+1))
## TODO: Detect actual Windows installation if any
## create example file for windows
cat << EOF >> "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
if [ "\${grub_platform}" == "pc" ]; then
## Microsoft Windows 10/11 BIOS
#menuentry \"Microsoft Windows 10/11 BIOS-MBR\" {
# insmod part_msdos
# insmod ntfs
# insmod search_fs_uuid
# insmod ntldr
# search --fs-uuid --no-floppy --set=root <FS_UUID of Windows SYSTEM Partition>
# ntldr /bootmgr
#}
fi
2011-02-07 17:07:41 +01:00
EOF
2022-01-05 15:21:30 +01:00
fi
## copy unicode.pf2 font file
2012-06-25 11:34:07 +02:00
cp -f "${DESTDIR}/usr/share/grub/unicode.pf2" "${DESTDIR}/${GRUB_PREFIX_DIR}/fonts/unicode.pf2"
chroot_umount
## Edit grub.cfg config file
2012-06-25 11:34:07 +02:00
DIALOG --msgbox "You must now review the grub(2) configuration file.\n\nYou will now be put into the editor. After you save your changes, exit the editor." 0 0
geteditor || return 1
"${EDITOR}" "${DESTDIR}/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
unset BOOT_PART_FS_UUID
unset BOOT_PART_FS
unset BOOT_PART_FS_LABEL
unset BOOT_PART_DRIVE
2011-02-07 17:07:41 +01:00
unset ROOT_PART_FS_UUID
unset ROOT_PART_FS
unset ROOT_PART_FS_LABEL
unset ROOT_PART_DEVICE
2011-02-07 17:07:41 +01:00
unset GRUB_ROOT_DRIVE
unset LINUX_UNMOD_COMMAND
unset LINUX_MOD_COMMAND
}
do_grub_bios() {
do_grub_common_before
2013-08-22 16:42:38 +02:00
2012-06-25 11:34:07 +02:00
# try to auto-configure GRUB(2)...
2011-02-04 14:34:11 +01:00
if [[ "${PART_ROOT}" != "" ]]; then
check_bootpart
2012-01-09 13:54:09 +01:00
# check if raid, raid partition, dmraid or device devicemapper is used
2011-10-27 09:51:17 +02:00
if [[ "$(echo ${bootdev} | grep /dev/md)" ]] || [[ "$(echo ${bootdev} | grep /dev/mapper)" ]]; then
2012-04-22 20:06:54 +02:00
# boot from lvm, raid, partitioned raid and dmraid devices is supported
FAIL_COMPLEX="0"
2012-01-09 13:54:09 +01:00
2012-04-22 20:06:54 +02:00
if [[ "$(cryptsetup status ${bootdev})" ]]; then
# encryption devices are not supported
FAIL_COMPLEX="1"
fi
fi
2012-01-09 13:54:09 +01:00
2011-10-27 09:51:17 +02:00
if [[ "${FAIL_COMPLEX}" == "0" ]]; then
2011-02-04 14:34:11 +01:00
grubdev=$(basename ${bootdev})
complexuuid=$(getfsuuid ${bootdev})
# check if mapper is used
if [[ "$(echo ${bootdev} | grep /dev/mapper)" ]]; then
RAID_ON_LVM="0"
#check if mapper contains a md device!
for devpath in $(pvs -o pv_name --noheading); do
if [[ "$(echo ${devpath} | grep -v /dev/md*p | grep /dev/md)" ]]; then
detectedvolumegroup="$(echo $(pvs -o vg_name --noheading ${devpath}))"
if [[ "$(echo /dev/mapper/${detectedvolumegroup}-* | grep ${bootdev})" ]]; then
# change bootdev to md device!
bootdev=$(pvs -o pv_name --noheading ${devpath})
RAID_ON_LVM="1"
break
fi
fi
done
fi
#check if raid is used
USE_RAID=""
if [[ "$(echo ${bootdev} | grep /dev/md)" ]]; then
USE_RAID="1"
fi
else
# use normal device
2011-02-04 14:34:11 +01:00
grubdev=$(mapdev ${bootdev})
fi
fi
2011-02-04 14:34:11 +01:00
# A switch is needed if complex ${bootdev} is used!
2012-04-22 20:06:54 +02:00
# - LVM and RAID ${bootdev} needs the MBR of a device and cannot be used itself as ${bootdev}
2011-10-27 09:51:17 +02:00
if [[ "${FAIL_COMPLEX}" == "0" ]]; then
2012-04-22 20:06:54 +02:00
DEVS="$(findbootloaderdisks _)"
2012-01-09 13:54:09 +01:00
2012-04-22 20:06:54 +02:00
if [[ "${DEVS}" == "" ]]; then
2012-10-08 09:14:16 +02:00
DIALOG --msgbox "No storage drives were found" 0 0
2012-04-22 20:06:54 +02:00
return 1
fi
2012-04-22 20:06:54 +02:00
2012-06-25 11:34:07 +02:00
DIALOG --menu "Select the boot device where the GRUB(2) bootloader will be installed." 14 55 7 ${DEVS} 2>${ANSWER} || return 1
2012-04-22 20:06:54 +02:00
bootdev=$(cat ${ANSWER})
else
DEVS="$(findbootloaderdisks _)"
2012-05-26 10:14:32 +02:00
2013-06-22 20:29:23 +02:00
## grub BIOS install to partition is not supported
2012-05-26 10:14:32 +02:00
# DEVS="${DEVS} $(findbootloaderpartitions _)"
2012-01-09 13:54:09 +01:00
2011-10-27 09:51:17 +02:00
if [[ "${DEVS}" == "" ]]; then
2012-10-08 09:14:16 +02:00
DIALOG --msgbox "No storage drives were found" 0 0
return 1
fi
2012-01-09 13:54:09 +01:00
DIALOG --menu "Select the boot device where the GRUB(2) bootloader will be installed." 14 55 7 ${DEVS} 2>${ANSWER} || return 1
2011-02-04 14:34:11 +01:00
bootdev=$(cat ${ANSWER})
fi
2012-04-23 15:17:42 +02:00
if [[ "$(${_BLKID} -p -i -o value -s PTTYPE ${bootdev})" == "gpt" ]]; then
2012-06-25 11:34:07 +02:00
CHECK_BIOS_BOOT_GRUB="1"
CHECK_UEFISYS_PART=""
RUN_CFDISK=""
2011-11-16 20:09:05 +01:00
DISC="${bootdev}"
2011-09-12 21:38:58 +02:00
check_gpt
else
2011-10-27 09:51:17 +02:00
if [[ "${FAIL_COMPLEX}" == "0" ]]; then
2012-06-25 11:34:07 +02:00
DIALOG --defaultno --yesno "Warning:\nSetup detected no GUID (gpt) partition table.\n\nGrub(2) has only space for approx. 30k core.img file. Depending on your setup, it might not fit into this gap and fail.\n\nDo you really want to install grub(2) to a msdos partition table?" 0 0 || return 1
fi
fi
2011-10-27 09:51:17 +02:00
if [[ "${FAIL_COMPLEX}" == "1" ]]; then
2012-06-25 11:34:07 +02:00
DIALOG --msgbox "Error:\nGrub(2) cannot boot from ${bootdev}, which contains /boot!\n\nPossible error sources:\n- encrypted devices are not supported" 0 0
return 1
fi
2012-06-25 11:34:07 +02:00
DIALOG --infobox "Installing the GRUB(2) BIOS bootloader..." 0 0
# freeze and unfreeze xfs filesystems to enable grub(2) installation on xfs filesystems
freeze_xfs
chroot_mount
2012-03-03 08:25:46 +01:00
2013-05-21 12:38:07 +02:00
chroot "${DESTDIR}" "/usr/bin/grub-install" \
2012-03-03 08:25:46 +01:00
--directory="/usr/lib/grub/i386-pc" \
--target="i386-pc" \
--boot-directory="/boot" \
--recheck \
2012-03-26 09:25:29 +02:00
--debug \
2012-06-25 11:34:07 +02:00
"${bootdev}" &>"/tmp/grub_bios_install.log"
2012-03-03 08:25:46 +01:00
chroot_umount
2012-01-09 13:54:09 +01:00
2012-06-24 22:47:53 +02:00
mkdir -p "${DESTDIR}/boot/grub/locale"
cp -f "${DESTDIR}/usr/share/locale/en@quot/LC_MESSAGES/grub.mo" "${DESTDIR}/boot/grub/locale/en.mo"
if [[ -e "${DESTDIR}/boot/grub/i386-pc/core.img" ]]; then
2012-06-25 11:34:07 +02:00
DIALOG --msgbox "GRUB(2) BIOS has been successfully installed." 0 0
2012-06-25 11:34:07 +02:00
GRUB_PREFIX_DIR="/boot/grub/"
GRUB_BIOS="1"
do_grub_config
2012-06-25 11:34:07 +02:00
GRUB_BIOS=""
else
2013-09-14 08:15:58 +02:00
DIALOG --msgbox "Error installing GRUB(2) BIOS.\nCheck /tmp/grub_bios_install.log for more info.\n\nYou probably need to install it manually by chrooting into ${DESTDIR}.\nDon't forget to bind mount /dev and /proc into ${DESTDIR} before chrooting." 0 0
return 1
fi
2012-01-09 13:54:09 +01:00
}
do_grub_uefi() {
do_uefi_common
2014-05-15 09:34:54 +02:00
[[ "${_UEFI_ARCH}" == "X64" ]] && _GRUB_ARCH="x86_64"
[[ "${_UEFI_ARCH}" == "IA32" ]] && _GRUB_ARCH="i386"
2022-01-05 14:45:36 +01:00
[[ "${_UEFI_ARCH}" == "AA64" ]] && _GRUB_ARCH="arm64"
do_grub_common_before
2012-01-09 13:54:09 +01:00
chroot_mount
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
2021-10-17 21:28:54 +02:00
# install fedora shim
2021-10-16 00:08:11 +02:00
[[ ! -d ${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT ]] && mkdir -p ${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/
2021-10-17 22:42:25 +02:00
cp -f /usr/share/archboot/fedora-shim/shim${_SPEC_UEFI_ARCH}.efi ${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/BOOT${_UEFI_ARCH}.efi
cp -f /usr/share/archboot/fedora-shim/mm${_SPEC_UEFI_ARCH}.efi ${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/
GRUB_PREFIX_DIR="${UEFISYS_MOUNTPOINT}/EFI/BOOT/"
else
## Create GRUB Standalone EFI image - https://wiki.archlinux.org/index.php/GRUB#GRUB_Standalone
echo 'configfile ${cmdpath}/grub.cfg' > /tmp/grub.cfg
chroot "${DESTDIR}" "/usr/bin/grub-mkstandalone" \
--directory="/usr/lib/grub/${_GRUB_ARCH}-efi" \
--format="${_GRUB_ARCH}-efi" \
--modules="part_gpt part_msdos" \
--install-modules="all" \
--fonts="unicode" \
--locales="en@quot" \
--themes="" \
--verbose \
--output="${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}_standalone.efi" \
"/boot/grub/grub.cfg=/tmp/grub.cfg" &> "/tmp/grub_uefi_${_UEFI_ARCH}_mkstandalone.log"
## Install GRUB normally
chroot "${DESTDIR}" "/usr/bin/grub-install" \
--directory="/usr/lib/grub/${_GRUB_ARCH}-efi" \
--target="${_GRUB_ARCH}-efi" \
--efi-directory="${UEFISYS_MOUNTPOINT}" \
--bootloader-id="grub" \
--boot-directory="/boot" \
--no-nvram \
--recheck \
--debug &> "/tmp/grub_uefi_${_UEFI_ARCH}_install.log"
cat "/tmp/grub_uefi_${_UEFI_ARCH}_mkstandalone.log" >> "${LOG}"
cat "/tmp/grub_uefi_${_UEFI_ARCH}_install.log" >> "${LOG}"
GRUB_PREFIX_DIR="/boot/grub/"
fi
2021-10-16 00:08:11 +02:00
chroot_umount
GRUB_UEFI="1"
do_grub_config
GRUB_UEFI=""
2021-10-17 22:42:25 +02:00
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
# generate GRUB with config embeded
chroot_mount
2021-10-18 12:04:49 +02:00
#remove existing, else weird things are happening
[[ -f "${DESTDIR}/${GRUB_PREFIX_DIR}/grub${_SPEC_UEFI_ARCH}.efi" ]] && rm ${DESTDIR}/${GRUB_PREFIX_DIR}/grub${_SPEC_UEFI_ARCH}.efi
### Hint: https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/grub.macros#_407
# add -v for verbose
2022-01-05 14:45:36 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
chroot "${DESTDIR}" grub-mkstandalone -d /usr/lib/grub/${_GRUB_ARCH}-efi -O ${_GRUB_ARCH}-efi --sbat=/usr/share/grub/sbat.csv --modules="all_video boot btrfs cat configfile cryptodisk echo efi_gop efifwsetup efinet ext2 f2fs fat font gcry_rijndael gcry_rsa gcry_serpent gcry_sha256 gcry_twofish gcry_whirlpool gfxmenu gfxterm gzio halt hfsplus http iso9660 loadenv loopback linux lvm lsefi lsefimmap luks luks2 mdraid09 mdraid1x minicmd net normal part_apple part_msdos part_gpt password_pbkdf2 pgp png reboot regexp search search_fs_uuid search_fs_file search_label serial sleep syslinuxcfg test tftp video xfs zstd chain tpm" --fonts="unicode" --locales="en@quot" --themes="" -o "${GRUB_PREFIX_DIR}/grub${_SPEC_UEFI_ARCH}.efi" "boot/grub/grub.cfg=/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
else
chroot "${DESTDIR}" grub-mkstandalone -d /usr/lib/grub/${_GRUB_ARCH}-efi -O ${_GRUB_ARCH}-efi --sbat=/usr/share/grub/sbat.csv --modules="all_video boot btrfs cat configfile cryptodisk echo efi_gop efi_uga efifwsetup efinet ext2 f2fs fat font gcry_rijndael gcry_rsa gcry_serpent gcry_sha256 gcry_twofish gcry_whirlpool gfxmenu gfxterm gzio halt hfsplus http iso9660 loadenv loopback linux lvm lsefi lsefimmap luks luks2 mdraid09 mdraid1x minicmd net normal part_apple part_msdos part_gpt password_pbkdf2 pgp png reboot regexp search search_fs_uuid search_fs_file search_label serial sleep syslinuxcfg test tftp video xfs zstd backtrace chain tpm usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug keylayouts at_keyboard" --fonts="unicode" --locales="en@quot" --themes="" -o "${GRUB_PREFIX_DIR}/grub${_SPEC_UEFI_ARCH}.efi" "boot/grub/grub.cfg=/${GRUB_PREFIX_DIR}/${GRUB_CFG}"
fi
2021-10-17 22:42:25 +02:00
cp /${GRUB_PREFIX_DIR}/${GRUB_CFG} ${UEFISYS_MOUNTPOINT}/EFI/BOOT/grub${_SPEC_UEFI_ARCH}.cfg
chroot_umount
fi
if [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}_standalone.efi" ]]; then
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/${GRUB_PREFIX_DIR}/grub.cfg" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub.cfg"
_BOOTMGR_LABEL="GRUB_Standalone"
2021-10-17 22:42:25 +02:00
_BOOTMGR_LOADER_DIR="/EFI/grub/grub${_SPEC_UEFI_ARCH}_standalone.efi"
do_uefi_bootmgr_setup
2021-10-16 23:14:46 +02:00
DIALOG --msgbox "GRUB(2) Standalone for ${_UEFI_ARCH} UEFI has been installed successfully." 8 65
elif [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi" ]] && [[ -e "${DESTDIR}/boot/grub/${_GRUB_ARCH}-efi/core.efi" ]]; then
_BOOTMGR_LABEL="GRUB_Normal"
2021-10-17 22:42:25 +02:00
_BOOTMGR_LOADER_DIR="/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi"
do_uefi_bootmgr_setup
2021-10-16 23:14:46 +02:00
DIALOG --msgbox "GRUB(2) for ${_UEFI_ARCH} UEFI has been installed successfully." 8 65
2022-01-05 15:38:15 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
_UEFISYS_EFI_BOOT_DIR="1"
else
DIALOG --defaultno --yesno "Do you want to copy ${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi to ${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi ?\n\nThis might be needed in some systems where efibootmgr may not work due to firmware issues." 0 0 && _UEFISYS_EFI_BOOT_DIR="1"
fi
if [[ "${_UEFISYS_EFI_BOOT_DIR}" == "1" ]]; then
mkdir -p "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT"
rm -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi" || true
cp -f "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/grub/grub${_SPEC_UEFI_ARCH}.efi" "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/boot${_SPEC_UEFI_ARCH}.efi"
fi
elif [[ -e "${DESTDIR}/${UEFISYS_MOUNTPOINT}/EFI/BOOT/grub${_SPEC_UEFI_ARCH}.efi" ]]; then
do_secureboot_keys
do_mok_sign
do_pacman_sign
do_uefi_secure_boot_efitools
2021-10-17 19:48:46 +02:00
_BOOTMGR_LABEL="SHIM with GRUB Secure Boot"
2021-10-17 22:42:25 +02:00
_BOOTMGR_LOADER_DIR="/EFI/BOOT/BOOT${_UEFI_ARCH}.efi"
2021-10-17 19:48:46 +02:00
do_uefi_bootmgr_setup
2021-10-16 23:14:46 +02:00
DIALOG --msgbox "SHIM and GRUB Secure Boot for ${_UEFI_ARCH} UEFI has been installed successfully." 8 75
else
2014-05-15 09:34:54 +02:00
DIALOG --msgbox "Error installing GRUB(2) for ${_UEFI_ARCH} UEFI.\nCheck /tmp/grub_uefi_${_UEFI_ARCH}_install.log for more info.\n\nYou probably need to install it manually by chrooting into ${DESTDIR}.\nDon't forget to bind mount /dev, /sys and /proc into ${DESTDIR} before chrooting." 0 0
return 1
fi
}
2012-01-09 13:54:09 +01:00
select_source() {
2021-09-26 15:28:45 +02:00
NEXTITEM="2"
MODE="network"
if [[ ${S_NET} -eq 0 ]]; then
donetwork || return 1
fi
if [[ ${S_TESTING} -eq 0 ]]; then
[[ "${RUNNING_ARCH}" == "x86_64" ]] && dotesting
fi
TITLE="Arch Linux Installation"
2013-03-25 17:48:49 +01:00
getsource || return 1
# check for updating complete environment with packages
2021-10-16 08:54:16 +02:00
if [[ -d "/var/cache/pacman/pkg" ]] && [[ -n "$(ls -A "/var/cache/pacman/pkg")" ]]; then
echo "Packages are already in pacman cache... > ${LOG}"
else
2021-10-16 08:54:16 +02:00
detect_uefi_boot
UPDATE_ENVIRONMENT=""
2022-01-04 15:25:30 +01:00
if [[ -e "/usr/bin/update-installer.sh" && "${_DETECTED_UEFI_SECURE_BOOT}" == "0" && "${RUNNING_ARCH}" == "x86_64" ]]; then
2021-12-12 14:22:27 +01:00
DIALOG --defaultno --yesno "${_DETECTED_UEFI_SECURE_BOOT} Do you want to update the archboot environment to latest packages with caching packages for installation?\n\nATTENTION:\nRequires at least 4GB RAM and will reboot the system using kexec!" 0 0 && UPDATE_ENVIRONMENT="1"
if [[ "${UPDATE_ENVIRONMENT}" == "1" ]]; then
DIALOG --infobox "Now setting up new archboot environment and dowloading latest packages.\n\nRunning at the moment: update-installer.sh -latest-install\nCheck "${LOG}" for progress...\n\nGet a cup of coffee ...\nThis needs approx. 5 minutes on a fast internet connection (100Mbit)." 0 0
/usr/bin/update-installer.sh -latest-install > "${LOG}" 2>&1
fi
fi
fi
2021-09-26 15:28:45 +02:00
NEXTITEM="3"
2008-10-20 22:39:25 +02:00
}
2012-01-09 13:54:09 +01:00
set_clock() {
2011-02-03 21:54:43 +01:00
if [[ -e /usr/bin/tz ]]; then
2021-09-26 15:28:45 +02:00
tz --setup && NEXTITEM="4"
else
DIALOG --msgbox "Error:\ntz script not found, aborting clock setting" 0 0
fi
2008-10-20 22:39:25 +02:00
}
2012-01-09 13:54:09 +01:00
set_keyboard() {
2011-02-03 21:54:43 +01:00
if [[ -e /usr/bin/km ]]; then
2012-08-03 11:37:44 +02:00
km --setup && NEXTITEM="1"
else
DIALOG --msgbox "Error:\nkm script not found, aborting keyboard and console setting" 0 0
fi
2008-10-20 22:39:25 +02:00
}
# run_mkinitcpio()
# runs mkinitcpio on the target system, displays output
#
2012-01-09 13:54:09 +01:00
run_mkinitcpio() {
chroot_mount
# all mkinitcpio output goes to /tmp/mkinitcpio.log, which we tail into a dialog
( \
touch /tmp/setup-mkinitcpio-running
echo "Initramfs progress ..." > /tmp/initramfs.log; echo >> /tmp/mkinitcpio.log
2022-01-05 15:21:30 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
chroot ${DESTDIR} /usr/bin/mkinitcpio -p ${KERNELPKG}-${RUNNING_ARCH} >>/tmp/mkinitcpio.log 2>&1
else
chroot ${DESTDIR} /usr/bin/mkinitcpio -p ${KERNELPKG} >>/tmp/mkinitcpio.log 2>&1
fi
echo >> /tmp/mkinitcpio.log
2009-02-11 12:03:41 +01:00
rm -f /tmp/setup-mkinitcpio-running
) &
2009-02-11 12:03:41 +01:00
sleep 2
2011-02-04 14:34:11 +01:00
dialog --backtitle "${TITLE}" --title "Rebuilding initramfs images ..." --no-kill --tailboxbg "/tmp/mkinitcpio.log" 18 70
2011-02-03 21:54:43 +01:00
while [[ -f /tmp/setup-mkinitcpio-running ]]; do
2013-06-07 08:53:17 +02:00
/usr/bin/true
done
chroot_umount
}
2012-10-08 09:14:16 +02:00
prepare_storagedrive() {
S_MKFSAUTO=0
S_MKFS=0
DONE=0
NEXTITEM=""
2021-10-16 09:06:06 +02:00
detect_
2011-02-04 14:34:11 +01:00
while [[ "${DONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
2012-10-08 09:14:16 +02:00
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Prepare Storage Drive" 12 60 5 \
"1" "Auto-Prepare (erases the ENTIRE storage drive)" \
"2" "Partition Storage Drives" \
2009-04-17 22:29:31 +02:00
"3" "Create Software Raid, Lvm2 and Luks encryption" \
"4" "Set Filesystem Mountpoints" \
2011-02-04 14:34:11 +01:00
"5" "Return to Main Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
[[ "${S_MKFSAUTO}" = "1" ]] && DONE=1
case $(cat ${ANSWER}) in
"1")
2009-02-11 12:03:41 +01:00
autoprepare
2011-02-04 14:34:11 +01:00
[[ "${S_MKFSAUTO}" = "1" ]] && DONE=1
;;
"2")
partition ;;
"3")
create_special ;;
"4")
2009-02-11 22:31:52 +01:00
PARTFINISH=""
ASK_MOUNTPOINTS="1"
mountpoints ;;
*)
DONE=1 ;;
esac
done
2011-02-04 14:34:11 +01:00
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="4"
2021-09-26 15:28:45 +02:00
else
NEXTITEM="5"
fi
}
# menu for raid, lvm and encrypt
2012-01-09 13:54:09 +01:00
create_special() {
NEXTITEM=""
2009-02-14 18:51:13 +01:00
SPECIALDONE=0
2011-02-04 14:34:11 +01:00
while [[ "${SPECIALDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
2011-02-04 14:34:11 +01:00
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create Software Raid, LVM2 and Luks encryption" 14 60 5 \
"1" "Create Software Raid" \
2009-04-17 22:29:31 +02:00
"2" "Create LVM2" \
"3" "Create Luks encryption" \
2011-02-04 14:34:11 +01:00
"4" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"1")
2009-02-11 22:31:52 +01:00
_createmd ;;
"2")
2009-02-11 22:31:52 +01:00
_createlvm ;;
"3")
2009-04-17 22:29:31 +02:00
_createluks ;;
*)
2009-02-14 18:51:13 +01:00
SPECIALDONE=1 ;;
esac
done
2011-02-04 14:34:11 +01:00
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="3"
else
NEXTITEM="4"
fi
2008-10-20 22:39:25 +02:00
}
2009-04-17 22:29:31 +02:00
# menu for md creation
2012-01-09 13:54:09 +01:00
_createmd() {
2009-04-17 22:29:31 +02:00
NEXTITEM=""
MDDONE=0
2011-02-04 14:34:11 +01:00
while [[ "${MDDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
2009-04-17 22:29:31 +02:00
else
DEFAULT=""
fi
CANCEL=""
2011-02-04 14:34:11 +01:00
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create Software Raid" 12 60 5 \
2009-04-17 22:29:31 +02:00
"1" "Raid Help" \
"2" "Reset Software Raid completely" \
"3" "Create Software Raid" \
"4" "Create Partitionable Software Raid" \
2011-02-04 14:34:11 +01:00
"5" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
2009-04-17 22:29:31 +02:00
"1")
_helpraid ;;
"2")
_stopmd ;;
"3")
RAID_PARTITION=""
2009-04-17 22:29:31 +02:00
_raid ;;
"4")
RAID_PARTITION="1"
_raid ;;
2009-04-17 22:29:31 +02:00
*)
MDDONE=1 ;;
esac
done
2011-02-04 14:34:11 +01:00
if [[ "${CANCEL}" = "1" ]]; then
2009-04-17 22:29:31 +02:00
NEXTITEM="1"
else
NEXTITEM="4"
fi
}
# menu for lvm creation
2012-01-09 13:54:09 +01:00
_createlvm() {
NEXTITEM=""
LVMDONE=0
2011-02-04 14:34:11 +01:00
while [[ "${LVMDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
2011-02-04 14:34:11 +01:00
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create physical volume, volume group or logical volume" 13 60 7 \
"1" "LVM Help" \
"2" "Reset Logical Volume completely" \
"3" "Create Physical Volume" \
"4" "Create Volume Group" \
"5" "Create Logical Volume" \
2011-02-04 14:34:11 +01:00
"6" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"1")
_helplvm ;;
"2")
_stoplvm ;;
"3")
_createpv ;;
"4")
_createvg ;;
"5")
_createlv ;;
*)
LVMDONE=1 ;;
esac
done
2011-02-04 14:34:11 +01:00
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="2"
else
NEXTITEM="4"
fi
}
2009-04-17 22:29:31 +02:00
# menu for luks creation
2012-01-09 13:54:09 +01:00
_createluks() {
NEXTITEM=""
2009-04-17 22:29:31 +02:00
LUKSDONE=0
2011-02-04 14:34:11 +01:00
while [[ "${LUKSDONE}" = "0" ]]; do
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
CANCEL=""
2011-02-04 14:34:11 +01:00
dialog ${DEFAULT} --backtitle "${TITLE}" --menu "Create Luks Encryption" 12 60 5 \
2009-04-17 22:29:31 +02:00
"1" "Luks Help" \
"2" "Reset Luks Encryption completely" \
"3" "Create Luks" \
2011-02-04 14:34:11 +01:00
"4" "Return to Previous Menu" 2>${ANSWER} || CANCEL="1"
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"1")
2009-04-17 22:29:31 +02:00
_helpluks ;;
"2")
2009-04-17 22:29:31 +02:00
_stopluks ;;
"3")
2009-04-17 22:29:31 +02:00
_luks ;;
*)
2009-04-17 22:29:31 +02:00
LUKSDONE=1 ;;
esac
done
2011-02-04 14:34:11 +01:00
if [[ "${CANCEL}" = "1" ]]; then
2009-04-17 22:29:31 +02:00
NEXTITEM="3"
else
NEXTITEM="4"
fi
}
2012-01-09 13:54:09 +01:00
auto_hwdetect() {
HWDETECT=""
FBPARAMETER=""
HWPARAMETER=""
HWDETECTMODULES=""
HWDETECTHOOKS=""
HWKVER==
DIALOG --yesno "PRECONFIGURATION?\n-----------------\n\nDo you want to use 'hwdetect' for:\n'/etc/mkinitcpio.conf'?\n\nThis ensures consistent ordering of your storage disk / usb controllers.\n\nIt is recommended to say 'YES' here." 18 70 && HWDETECT="yes"
2011-02-04 14:34:11 +01:00
if [[ "${HWDETECT}" = "yes" ]]; then
# check on used keymap
! [[ "$(grep '^KEYMAP="us"' ${DESTDIR}/etc/vconsole.conf)" ]] && HWPARAMETER="${HWPARAMETER} --keymap"
# check on framebuffer modules and kms
[[ "$(grep "^radeon" /proc/modules)" ]] && FBPARAMETER="--ati-kms"
2021-10-07 14:32:51 +02:00
[[ "$(grep "^amdgpu" /proc/modules)" ]] && FBPARAMETER="--amd-kms"
[[ "$(grep "^i915" /proc/modules )" ]] && FBPARAMETER="--intel-kms"
[[ "$(grep "^nouveau" /proc/modules)" ]] && FBPARAMETER="--nvidia-kms"
2012-01-09 13:54:09 +01:00
if [[ "$(lsmod | grep ^nfs)" ]]; then
2011-02-04 14:34:11 +01:00
DIALOG --defaultno --yesno "Setup detected nfs driver...\nDo you need support for booting from nfs shares?" 0 0 && HWPARAMETER="${HWPARAMETER} --nfs"
fi
2011-02-04 14:34:11 +01:00
if [[ -e ${DESTDIR}/lib/initcpio/hooks/dmraid ]]; then
2011-02-03 21:54:43 +01:00
if ! [[ "$(dmraid -r | grep ^no )" ]]; then
2011-02-04 14:34:11 +01:00
HWPARAMETER="${HWPARAMETER} --dmraid"
fi
fi
2013-01-21 17:19:00 +01:00
offset=$(hexdump -s 526 -n 2 -e '"%0d"' "${DESTDIR}/boot/${VMLINUZ}")
read HWKER _ < <(dd if="${DESTDIR}/boot/${VMLINUZ}" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null)
HWDETECTMODULES="$(echo $(hwdetect --kernel_directory=${DESTDIR} --kernel_version=${HWKVER} ${FBPARAMETER} --hostcontroller --filesystem ${HWPARAMETER}) | sed -e 's#.*\" ##g')"
HWDETECTHOOKS="$(hwdetect --kernel_directory=${DESTDIR} --kernel_version=${HWKVER} --rootdevice=${PART_ROOT} --hooks-dir=${DESTDIR}/usr/lib/initcpio/install ${FBPARAMETER} ${HWPARAMETER} --hooks)"
2011-02-04 14:34:11 +01:00
[[ -n "${HWDETECTMODULES}" ]] && sed -i -e "s/^MODULES=.*/${HWDETECTMODULES}/g" ${DESTDIR}/etc/mkinitcpio.conf
[[ -n "${HWDETECTHOOKS}" ]] && sed -i -e "s/^HOOKS=.*/${HWDETECTHOOKS}/g" ${DESTDIR}/etc/mkinitcpio.conf
fi
}
2012-01-09 13:54:09 +01:00
auto_parameters() {
if [[ ! -f ${DESTDIR}/etc/vconsole.conf ]]; then
: >${DESTDIR}/etc/vconsole.conf
2012-06-14 19:19:38 +02:00
if [[ -s /tmp/.keymap ]]; then
DIALOG --infobox "Setting the keymap: $(cat /tmp/.keymap | sed -e 's/\..*//g') in vconsole.conf ..." 0 0
echo KEYMAP=$(cat /tmp/.keymap | sed -e 's/\..*//g') >> ${DESTDIR}/etc/vconsole.conf
2012-06-01 18:51:20 +02:00
fi
if [[ -s /tmp/.font ]]; then
DIALOG --infobox "Setting the consolefont: $(cat /tmp/.font | sed -e 's/\..*//g') in vconsole.conf ..." 0 0
echo FONT=$(cat /tmp/.font | sed -e 's/\..*//g') >> ${DESTDIR}/etc/vconsole.conf
2012-06-01 18:51:20 +02:00
fi
fi
2008-12-14 11:20:01 +01:00
}
2012-01-09 13:54:09 +01:00
auto_luks() {
2011-02-06 22:12:44 +01:00
# remove root device from crypttab
2011-02-04 14:34:11 +01:00
if [[ -e /tmp/.crypttab && "$(grep -v '^#' ${DESTDIR}/etc/crypttab)" = "" ]]; then
2011-02-06 22:12:44 +01:00
# add to temp crypttab
2011-02-08 17:06:48 +01:00
sed -i -e "/^$(basename ${PART_ROOT}) /d" /tmp/.crypttab
2011-02-04 14:34:11 +01:00
cat /tmp/.crypttab >> ${DESTDIR}/etc/crypttab
2012-07-27 12:02:05 +02:00
chmod 600 /tmp/passphrase-* 2>/dev/null
cp /tmp/passphrase-* ${DESTDIR}/etc/ 2>/dev/null
2009-04-19 17:19:37 +02:00
fi
}
2012-01-09 13:54:09 +01:00
auto_timesetting() {
2013-05-08 09:39:23 +02:00
if [[ -e /etc/localtime && ! -e ${DESTDIR}/etc/localtime ]]; then
cp -a /etc/localtime ${DESTDIR}/etc/localtime
fi
2012-08-01 09:09:55 +02:00
if [[ ! -f ${DESTDIR}/etc/adjtime ]]; then
echo "0.0 0 0.0" > ${DESTDIR}/etc/adjtime
2012-08-06 17:06:20 +02:00
echo "0" >> ${DESTDIR}/etc/adjtime
[[ -s /tmp/.hardwareclock ]] && cat /tmp/.hardwareclock >>${DESTDIR}/etc/adjtime
fi
2008-12-15 21:25:05 +01:00
}
2013-07-12 12:10:40 +02:00
auto_pacman_mirror() {
# /etc/pacman.d/mirrorlist
# add installer-selected mirror to the top of the mirrorlist
if [[ "${MODE}" = "network" && "${SYNC_URL}" != "" ]]; then
2011-02-04 14:34:11 +01:00
SYNC_URL="${SYNC_URL}"
awk "BEGIN { printf(\"# Mirror used during installation\nServer = "${SYNC_URL}"\n\n\") } 1 " "${DESTDIR}/etc/pacman.d/mirrorlist" > /tmp/inst-mirrorlist
mv /tmp/inst-mirrorlist "${DESTDIR}/etc/pacman.d/mirrorlist"
fi
}
auto_system_files () {
if [[ ! -f ${DESTDIR}/etc/hostname ]]; then
echo "myhostname" > ${DESTDIR}/etc/hostname
fi
if [[ ! -f ${DESTDIR}/etc/locale.conf ]]; then
echo "LANG=en_US.UTF-8" > ${DESTDIR}/etc/locale.conf
echo "LC_COLLATE=C" >> ${DESTDIR}/etc/locale.conf
2012-06-01 21:10:24 +02:00
fi
2012-06-01 21:07:27 +02:00
}
2012-01-09 13:54:09 +01:00
configure_system() {
2011-06-10 16:57:49 +02:00
destdir_mounts || return 1
## PREPROCESSING ##
# only done on first invocation of configure_system and redone on canceled configure system
2011-02-04 14:34:11 +01:00
if [[ ${S_CONFIG} -eq 0 ]]; then
2013-07-12 12:10:40 +02:00
auto_pacman_mirror
auto_network
auto_parameters
auto_system_files
auto_hwdetect
fi
## END PREPROCESS ##
geteditor || return 1
FILE=""
# main menu loop
while true; do
S_CONFIG=0
2011-02-04 14:34:11 +01:00
if [[ -n "${FILE}" ]]; then
DEFAULT="--default-item ${FILE}"
else
DEFAULT=""
fi
2012-07-24 14:01:22 +02:00
DIALOG ${DEFAULT} --menu "Configuration" 21 80 16 \
"/etc/hostname" "System Hostname" \
"/etc/vconsole.conf" "Virtual Console" \
"/etc/locale.conf" "Locale Setting" \
"/etc/fstab" "Filesystem Mountpoints" \
"/etc/mkinitcpio.conf" "Initramfs Config" \
"/etc/modprobe.d/modprobe.conf" "Kernel Modules" \
"/etc/resolv.conf" "DNS Servers" \
"/etc/hosts" "Network Hosts" \
"/etc/locale.gen" "Glibc Locales" \
"/etc/pacman.d/mirrorlist" "Pacman Mirror List" \
"/etc/pacman.conf" "Pacman Config File" \
"Root-Password" "Set the root password" \
"Return" "Return to Main Menu" 2>${ANSWER} || break
2011-02-04 14:34:11 +01:00
FILE="$(cat ${ANSWER})"
if [[ "${FILE}" = "Return" || -z "${FILE}" ]]; then # exit
S_CONFIG=1
break
2011-02-04 14:34:11 +01:00
elif [[ "${FILE}" = "/etc/mkinitcpio.conf" ]]; then # non-file
DIALOG --msgbox "The mkinitcpio.conf file controls which modules will be placed into the initramfs for your system's kernel.\n\n- Non US keymap users should add 'keymap' to HOOKS= array\n- If you install under VMWARE add 'BusLogic' to MODULES= array\n- raid, lvm2, encrypt are not enabled by default\n- 2 or more disk controllers, please specify the correct module\n loading order in MODULES= array \n\nMost of you will not need to change anything in this file." 18 70
HOOK_ERROR=""
2011-02-04 14:34:11 +01:00
${EDITOR} ${DESTDIR}${FILE}
for i in $(cat ${DESTDIR}/etc/mkinitcpio.conf | grep ^HOOKS | sed -e 's/"//g' -e 's/HOOKS=//g'); do
2012-04-20 15:36:41 +02:00
[[ -e ${DESTDIR}/usr/lib/initcpio/install/${i} ]] || HOOK_ERROR=1
done
2011-02-04 14:34:11 +01:00
if [[ "${HOOK_ERROR}" = "1" ]]; then
DIALOG --msgbox "ERROR: Detected error in 'HOOKS=' line, please correct HOOKS= in /etc/mkinitcpio.conf!" 18 70
fi
2011-02-04 14:34:11 +01:00
elif [[ "${FILE}" = "/etc/locale.gen" ]]; then # non-file
# enable glibc locales from locale.conf
for i in $(grep "^LANG" ${DESTDIR}/etc/locale.conf | sed -e 's/.*=//g' -e's/\..*//g'); do
sed -i -e "s/^#${i}/${i}/g" ${DESTDIR}/etc/locale.gen
done
2011-02-04 14:34:11 +01:00
${EDITOR} ${DESTDIR}${FILE}
elif [[ "${FILE}" = "Root-Password" ]]; then # non-file
2009-04-19 00:02:34 +02:00
PASSWORD=""
2011-02-04 14:34:11 +01:00
while [[ "${PASSWORD}" = "" ]]; do
DIALOG --insecure --passwordbox "Enter root password:" 0 0 2>${ANSWER} || return 1
PASS=$(cat ${ANSWER})
DIALOG --insecure --passwordbox "Retype root password:" 0 0 2>${ANSWER} || return 1
PASS2=$(cat ${ANSWER})
if [[ "${PASS}" = "${PASS2}" ]]; then
PASSWORD=${PASS}
echo ${PASSWORD} > /tmp/.password
echo ${PASSWORD} >> /tmp/.password
2009-04-19 00:02:34 +02:00
PASSWORD=/tmp/.password
else
DIALOG --msgbox "Password didn't match, please enter again." 0 0
fi
done
2011-02-04 14:34:11 +01:00
chroot ${DESTDIR} passwd root < /tmp/.password
2009-04-19 00:02:34 +02:00
rm /tmp/.password
else #regular file
2011-02-04 14:34:11 +01:00
${EDITOR} ${DESTDIR}${FILE}
2009-02-11 12:03:41 +01:00
fi
done
2011-02-04 14:34:11 +01:00
if [[ ${S_CONFIG} -eq 1 ]]; then
# only done on normal exit of configure menu
## POSTPROCESSING ##
# adjust time
auto_timesetting
# /etc/initcpio.conf
run_mkinitcpio
# /etc/locale.gen
2012-08-02 12:00:49 +02:00
# enable at least en_US.UTF8 if nothing was changed, else weird things happen on reboot!
! [[ $(grep -q ^[a-z] ${DESTDIR}/etc/locale.gen) ]] && sed -i -e 's:^#en_US.UTF-8:en_US.UTF-8:g' ${DESTDIR}/etc/locale.gen
2011-02-04 14:34:11 +01:00
chroot ${DESTDIR} locale-gen >/dev/null 2>&1
## END POSTPROCESSING ##
NEXTITEM="7"
fi
2008-10-20 22:39:25 +02:00
}
install_bootloader_uefi() {
do_uefi_setup_env_vars
2014-06-04 09:04:42 +02:00
if [[ "${_EFI_MIXED}" == "1" ]]; then
2014-05-15 09:34:54 +02:00
_EFISTUB_MENU_LABEL=""
_EFISTUB_MENU_TEXT=""
else
_EFISTUB_MENU_LABEL="EFISTUB"
_EFISTUB_MENU_TEXT="EFISTUB for ${_UEFI_ARCH} UEFI"
fi
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
do_grub_uefi
else
2022-01-05 14:45:36 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
DIALOG --menu "Which ${_UEFI_ARCH} UEFI bootloader would you like to use?" 12 55 5 \
"${_EFISTUB_MENU_LABEL}" "${_EFISTUB_MENU_TEXT}" \
2022-01-05 14:45:36 +01:00
"GRUB_UEFI" "GRUB(2) for ${_UEFI_ARCH} UEFI" 2>${ANSWER} || CANCEL=1
else
DIALOG --menu "Which ${_UEFI_ARCH} UEFI bootloader would you like to use?" 12 55 5 \
"${_EFISTUB_MENU_LABEL}" "${_EFISTUB_MENU_TEXT}" \
2022-01-16 16:14:12 +01:00
"GRUB_UEFI" "GRUB(2) for ${_UEFI_ARCH} UEFI" 2>${ANSWER} || CANCEL=1
2022-01-05 14:45:36 +01:00
fi
case $(cat ${ANSWER}) in
"EFISTUB") do_efistub_uefi ;;
"GRUB_UEFI") do_grub_uefi ;;
esac
fi
}
install_bootloader_bios() {
2012-04-20 16:07:05 +02:00
DIALOG --menu "Which BIOS bootloader would you like to use?" 11 50 4 \
2022-01-16 16:14:12 +01:00
"GRUB_BIOS" "GRUB(2) BIOS" 2>${ANSWER} || CANCEL=1
case $(cat ${ANSWER}) in
"GRUB_BIOS") do_grub_bios ;;
esac
}
2012-01-09 13:54:09 +01:00
install_bootloader() {
destdir_mounts || return 1
2012-01-21 09:43:36 +01:00
if [[ "${NAME_SCHEME_PARAMETER_RUN}" == "" ]]; then
set_device_name_scheme || return 1
fi
if [[ "${S_SRC}" = "0" ]]; then
select_source || return 1
fi
prepare_pacman
CANCEL=""
detect_uefi_boot
_ANOTHER="1"
2021-10-16 09:06:06 +02:00
NEXTITEM="7"
if [[ "${_DETECTED_UEFI_BOOT}" == "1" ]]; then
do_uefi_setup_env_vars
2021-10-16 00:08:11 +02:00
_ANOTHER="0"
if [[ "${_DETECTED_UEFI_SECURE_BOOT}" == "1" ]]; then
2021-10-16 23:14:46 +02:00
DIALOG --yesno "Setup has detected that you are using Secure Boot ...\nDo you like to install SHIM and GRUB ${_UEFI_ARCH} UEFI bootloader?" 0 0 || CANCEL="1"
2021-10-16 09:15:47 +02:00
if [[ "${CANCEL}" == "" ]]; then
install_bootloader_uefi
NEXTITEM="8"
else
NEXTITEM="7"
fi
else
DIALOG --yesno "Setup has detected that you are using ${_UEFI_ARCH} UEFI ...\nDo you like to install a ${_UEFI_ARCH} UEFI bootloader?" 0 0 && install_bootloader_uefi
2021-10-16 00:08:11 +02:00
DIALOG --defaultno --yesno "Do you want to install another bootloader?" 0 0 && _ANOTHER="1"
2021-10-16 09:06:06 +02:00
NEXTITEM="8"
fi
fi
2013-09-22 14:11:49 +02:00
while [[ "${_ANOTHER}" == "1" ]]; do
install_bootloader_menu
_ANOTHER="0"
DIALOG --defaultno --yesno "Do you want to install another bootloader?" 0 0 && _ANOTHER="1"
done
}
install_bootloader_menu() {
2022-01-05 14:45:36 +01:00
if [[ "${RUNNING_ARCH}" == "aarch64" ]]; then
ANSWER="UEFI"
else
DIALOG --menu "What is your boot system type?" 10 40 2 \
"UEFI" "UEFI" \
"BIOS" "BIOS" 2>${ANSWER} || CANCEL=1
case $(cat ${ANSWER}) in
"UEFI") install_bootloader_uefi ;;
"BIOS") install_bootloader_bios ;;
esac
fi
2011-02-04 14:34:11 +01:00
if [[ "${CANCEL}" = "1" ]]; then
NEXTITEM="7"
2012-07-26 14:33:41 +02:00
else
NEXTITEM="8"
fi
2008-10-20 22:39:25 +02:00
}
mainmenu() {
2011-02-04 14:34:11 +01:00
if [[ -n "${NEXTITEM}" ]]; then
DEFAULT="--default-item ${NEXTITEM}"
else
DEFAULT=""
fi
2011-02-04 14:34:11 +01:00
dialog ${DEFAULT} --backtitle "${TITLE}" --title " MAIN MENU " \
2012-07-26 14:33:41 +02:00
--menu "Use the UP and DOWN arrows to navigate menus.\nUse TAB to switch between buttons and ENTER to select." 18 58 14 \
"0" "Set Keyboard And Console Font" \
2012-07-26 14:33:41 +02:00
"1" "Set up Network" \
2021-09-26 15:28:45 +02:00
"2" "Select Source" \
"3" "Set Time And Date" \
"4" "Prepare Storage Drive" \
"5" "Install Packages" \
"6" "Configure System" \
"7" "Install Bootloader" \
"8" "Exit Install" 2>${ANSWER}
2011-02-04 14:34:11 +01:00
NEXTITEM="$(cat ${ANSWER})"
case $(cat ${ANSWER}) in
"0")
set_keyboard ;;
"1")
2012-07-26 14:33:41 +02:00
donetwork ;;
"2")
2021-09-26 15:28:45 +02:00
select_source ;;
"3")
2021-09-26 15:28:45 +02:00
set_clock ;;
"4")
2021-09-26 15:28:45 +02:00
prepare_storagedrive ;;
"5")
2012-07-26 14:33:41 +02:00
install_packages ;;
"6")
2012-07-26 14:33:41 +02:00
configure_system ;;
"7")
2012-07-26 14:33:41 +02:00
install_bootloader ;;
"8")
2011-02-03 21:54:43 +01:00
[[ -e /tmp/.setup-running ]] && rm /tmp/.setup-running
clear
echo ""
echo "If the install finished successfully, you can now type 'reboot'"
echo "to restart the system."
echo ""
exit 0 ;;
*)
2011-02-03 21:54:43 +01:00
DIALOG --yesno "Abort Installation?" 6 40 && [[ -e /tmp/.setup-running ]] && rm /tmp/.setup-running && clear && exit 0
;;
esac
2008-10-20 22:39:25 +02:00
}
#####################
## begin execution ##
2011-02-03 21:54:43 +01:00
if [[ -e /tmp/.setup-running ]]; then
echo "HINT:"
echo "setup already runs on a different console!"
echo "Please remove /tmp/.setup-running first to launch setup!"
exit 1
2009-02-11 12:03:41 +01:00
fi
2008-10-20 22:39:25 +02:00
: >/tmp/.setup-running
: >/tmp/.setup
DIALOG --msgbox "Welcome to the Arch Linux Installation program.\n\nThe install process is fairly straightforward, and you should run through the options in the order they are presented.\n\nIf you are unfamiliar with partitioning/making filesystems, you may want to consult some documentation before continuing.\n\nYou can view all output from commands by viewing your VC7 console (ALT-F7). ALT-F1 will bring you back here." 14 65
2008-10-20 22:39:25 +02:00
while true; do
mainmenu
2008-10-20 22:39:25 +02:00
done
clear
exit 0
2009-07-30 18:42:45 +02:00
# vim: set ts=4 sw=4 et: