Installer - added support for UUID and some small bugfixes.

This commit is contained in:
Igor Pecovnik 2016-07-25 19:52:12 +02:00
parent 85845da4e5
commit c1808c85a3

View file

@ -10,35 +10,50 @@
#
# Target sata drive
# script configuration
CWD="/usr/lib/nand-sata-install"
EX_LIST="${CWD}/exclude.txt"
backtitle="Armbian install script, http://www.armbian.com | Author: Igor Pecovnik"
title="NAND, eMMC, SATA and USB Armbian installer"
emmcdevice="/dev/mmcblk1"
nanddevice="/dev/nand"
if cat /proc/cpuinfo | grep -q 'sun4i'; then DEVICE_TYPE="a10"; else DEVICE_TYPE="a20"; fi # Determine device
BOOTLOADER="${CWD}/${DEVICE_TYPE}/bootloader" # Define bootloader
nandcheck=$(grep nand /proc/partitions) # check NAND
emmccheck=$(grep mmcblk1 /proc/partitions) # check eMMC
satacheck=$(grep sd /proc/partitions) # check SATA/USB
# read in board info
[[ -f /etc/armbian-release ]] && source /etc/armbian-release || read ID </run/machine.id
backtitle="Armbian for $BOARD_NAME install script, http://www.armbian.com | Author: Igor Pecovnik"
title="NAND, eMMC, SATA and USB Armbian installer v""$VERSION"
# exception
if cat /proc/cpuinfo | grep -q 'sun4i'; then DEVICE_TYPE="a10"; else DEVICE_TYPE="a20"; fi
BOOTLOADER="${CWD}/${DEVICE_TYPE}/bootloader"
# find targets: NAND, EMMC, SATA
nandcheck=$(ls -l /dev/ | grep -w 'nand' | awk '{print $NF}'); [[ -n $nandcheck ]] && nandcheck="/dev/$nandcheck"
emmccheck=$(ls -l /dev/ | grep -w 'mmcblk[1-9]' | awk '{print $NF}'); [[ -n $emmccheck ]] && emmccheck="/dev/$emmccheck"
satacheck=$(cat /proc/partitions | grep 'sd' | awk '{print $NF}')
# Create boot and root file system $1 = boot, $2 = root (Example: create_armbian "/dev/nand1" "/dev/sda3")
create_armbian() {
# read in board info
[[ -f /etc/armbian-release ]] && source /etc/armbian-release || read ID </run/machine.id
# create mount points, mount and clean
sync
mkdir -p /mnt/bootfs /mnt/rootfs
[ -n "$2" ] && mount $2 /mnt/rootfs
[[ -n "$1" && "$1" != "$2" ]] && mount $1 /mnt/bootfs
sync && mkdir -p /mnt/bootfs /mnt/rootfs
[ -n "$2" ] && mount $2 /mnt/rootfs
[ -n "$1" ] && mount $1 /mnt/bootfs
rm -rf /mnt/bootfs/* /mnt/rootfs/*
# sata root part
satauuid=$(blkid -o export $2 | grep -w UUID)
# calculate usage and see if it fits on destination
USAGE=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
DEST=$(df -BM | grep ^/dev | grep /mnt/rootfs | awk '{print $4}' | tr -cd '[0-9]. \n')
DEST=$(df -BM | grep ^/dev | grep /mnt/rootfs | awk '{print $4}' | tr -cd '[0-9]. \n')
if [ $USAGE -gt $DEST ]; then
dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
"\n\Z1Partition too small.\Zn Needed: $USAGE Mb Avaliable: $DEST Mb" 5 60
@ -84,7 +99,7 @@ EOF
[[ $DEVICE_TYPE = "a20" ]] && echo "machid=10bb" >> /mnt/bootfs/uEnv.txt
# ugly hack becouse we don't have sources for A10 nand uboot
if [[ "${ID}" == "Cubieboard" ]]; then
if [[ "${ID}" == "Cubieboard" || "${BOARD_NAME}" == "Cubieboard" || "${ID}" == "Lime A10" || "${BOARD_NAME}" == "Lime A10" ]]; then
cp /mnt/bootfs/uEnv.txt /mnt/rootfs/boot/uEnv.txt
cp /mnt/bootfs/script.bin /mnt/rootfs/boot/script.bin
cp /mnt/bootfs/uImage /mnt/rootfs/boot/uImage
@ -94,29 +109,36 @@ EOF
tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1
e2fsck -f /dev/nand2 >/dev/null 2>&1
elif [[ "$2" == "/dev/mmcblk1p1" ]]; then
elif [[ "$2" == "$emmccheck""p1" || "$1" == "$emmccheck""p1" ]]; then
# eMMC install
# fix that we can have one exlude file
cp -R /boot/ /mnt/rootfs
cp -R /boot/ /mnt/bootfs
# eMMC install
sed -e 's,root='"$root_partition"',root='"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd
mkimage -C none -A arm -T script -d /mnt/bootfs/boot/boot.cmd /mnt/bootfs/boot/boot.scr >/dev/null 2>&1 || (echo "Error"; exit 0)
# fstab adj
sed -e 's,$root_partition,$emmcuuid,g' -i /mnt/rootfs/etc/fstab
# determine u-boot and write it
name_of_ubootpackage=$(aptitude versions '~i linux-u-boot*'| head -1 | awk '{print $2}' | sed 's/linux-u-boot-//g' | cut -f1 -d"-")
version_of_ubootpkg=$(aptitude versions '~i linux-u-boot*'| tail -1 | awk '{print $2}')
architecture=$(dpkg --print-architecture)
uboot="/usr/lib/linux-u-boot-"$name_of_ubootpackage"_"$version_of_ubootpkg"_"$architecture""/u-boot-sunxi-with-spl.bin
dd if=$uboot of=$emmcdevice bs=1024 seek=8
dd if=$uboot of=$emmccheck bs=1024 seek=8 >/dev/null 2>&1 || (echo "Error"; exit 0)
elif [[ -f /boot/boot.cmd ]]; then
sed -e 's,root='"$root_partition"',root='"$2"',g' -i /boot/boot.cmd
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.cmd
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1 || (echo "Error"; exit 0)
mkdir -p /mnt/rootfs/media/mmc/boot
if ! grep -q "/boot" /mnt/rootfs/etc/fstab; then # in two partition setup
echo "/dev/mmcblk0p1 /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab
echo "$satauuid /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab
echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab
fi
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
elif [[ -f /boot/boot.ini ]]; then
sed -e 's,root='"$root_partition"',root='"$2"',g' -i /boot/boot.ini
sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.ini
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
fi
umountdevice "/dev/sda"
@ -178,6 +200,7 @@ formatemmc() {
# to other media 'of the same size' (one sector less and cloning will fail)
QUOTED_DEVICE=$(echo "${1}" | sed 's:/:\\\/:g')
CAPACITY=$(parted ${1} unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", \$2 / ( 1024 / \$4 ))}")
if [ ${CAPACITY} -lt 4000000 ]; then
# Leave 2 percent unpartitioned when eMMC size is less than 4GB (unlikely)
LASTSECTOR=$(( 32 * $(parted ${1} unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", ( \$2 * 98 / 3200))}") -1 ))
@ -191,6 +214,7 @@ formatemmc() {
partprobe $1
# create fs
mkfs.ext4 -qF $1"p1" >/dev/null 2>&1
emmcuuid=$(blkid -o export $1"p1" | grep -w UUID)
} # formatemmc
@ -243,24 +267,25 @@ main() {
exit 1
fi
recognize_root
#recognize_root
root_partition=$(cat /proc/cmdline | sed -e 's/^.*root=//' -e 's/ .*$//')
IFS="'"
options=()
if [[ -n "$emmccheck" ]]; then
ichip="eMMC";
dest_boot="/dev/mmcblk1p1";
dest_root="/dev/mmcblk1p1";
dest_boot=$emmccheck"p1"
dest_root=$emmccheck"p1"
else
ichip="NAND";
dest_boot="/dev/nand1";
dest_root="/dev/nand2";
ichip="NAND"
dest_boot="/dev/nand1"
dest_root="/dev/nand2"
fi
[[ -n "$nandcheck" || -n "$emmccheck" ]] && options=(${options[@]} 1 'Boot from '$ichip' - system on '$ichip)
[[ ( -n "$nandcheck" || -n "$emmccheck" ) && -n "$satacheck" ]] && options=(${options[@]} 2 'Boot from '$ichip' - system on SATA or USB')
[[ -n "$satacheck" ]] && options=(${options[@]} 3 'Boot from SD - system on SATA or USB')
[[ ${#options[@]} -eq 0 ]] && dialog --title "$title" --backtitle "$backtitle" --colors --infobox "\n\Z1There are no targets. Please check your drives.\Zn" 5 60 && exit 1
[[ ${#options[@]} -eq 0 || "$root_partition" == "$emmcuuid" || "$root_partition" == "/dev/nand2" ]] && dialog --title "$title" --backtitle "$backtitle" --colors --infobox "\n\Z1There are no targets. Please check your drives.\Zn" 5 60 && exit 1
cmd=(dialog --title "Choose an option:" --backtitle "$backtitle" --menu "\nCurrent root: $root_partition \n \n" 14 60 7)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
@ -274,8 +299,8 @@ main() {
command="Power off"
ShowWarning "This script will erase your $ichip. Continue?"
if [[ -n "$emmccheck" ]]; then
umountdevice "/dev/mmcblk1"
formatemmc "/dev/mmcblk1"
umountdevice "$emmccheck"
formatemmc "$emmccheck"
else
umountdevice "/dev/nand"
formatnand
@ -285,11 +310,11 @@ main() {
2)
title="$ichip boot / SATA root install"
command="Power off"
checksatatarget
checksatatarget
ShowWarning "This script will erase your $ichip and $SDA_ROOT_PART. Continue?"
if [[ -n "$emmccheck" ]]; then
umountdevice "/dev/mmcblk1"
formatemmc "/dev/mmcblk1"
umountdevice "$emmccheck"
formatemmc "$emmccheck"
else
umountdevice "/dev/nand"
formatnand