mirror of
https://github.com/Fishwaldo/build.git
synced 2025-04-01 11:41:42 +00:00
Installer - added support for UUID and some small bugfixes.
This commit is contained in:
parent
85845da4e5
commit
c1808c85a3
1 changed files with 62 additions and 37 deletions
|
@ -10,32 +10,47 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
# Target sata drive
|
|
||||||
|
|
||||||
|
# script configuration
|
||||||
CWD="/usr/lib/nand-sata-install"
|
CWD="/usr/lib/nand-sata-install"
|
||||||
EX_LIST="${CWD}/exclude.txt"
|
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"
|
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
|
# read in board info
|
||||||
emmccheck=$(grep mmcblk1 /proc/partitions) # check eMMC
|
[[ -f /etc/armbian-release ]] && source /etc/armbian-release || read ID </run/machine.id
|
||||||
satacheck=$(grep sd /proc/partitions) # check SATA/USB
|
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 boot and root file system $1 = boot, $2 = root (Example: create_armbian "/dev/nand1" "/dev/sda3")
|
||||||
create_armbian() {
|
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
|
# create mount points, mount and clean
|
||||||
sync
|
sync && mkdir -p /mnt/bootfs /mnt/rootfs
|
||||||
mkdir -p /mnt/bootfs /mnt/rootfs
|
|
||||||
[ -n "$2" ] && mount $2 /mnt/rootfs
|
[ -n "$2" ] && mount $2 /mnt/rootfs
|
||||||
[[ -n "$1" && "$1" != "$2" ]] && mount $1 /mnt/bootfs
|
[ -n "$1" ] && mount $1 /mnt/bootfs
|
||||||
rm -rf /mnt/bootfs/* /mnt/rootfs/*
|
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
|
# calculate usage and see if it fits on destination
|
||||||
USAGE=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
|
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')
|
||||||
|
@ -84,7 +99,7 @@ EOF
|
||||||
|
|
||||||
[[ $DEVICE_TYPE = "a20" ]] && echo "machid=10bb" >> /mnt/bootfs/uEnv.txt
|
[[ $DEVICE_TYPE = "a20" ]] && echo "machid=10bb" >> /mnt/bootfs/uEnv.txt
|
||||||
# ugly hack becouse we don't have sources for A10 nand uboot
|
# 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/uEnv.txt /mnt/rootfs/boot/uEnv.txt
|
||||||
cp /mnt/bootfs/script.bin /mnt/rootfs/boot/script.bin
|
cp /mnt/bootfs/script.bin /mnt/rootfs/boot/script.bin
|
||||||
cp /mnt/bootfs/uImage /mnt/rootfs/boot/uImage
|
cp /mnt/bootfs/uImage /mnt/rootfs/boot/uImage
|
||||||
|
@ -94,29 +109,36 @@ EOF
|
||||||
tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1
|
tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1
|
||||||
e2fsck -f /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
|
||||||
|
|
||||||
|
# fix that we can have one exlude file
|
||||||
|
cp -R /boot/ /mnt/bootfs
|
||||||
|
|
||||||
# eMMC install
|
# eMMC install
|
||||||
# fix that we can have one exlude file
|
sed -e 's,root='"$root_partition"',root='"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd
|
||||||
cp -R /boot/ /mnt/rootfs
|
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
|
# 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"-")
|
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}')
|
version_of_ubootpkg=$(aptitude versions '~i linux-u-boot*'| tail -1 | awk '{print $2}')
|
||||||
architecture=$(dpkg --print-architecture)
|
architecture=$(dpkg --print-architecture)
|
||||||
uboot="/usr/lib/linux-u-boot-"$name_of_ubootpackage"_"$version_of_ubootpkg"_"$architecture""/u-boot-sunxi-with-spl.bin
|
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
|
elif [[ -f /boot/boot.cmd ]]; then
|
||||||
sed -e 's,root='"$root_partition"',root='"$2"',g' -i /boot/boot.cmd
|
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
|
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
|
mkdir -p /mnt/rootfs/media/mmc/boot
|
||||||
if ! grep -q "/boot" /mnt/rootfs/etc/fstab; then # in two partition setup
|
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
|
echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab
|
||||||
fi
|
fi
|
||||||
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
|
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
|
||||||
elif [[ -f /boot/boot.ini ]]; then
|
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
|
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
|
||||||
fi
|
fi
|
||||||
umountdevice "/dev/sda"
|
umountdevice "/dev/sda"
|
||||||
|
@ -178,6 +200,7 @@ formatemmc() {
|
||||||
# to other media 'of the same size' (one sector less and cloning will fail)
|
# to other media 'of the same size' (one sector less and cloning will fail)
|
||||||
QUOTED_DEVICE=$(echo "${1}" | sed 's:/:\\\/:g')
|
QUOTED_DEVICE=$(echo "${1}" | sed 's:/:\\\/:g')
|
||||||
CAPACITY=$(parted ${1} unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", \$2 / ( 1024 / \$4 ))}")
|
CAPACITY=$(parted ${1} unit s print -sm | awk -F":" "/^${QUOTED_DEVICE}/ {printf (\"%0d\", \$2 / ( 1024 / \$4 ))}")
|
||||||
|
|
||||||
if [ ${CAPACITY} -lt 4000000 ]; then
|
if [ ${CAPACITY} -lt 4000000 ]; then
|
||||||
# Leave 2 percent unpartitioned when eMMC size is less than 4GB (unlikely)
|
# 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 ))
|
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
|
partprobe $1
|
||||||
# create fs
|
# create fs
|
||||||
mkfs.ext4 -qF $1"p1" >/dev/null 2>&1
|
mkfs.ext4 -qF $1"p1" >/dev/null 2>&1
|
||||||
|
emmcuuid=$(blkid -o export $1"p1" | grep -w UUID)
|
||||||
} # formatemmc
|
} # formatemmc
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,24 +267,25 @@ main() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
recognize_root
|
#recognize_root
|
||||||
|
root_partition=$(cat /proc/cmdline | sed -e 's/^.*root=//' -e 's/ .*$//')
|
||||||
IFS="'"
|
IFS="'"
|
||||||
options=()
|
options=()
|
||||||
if [[ -n "$emmccheck" ]]; then
|
if [[ -n "$emmccheck" ]]; then
|
||||||
ichip="eMMC";
|
ichip="eMMC";
|
||||||
dest_boot="/dev/mmcblk1p1";
|
dest_boot=$emmccheck"p1"
|
||||||
dest_root="/dev/mmcblk1p1";
|
dest_root=$emmccheck"p1"
|
||||||
else
|
else
|
||||||
ichip="NAND";
|
ichip="NAND"
|
||||||
dest_boot="/dev/nand1";
|
dest_boot="/dev/nand1"
|
||||||
dest_root="/dev/nand2";
|
dest_root="/dev/nand2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "$nandcheck" || -n "$emmccheck" ]] && options=(${options[@]} 1 'Boot from '$ichip' - system on '$ichip)
|
[[ -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 "$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')
|
[[ -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)
|
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)
|
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
||||||
|
@ -274,8 +299,8 @@ main() {
|
||||||
command="Power off"
|
command="Power off"
|
||||||
ShowWarning "This script will erase your $ichip. Continue?"
|
ShowWarning "This script will erase your $ichip. Continue?"
|
||||||
if [[ -n "$emmccheck" ]]; then
|
if [[ -n "$emmccheck" ]]; then
|
||||||
umountdevice "/dev/mmcblk1"
|
umountdevice "$emmccheck"
|
||||||
formatemmc "/dev/mmcblk1"
|
formatemmc "$emmccheck"
|
||||||
else
|
else
|
||||||
umountdevice "/dev/nand"
|
umountdevice "/dev/nand"
|
||||||
formatnand
|
formatnand
|
||||||
|
@ -288,8 +313,8 @@ main() {
|
||||||
checksatatarget
|
checksatatarget
|
||||||
ShowWarning "This script will erase your $ichip and $SDA_ROOT_PART. Continue?"
|
ShowWarning "This script will erase your $ichip and $SDA_ROOT_PART. Continue?"
|
||||||
if [[ -n "$emmccheck" ]]; then
|
if [[ -n "$emmccheck" ]]; then
|
||||||
umountdevice "/dev/mmcblk1"
|
umountdevice "$emmccheck"
|
||||||
formatemmc "/dev/mmcblk1"
|
formatemmc "$emmccheck"
|
||||||
else
|
else
|
||||||
umountdevice "/dev/nand"
|
umountdevice "/dev/nand"
|
||||||
formatnand
|
formatnand
|
||||||
|
|
Loading…
Add table
Reference in a new issue