RFC: nand-sata-install tool - fixed non working eMMC / SATA option, added estimated transfer time, invoke fdisk if target is not partitioned, option to select target FS type: ext4, ext3, ext2. Tested with all possible combination ...
This commit is contained in:
parent
79931b1d4f
commit
c364f1c5f0
@ -1,10 +1,10 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) 2014 Igor Pecovnik, igor.pecovnik@gma**.com
|
||||
#
|
||||
# www.igorpecovnik.com / images + support
|
||||
# Copyright (c) Authors: http://www.armbian.com/authors
|
||||
#
|
||||
# NAND, eMMC, SATA and USB Armbian installer
|
||||
#
|
||||
# Remarks:
|
||||
# nand boot za a10: git clone -b dev/a10-nand-ext4 https://github.com/mmplayer/u-boot-sunxi --depth 1
|
||||
# Should work with: Cubietruck, Cubieboards, BananaPi, Olimex Lime+Lime2+Micro, Hummingboard, ...
|
||||
#
|
||||
@ -18,10 +18,12 @@
|
||||
CWD="/usr/lib/nand-sata-install"
|
||||
EX_LIST="${CWD}/exclude.txt"
|
||||
nanddevice="/dev/nand"
|
||||
logfile="/tmp/nand-sata-install.log"
|
||||
rm -f $logfile
|
||||
|
||||
# read in board info
|
||||
[[ -f /etc/armbian-release ]] && source /etc/armbian-release
|
||||
backtitle="Armbian for $BOARD_NAME install script, http://www.armbian.com | Author: Igor Pecovnik"
|
||||
backtitle="Armbian for $BOARD_NAME install script, http://www.armbian.com"
|
||||
title="NAND, eMMC, SATA and USB Armbian installer v""$VERSION"
|
||||
|
||||
# exception
|
||||
@ -66,24 +68,39 @@ create_armbian()
|
||||
# creating nand boot. Copy precompiled uboot
|
||||
rsync -aqc $BOOTLOADER/* /mnt/bootfs
|
||||
fi
|
||||
|
||||
|
||||
# write stuff to log
|
||||
echo "SD uuid: $sduuid" >> $logfile
|
||||
echo "Satauid: $satauuid" >> $logfile
|
||||
echo "Emmcuuid: $emmcuuid $eMMCFilesystemChoosen" >> $logfile
|
||||
echo "Boot: \$1 $1 $eMMCFilesystemChoosen" >> $logfile
|
||||
echo "Root: \$2 $2 $FilesystemChoosen" >> $logfile
|
||||
echo "Usage: $USAGE" >> $logfile
|
||||
echo "Dest: $DEST" >> $logfile
|
||||
|
||||
# count files is needed for progress bar
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Counting files ... few seconds." 5 40
|
||||
TODO=$(rsync -ahvrltDn --delete --stats --exclude-from=$EX_LIST / /mnt/rootfs | grep "Number of files:"|awk '{print $4}' | tr -d '.,')
|
||||
|
||||
# creating rootfs
|
||||
|
||||
# creating rootfs
|
||||
rsync -avrltD --delete --exclude-from=$EX_LIST / /mnt/rootfs | nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \
|
||||
| dialog --backtitle "$backtitle" --title "$title" --gauge "\n\n Creating rootfs on $2 ($USAGE Mb). Please wait!" 10 80
|
||||
|
||||
| dialog --backtitle "$backtitle" --title "$title" --gauge "\n\n Creating rootfs on $2 ($USAGE Mb). \n\n \
|
||||
This will take around $((USAGE/60)) minutes to finish. Please wait!\n\n" 11 80
|
||||
|
||||
# run rsync again to silently catch outstanding changes between / and /mnt/rootfs/
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... few seconds." 5 40
|
||||
rsync -avrltD --delete --exclude-from=$EX_LIST / /mnt/rootfs >/dev/null 2>&1
|
||||
|
||||
|
||||
|
||||
# creating fstab from scratch
|
||||
rm -f /mnt/rootfs/etc/fstab
|
||||
|
||||
|
||||
# creating fstab, kernel and boot script for NAND partition
|
||||
#
|
||||
if [[ $1 == *nand* ]]; then
|
||||
echo "Install to NAND" >> $logfile
|
||||
REMOVESDTXT="and remove SD to boot from NAND"
|
||||
#sed -i '/boot/d' /mnt/rootfs/etc/fstab
|
||||
echo "$1 /boot vfat defaults 0 0" >> /mnt/rootfs/etc/fstab
|
||||
@ -113,64 +130,70 @@ create_armbian()
|
||||
tune2fs -o journal_data_writeback /dev/nand2 >/dev/null 2>&1
|
||||
tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1
|
||||
e2fsck -f /dev/nand2 >/dev/null 2>&1
|
||||
|
||||
elif [[ $2 == ${emmccheck}p1 || $1 == ${emmccheck}p1 ]]; then
|
||||
|
||||
# fix that we can have one exlude file
|
||||
cp -R /boot/ /mnt/bootfs
|
||||
|
||||
# eMMC install
|
||||
# old boot scripts
|
||||
fi
|
||||
|
||||
|
||||
# Boot from eMMC, root = eMMMC or SATA / USB
|
||||
#
|
||||
if [[ $2 == ${emmccheck}p1 || $1 == ${emmccheck}p1 ]]; then
|
||||
|
||||
sed -e 's,root='"$root_partition"',root='"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd
|
||||
if [[ $2 == ${SDA_ROOT_PART} ]]; then
|
||||
local targetuuid=$satauuid
|
||||
local choosen_fs=$FilesystemChoosen
|
||||
echo "Boot on eMMC, root on USB/SATA" >> $logfile
|
||||
echo "$emmcuuid /boot $eMMCFilesystemChoosen defaults 0 0" > /mnt/rootfs/etc/fstab
|
||||
else
|
||||
local targetuuid=$emmcuuid
|
||||
local choosen_fs=$eMMCFilesystemChoosen
|
||||
echo "Full install to eMMC" >> $logfile
|
||||
fi
|
||||
|
||||
# fix that we can have one exlude file
|
||||
cp -R /boot /mnt/bootfs
|
||||
# old boot scripts
|
||||
sed -e 's,root='"$root_partition"',root='"$targetuuid"',g' -i /mnt/bootfs/boot/boot.cmd
|
||||
# new boot scripts
|
||||
if [[ -f /mnt/bootfs/boot/armbianEnv.txt ]]; then
|
||||
sed -e 's,rootdev=.*,rootdev='"$emmcuuid"',g' -i /mnt/bootfs/boot/armbianEnv.txt
|
||||
sed -e 's,rootdev=.*,rootdev='"$targetuuid"',g' -i /mnt/bootfs/boot/armbianEnv.txt
|
||||
else
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$targetuuid"',g' -i /mnt/bootfs/boot/boot.cmd
|
||||
fi
|
||||
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
|
||||
echo "$emmcuuid / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" > /mnt/rootfs/etc/fstab
|
||||
|
||||
echo "$targetuuid / $choosen_fs defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> /mnt/rootfs/etc/fstab
|
||||
if [[ $(type -t write_uboot_platform) != function ]]; then
|
||||
echo "Error: no u-boot package found, exiting"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
write_uboot_platform $DIR $emmccheck
|
||||
|
||||
fi
|
||||
|
||||
elif [[ -f /boot/boot.cmd ]]; then
|
||||
# old boot scripts
|
||||
# Boot from SD card, root = SATA / USB
|
||||
#
|
||||
if [[ $2 == ${SDA_ROOT_PART} && -z $1 ]]; then
|
||||
echo "Install to USB/SATA boot from SD" >> $logfile
|
||||
sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.cmd
|
||||
sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.ini
|
||||
# new boot scripts
|
||||
if [[ -f /boot/armbianEnv.txt ]]; then
|
||||
sed -e 's,rootdev=.*,rootdev='"$satauuid"',g' -i /boot/armbianEnv.txt
|
||||
else
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',g' -i /boot/boot.cmd
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',g' -i /boot/boot.ini
|
||||
fi
|
||||
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
|
||||
echo "$sduuid /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab
|
||||
echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab
|
||||
echo "$satauuid / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> /mnt/rootfs/etc/fstab
|
||||
elif [[ -f /boot/boot.ini ]]; then
|
||||
# old boot scripts
|
||||
sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.ini
|
||||
# new boot scripts
|
||||
if [[ -f /boot/armbianEnv.txt ]]; then
|
||||
sed -e 's,rootdev=.*,rootdev='"$satauuid"',g' -i /boot/armbianEnv.txt
|
||||
else
|
||||
sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',g' -i /boot/boot.ini
|
||||
fi
|
||||
mkdir -p /mnt/rootfs/media/mmc/boot
|
||||
echo "$sduuid /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab
|
||||
echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab
|
||||
echo "$satauuid / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> /mnt/rootfs/etc/fstab
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Restore TMP and swap
|
||||
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> /mnt/rootfs/etc/fstab
|
||||
cat /etc/fstab | grep swap >> /mnt/rootfs/etc/fstab
|
||||
|
||||
umountdevice "/dev/sda"
|
||||
} # create_armbian
|
||||
|
||||
@ -189,7 +212,9 @@ umountdevice()
|
||||
fi
|
||||
} # umountdevice
|
||||
|
||||
# Recognize root filesystem
|
||||
|
||||
# recognize root filesystem
|
||||
#
|
||||
recognize_root()
|
||||
{
|
||||
# replace with PARTUUID approach parsing /proc/cmdline when ready
|
||||
@ -204,27 +229,30 @@ recognize_root()
|
||||
break;
|
||||
fi
|
||||
done
|
||||
} # recognize_root
|
||||
}
|
||||
|
||||
# Formatting NAND - no parameters. Fixed solution.
|
||||
|
||||
# formatting sunxi NAND - no parameters, fixed solution.
|
||||
#
|
||||
formatnand()
|
||||
{
|
||||
[[ ! -e /dev/nand ]] && echo "NAND error" && exit 0
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 40
|
||||
if [[ $DEVICE_TYPE = a20 ]]; then
|
||||
(echo y;) | sunxi-nand-part -f a20 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1
|
||||
(echo y;) | sunxi-nand-part -f a20 /dev/nand 65536 'bootloader 65536' 'linux 0' >> $logfile 2>&1
|
||||
else
|
||||
(echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1
|
||||
(echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >> $logfile 2>&1
|
||||
fi
|
||||
mkfs.vfat /dev/nand1 >/dev/null 2>&1
|
||||
mkfs.ext4 /dev/nand2 >/dev/null 2>&1
|
||||
} # formatnand
|
||||
mkfs.vfat -qF /dev/nand1 >> $logfile 2>&1
|
||||
mkfs.ext4 -qF /dev/nand2 >> $logfile 2>&1
|
||||
}
|
||||
|
||||
# Formatting eMMC [device] example /dev/mmcblk1
|
||||
|
||||
# formatting eMMC [device] example /dev/mmcblk1 - one can select filesystem type
|
||||
#
|
||||
formatemmc()
|
||||
{
|
||||
# deletes all partitions
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Formating eMMC ... one moment." 5 40
|
||||
# deletes all partitions on eMMC drive
|
||||
dd bs=1 seek=446 count=64 if=/dev/zero of=$1 >/dev/null 2>&1
|
||||
# calculate capacity and reserve some unused space to ease cloning of the installation
|
||||
# to other media 'of the same size' (one sector less and cloning will fail)
|
||||
@ -242,18 +270,45 @@ formatemmc()
|
||||
parted -s $1 -- mklabel msdos
|
||||
parted -s $1 -- mkpart primary ext4 2048s ${LASTSECTOR}s
|
||||
partprobe $1
|
||||
# create fs
|
||||
mkfs.ext4 -qF $1"p1" >/dev/null 2>&1
|
||||
|
||||
# choose and create fs
|
||||
IFS=" "
|
||||
FilesystemTargets="1 ext4 2 ext3 3 ext2"
|
||||
FilesystemOptions=($FilesystemTargets)
|
||||
|
||||
FilesystemCmd=(dialog --title "Select filesystem type for eMMC $1" --backtitle "$backtitle" --menu "\n$infos" 9 60 16)
|
||||
FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty)
|
||||
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
eMMCFilesystemChoosen=${FilesystemOptions[(2*$FilesystemChoices)-1]}
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $eMMCFilesystemChoosen ... please wait." 5 60
|
||||
mkfs.${eMMCFilesystemChoosen} -qF $1"p1" >> $logfile 2>&1
|
||||
|
||||
emmcuuid=$(blkid -o export $1"p1" | grep -w UUID)
|
||||
} # formatemmc
|
||||
}
|
||||
|
||||
|
||||
# formatting SATA/USB [device] example /dev/sda3
|
||||
#
|
||||
formatsata()
|
||||
{
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 40
|
||||
mkfs.ext4 $1 >/dev/null 2>&1
|
||||
tune2fs $1 -o journal_data_writeback >/dev/null 2>&1
|
||||
} # formatsata
|
||||
# choose and create fs
|
||||
IFS=" "
|
||||
FilesystemTargets="1 ext4 2 ext3 3 ext2"
|
||||
FilesystemOptions=($FilesystemTargets)
|
||||
|
||||
FilesystemCmd=(dialog --title "Select filesystem type for $1" --backtitle "$backtitle" --menu "\n$infos" 9 60 16)
|
||||
FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty)
|
||||
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
FilesystemChoosen=${FilesystemOptions[(2*$FilesystemChoices)-1]}
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $FilesystemChoosen ... please wait." 5 60
|
||||
mkfs.${FilesystemChoosen} -qF $1 >> $logfile 2>&1
|
||||
tune2fs $1 -o journal_data_writeback >> $logfile 2>&1
|
||||
}
|
||||
|
||||
|
||||
# choose target SATA/USB partition.
|
||||
checksatatarget()
|
||||
@ -261,29 +316,37 @@ checksatatarget()
|
||||
IFS=" "
|
||||
SataTargets=$(awk '/sd/ {print "/dev/"$4}' </proc/partitions | grep -E '[0-9]{1,4}' | nl | xargs echo -n)
|
||||
if [[ -z $SataTargets ]]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox \
|
||||
"\n\Z1There are no avaliable partitions. Please create them.\Zn" 5 60
|
||||
exit 1
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --msgbox \
|
||||
"\n\Z1There are no avaliable partitions. Please create them.\Zn" 7 60
|
||||
fdisk /dev/$satacheck
|
||||
fi
|
||||
|
||||
SataTargets=$(awk '/sd/ {print "/dev/"$4}' </proc/partitions | grep -E '[0-9]{1,4}' | nl | xargs echo -n)
|
||||
SataOptions=($SataTargets)
|
||||
|
||||
SataCmd=(dialog --title "Select destination:" --backtitle "$backtitle" --menu "\n$infos" 10 60 16)
|
||||
SataChoices=$("${SataCmd[@]}" "${SataOptions[@]}" 2>&1 >/dev/tty)
|
||||
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
SDA_ROOT_PART=${SataOptions[(2*$SataChoices)-1]}
|
||||
} # checksatatarget
|
||||
}
|
||||
|
||||
|
||||
# show warning [TEXT]
|
||||
ShowWarning()
|
||||
{
|
||||
{
|
||||
dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -f mono12 WARNING)\Zn\n$1" 17 74
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
} # ShowWarning
|
||||
}
|
||||
|
||||
|
||||
main()
|
||||
{
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
# if mounted
|
||||
umount /mnt/rootfs >> $logfile 2>&1
|
||||
umount /mnt/bootfs >> $logfile 2>&1
|
||||
|
||||
# This tool must run under root
|
||||
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
@ -318,7 +381,7 @@ main()
|
||||
|
||||
[[ ${#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" 12 60 7)
|
||||
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
||||
[[ $? -ne 0 ]] && exit 1
|
||||
|
||||
@ -337,6 +400,8 @@ main()
|
||||
formatnand
|
||||
fi
|
||||
create_armbian "$dest_boot" "$dest_root"
|
||||
umount /mnt/rootfs
|
||||
umount /mnt/bootfs
|
||||
;;
|
||||
2)
|
||||
title="$ichip boot / SATA root install"
|
||||
@ -353,6 +418,8 @@ main()
|
||||
umountdevice "${SDA_ROOT_PART//[0-9]*/}"
|
||||
formatsata "$SDA_ROOT_PART"
|
||||
create_armbian "$dest_boot" "$SDA_ROOT_PART"
|
||||
umount /mnt/rootfs
|
||||
umount /mnt/bootfs
|
||||
;;
|
||||
3)
|
||||
title="SD boot / SATA root install"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user