Commit 85f4c2a9 authored by aTc's avatar aTc

update install script, new u-boot

parent 019ca1dd
#!/bin/bash
version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | tail -n 1)" == "$1"; }
check_exists() { if ! hash $1 2>/dev/null ; then echo $1 not found ; exit 1 ; fi ; }
if [ "$#" -ne 3 ] ; then echo "Usage: $0 : rootfs.tgz u-boot /dev/mmcblk1" ; exit 1 ; fi
if [ $(id -u) -ne 0 ] ; then echo "Must be run as root"; exit 0; fi
check_exists dd
check_exists sfdisk
check_exists mkfs.ext4
check_exists lsblk
check_exists id
UBOOT=$2
IMAGE=$1
DISK=$3
echo Image:$IMAGE Disk:$DISK U-Boot:$UBOOT
#if [ ! -d $UBOOT ] ; then echo "u-boot files not found"; exit 1; fi
if [ ! -f "${UBOOT}/MLO" ] || [ ! -f "${UBOOT}/u-boot.img" ] ; then echo "u-boot files not found"; exit 1; fi
if [ ! -f $IMAGE ] ; then echo "rootfs image $IMAGE not found."; exit 1; fi
lsblk $DISK
#if [[ $? != 0 ]] ; then echo Failed; exit 1; fi
echo "Installing to $DISK , make sure all partitions are unmounted"
read -p "Are you sure you want to continue? <y/N> " prompt
if ! [[ $prompt =~ [yY](es)* ]] ; then echo "Exiting.." ; exit 1 ; fi
#exit 0
if [[ $DISK == /dev/mmcblk* ]] ; then
PART=${DISK}p1
else
PART=${DISK}1
fi
echo "Clearing partition table"
dd if=/dev/zero of=${DISK} bs=1M count=10
if [[ $? != 0 ]] ; then echo Partitioning failed.; exit 1; fi
echo "Installing U-Boot"
dd if="$UBOOT/MLO" of=${DISK} count=1 seek=1 bs=128k
dd if="$UBOOT/u-boot.img" of=${DISK} count=2 seek=1 bs=384k
echo "Creating partition"
SFVER=$(sfdisk -v | awk '{print $4}')
echo Found sfdisk version: ${SFVER}
if version_gt $SFVER 2.26.0; then
echo "> 2.26.0"
sfdisk ${DISK} <<-__EOF__
1M,,0x83,*
__EOF__
else
echo "< 2.26.0"
sfdisk --in-order --Linux --unit M ${DISK} <<-__EOF__
1,,0x83,*
__EOF__
fi
if [[ $? != 0 ]] ; then echo Partitioning failed.; exit 1; fi
echo "Formatting partition"
mkfs.ext4 -O ^64bit ${PART} -L rootfs
if [[ $? != 0 ]] ; then echo Formatting failed.; exit 1; fi
mkdir rootfs
mount ${PART} ./rootfs
if [[ $? != 0 ]] ; then echo Mounting ${PART} failed.; exit 1; fi
echo "Installing rootfs"
if hash bar 2>/dev/null ; then
bar $IMAGE | tar --numeric-owner -xzf - -C rootfs
else
echo Install "bar" for progress bar
tar --numeric-owner -xzf $IMAGE -C rootfs
fi
if [[ $? != 0 ]] ; then echo Extracting $IMAGE failed.; umount ${PART} ; exit 1; fi
echo "Syncing"
sync
umount rootfs
rm rootfs -rf
echo "Done"
......@@ -76,7 +76,17 @@ if [[ $? != 0 ]] ; then echo Partitioning failed.; exit 1; fi
echo "Formatting partitions"
#mkfs.ext4 -O ^64bit ${PART} -L rootfs
mkfs.ext4 -O ^64bit ${BOOTPART} -L boot
mkfs.f2fs ${PART} -f -l rootfs
# older mkfs.f2fs versions don't have -f, newer versions need -f if fs exists
# older versions don't report version either, so assume if -V fails, -f isn't there
mkfs.f2fs -V > /dev/null 2>/dev/null
if [[ $? == 0 ]] ; then
mkfs.f2fs ${PART} -f -l rootfs
else
mkfs.f2fs ${PART} -l rootfs
fi
if [[ $? != 0 ]] ; then echo Formatting failed.; exit 1; fi
......@@ -98,11 +108,11 @@ else
fi
ROOTPARTUUID=$(lsblk -n -o PARTUUID $PART)
BOOTPARTUUID=$(lsblk -n -o PARTUUID $BOOTPART)
# fs uuid sometimes failed, use PARTUUID for everything
ROOTFSUUID=$(lsblk -n -o UUID $PART)
BOOTFSUUID=$(lsblk -n -o UUID $BOOTPART)
echo BootFS-UUID: $BOOTFSUUID
echo RootFS-UUID: $ROOTFSUUID Part-UUID: $ROOTPARTUUID
sed -i -e 's/linux \/boot/linux /g' rootfs/boot/extlinux/linux.cfg
sed -i -e 's/initrd \/boot/initrd /g' rootfs/boot/extlinux/linux.cfg
......@@ -117,8 +127,8 @@ cat > rootfs/etc/fstab << EOF
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=$ROOTFSUUID / f2fs defaults 0 1
UUID=$BOOTFSUUID /boot ext4 defaults 0 1
PARTUUID=$ROOTPARTUUID / f2fs defaults 0 1
PARTUUID=$BOOTPARTUUID /boot ext4 defaults 0 1
EOF
......
No preview for this file type
No preview for this file type
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment