Commit f1478527 authored by aTc's avatar aTc

new install.sh with f2fs support

parent f6fa8672
#!/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"
......@@ -4,16 +4,18 @@ 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
check_exists mkfs.f2fs
check_exists lsblk
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
UBOOT=$2
IMAGE=$1
DISK=$3
......@@ -35,9 +37,12 @@ if ! [[ $prompt =~ [yY](es)* ]] ; then echo "Exiting.." ; exit 1 ; fi
#exit 0
if [[ $DISK == /dev/mmcblk* ]] ; then
PART=${DISK}p1
PART=${DISK}p2
BOOTPART=${DISK}p1
else
PART=${DISK}1
PART=${DISK}2
BOOTPART=${DISK}1
fi
echo "Clearing partition table"
......@@ -55,24 +60,31 @@ echo Found sfdisk version: ${SFVER}
if version_gt $SFVER 2.26.0; then
echo "> 2.26.0"
sfdisk ${DISK} <<-__EOF__
1M,,0x83,*
1M,100M,0x83,*
,,0x83,
__EOF__
else
echo "< 2.26.0"
sfdisk --in-order --Linux --unit M ${DISK} <<-__EOF__
1,,0x83,*
,,0x83,
__EOF__
fi
if [[ $? != 0 ]] ; then echo Partitioning failed.; exit 1; fi
echo "Formatting partition"
mkfs.ext4 -O ^64bit ${PART} -L rootfs
echo "Formatting partitions"
#mkfs.ext4 -O ^64bit ${PART} -L rootfs
mkfs.ext4 -O ^64bit ${BOOTPART} -L boot
mkfs.f2fs ${PART} -f -l rootfs
if [[ $? != 0 ]] ; then echo Formatting failed.; exit 1; fi
mkdir rootfs
mount ${PART} ./rootfs
mount ${PART} rootfs
mkdir rootfs/boot
mount ${BOOTPART} rootfs/boot
if [[ $? != 0 ]] ; then echo Mounting ${PART} failed.; exit 1; fi
......@@ -85,11 +97,35 @@ else
tar --numeric-owner -xzf $IMAGE -C rootfs
fi
ROOTPARTUUID=$(lsblk -n -o PARTUUID $PART)
ROOTFSUUID=$(lsblk -n -o UUID $PART)
BOOTFSUUID=$(lsblk -n -o UUID $BOOTPART)
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
sed -i -e "s/append root=\/dev\/mmcblk0p1/append root=PARTUUID=$ROOTPARTUUID/g" rootfs/boot/extlinux/linux.cfg
sed -i -e "s/EXTLINUX_ROOT=\"root=\/dev\/mmcblk0p1\"/EXTLINUX_ROOT=\"root=PARTUUID=$ROOTPARTUUID\"/g" rootfs/etc/default/pyra-extlinux
cat > rootfs/etc/fstab << EOF
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# 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
EOF
if [[ $? != 0 ]] ; then echo Extracting $IMAGE failed.; umount ${PART} ; exit 1; fi
echo "Syncing"
sync
umount rootfs/boot
umount rootfs
rm rootfs -rf
......
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