| 1 |
#!/bin/sh |
| 2 |
set -x |
| 3 |
# Ensure the kernel's partition list is up-to-date |
| 4 |
partprobe |
| 5 |
|
| 6 |
# Identify installer partition |
| 7 |
installpart=$(lsblk -n -o kname,mountpoint | grep ' /$' | awk '{ print $1 }') |
| 8 |
installdisk="$(echo ${installpart} | sed 's:p\?[0-9]$::' )" |
| 9 |
installuuid=$(lsblk -n -o uuid /dev/"${installpart}") |
| 10 |
# Identify internal target drive |
| 11 |
internal_target_disk=$(echo "${INTERNAL_TARGET}") |
| 12 |
# Identify target root partition |
| 13 |
rootpart=$(lsblk -n -o kname,mountpoint | grep ' /tmp/calamares-root' | awk '{ print $1 }') |
| 14 |
if [ "${rootpart}" = "dm-0" ]; then |
| 15 |
rootpart=$(lsblk -J | parent_blk '/tmp/calamares-root') |
| 16 |
if echo "${rootpart}" | grep -qE "(mmcblk|nvme)"; then |
| 17 |
rootpart="${rootpart}p2" |
| 18 |
else |
| 19 |
rootpart="${rootpart}2" |
| 20 |
fi |
| 21 |
fi |
| 22 |
rootdisk="$(echo ${rootpart} | sed 's:p\?[0-9]$::' )" |
| 23 |
|
| 24 |
external_to_internal="" |
| 25 |
if [ "${internal_target_disk}" = "${installdisk}" ]; then |
| 26 |
# Booted from eMMC |
| 27 |
external_to_internal=false |
| 28 |
elif [ "${installdisk}" = "${rootdisk}" ]; then |
| 29 |
# Installing SD -> SD |
| 30 |
external_to_internal=false |
| 31 |
else |
| 32 |
external_to_internal=true |
| 33 |
fi |
| 34 |
|
| 35 |
# Mount filesystems required to chroot into the installed system |
| 36 |
mount --bind /dev /mnt/install/dev |
| 37 |
mount --bind /sys /mnt/install/sys |
| 38 |
mount --bind /proc /mnt/install/proc |
| 39 |
bootpart="" |
| 40 |
if [ "${external_to_internal}" = true ]; then |
| 41 |
mount "${internal_target_disk}p1" /mnt/install/boot |
| 42 |
bootpart=$(mount | grep ' /mnt/install/boot' | awk '{ print $1 }') |
| 43 |
else |
| 44 |
mount --bind /boot /mnt/install/boot |
| 45 |
bootpart=$(mount | grep ' /boot' | awk '{ print $1 }') |
| 46 |
fi |
| 47 |
|
| 48 |
# If the system partition is encrypted, $rootpart is a /dev/mapper device |
| 49 |
# `lsblk -n -s` will give the list of parent devices, for example: |
| 50 |
# mmcblk0 disk |
| 51 |
# mmcblk0p2 part |
| 52 |
# luksdev crypt |
| 53 |
# The following command retrieves the UUID of the underlying physical partition, |
| 54 |
# which is not always the root filesystem's UUID |
| 55 |
rootuuid=$(lsblk -n -s -o uuid,type "/dev/${rootpart}" | grep 'part' | awk '{ print $1 }') |
| 56 |
bootuuid=$(lsblk -n -s -o uuid,type "${bootpart}" | grep 'part' | awk '{ print $1 }') |
| 57 |
rootfs=$(findmnt --noheadings --output FSTYPE /mnt/install) |
| 58 |
fspassno="1" |
| 59 |
if [ "${rootfs}" = "btrfs" ]; then |
| 60 |
fspassno="0" |
| 61 |
fi |
| 62 |
if lsblk -o type | grep -q 'crypt'; then |
| 63 |
echo "calamares_crypt UUID=${rootuuid} none luks,keyscript=/usr/share/initramfs-tools/scripts/unl0kr-keyscript" >> /mnt/install/etc/crypttab |
| 64 |
# Configures unl0kr to attempt to delete the above line on remove |
| 65 |
printf "unl0kr unl0kr/prerm-config boolean true\nunl0kr unl0kr/prerm-config seen false" | chroot /mnt/install debconf-set-selections |
| 66 |
sed "s:UUID=[0-9a-f-]*\s*/\s*ext4\s*defaults,x-systemd.growfs\s*[0-2]\s*[0-2]:/dev/mapper/calamares_crypt / ${rootfs} defaults,x-systemd.growfs 0 ${fspassno}:g" /etc/fstab > /mnt/install/etc/fstab |
| 67 |
chroot /mnt/install/ update-initramfs -u |
| 68 |
else |
| 69 |
# This is a onetime change which will be perpetuated by the rootpart's fstab |
| 70 |
sed "s:${installuuid}\s*/\s*ext4\s*defaults,x-systemd.growfs\s*[0-2]\s*[0-2]:${rootuuid} / ${rootfs} defaults,x-systemd.growfs 0 ${fspassno}:g" /etc/fstab > /mnt/install/etc/fstab |
| 71 |
# Remove unnecessary encryption-related packages as they result in a very |
| 72 |
# large initramfs; this action will trigger an initramfs update |
| 73 |
chroot /mnt/install/ dpkg -r cryptsetup cryptsetup-initramfs unl0kr |
| 74 |
fi |
| 75 |
|
| 76 |
# Install the pinephone-tweak-vccq package if running on a compatible installer |
| 77 |
if [ -f /var/lib/mobian-pinephone-tweaks-vccq.deb ] && \ |
| 78 |
grep -q "pine64,pinephone-" /proc/device-tree/compatible && \ |
| 79 |
[ -f /proc/device-tree/soc/mmc@1c11000/mmc-hs200-1_8v ]; then |
| 80 |
# Install configuration and dtbo |
| 81 |
cp /var/lib/mobian-pinephone-tweaks-vccq.deb /mnt/install/var/lib/mobian-pinephone-tweaks-vccq.deb && \ |
| 82 |
chroot /mnt/install dpkg -i /var/lib/mobian-pinephone-tweaks-vccq.deb && \ |
| 83 |
rm -f /mnt/install/var/lib/mobian-pinephone-tweaks-vccq.deb |
| 84 |
fi |
| 85 |
|
| 86 |
if [ -x /mnt/install/sbin/update-miniramfs ]; then |
| 87 |
chroot /mnt/install/ update-miniramfs -u |
| 88 |
fi |
| 89 |
|
| 90 |
# Update initramfs and extlinux.conf |
| 91 |
chroot /mnt/install/ u-boot-update |
| 92 |
|
| 93 |
if [ ${external_to_internal} = false ]; then |
| 94 |
# Identify installer partition's parent disk |
| 95 |
installdev=$(lsblk -n -s -o kname,type "/dev/${installpart}" | grep 'disk' | awk '{ print $1 }') |
| 96 |
|
| 97 |
# Identify installer partition number |
| 98 |
installpartnum=$(echo "${installpart}" | sed "s/${installdev}p\?//") |
| 99 |
|
| 100 |
# Delete installer partition |
| 101 |
sfdisk --delete "/dev/${installdev}" "${installpartnum}" |
| 102 |
# executed this way to preserve script output |
| 103 |
bash -c "sleep 5s && reboot" & |
| 104 |
else |
| 105 |
# Configure new boot partition in fstab |
| 106 |
sed -i "/\/boot/d" /mnt/install/etc/fstab # Delete the installers boot partition from the target fstab |
| 107 |
bootuuid=$(lsblk -n -s -o uuid "${internal_target_disk}p1" | tr -d "\n") |
| 108 |
echo "UUID=${bootuuid} /boot ext4 defaults 0 2" >> /mnt/install/etc/fstab |
| 109 |
if [ -x /mnt/install/sbin/update-miniramfs ]; then |
| 110 |
chroot /mnt/install/ update-miniramfs -u |
| 111 |
fi |
| 112 |
# executed this way to preserve script output |
| 113 |
bash -c "sleep 5s && poweroff" & |
| 114 |
fi |