diff --git a/bin/nand1-boot-cubietruck-arch.tgz b/bin/nand1-boot-cubietruck-arch.tgz new file mode 100644 index 0000000..767b183 Binary files /dev/null and b/bin/nand1-boot-cubietruck-arch.tgz differ diff --git a/bin/nand1-cubietruck-debian-boot.tgz b/bin/nand1-cubietruck-debian-boot.tgz deleted file mode 100755 index bbdb571..0000000 Binary files a/bin/nand1-cubietruck-debian-boot.tgz and /dev/null differ diff --git a/scripts/cubian-resize2fs b/scripts/cubian-resize2fs deleted file mode 100644 index 6bf090c..0000000 --- a/scripts/cubian-resize2fs +++ /dev/null @@ -1,30 +0,0 @@ -#! /bin/sh - -### BEGIN INIT INFO -# Provides: cubian-resize2fs -# Required-Start: $local_fs -# Required-Stop: -# Should-Start: -# Default-Start: S -# Default-Stop: -# Short-Description: Resize the root filesystem to fill partition -# Description: -### END INIT INFO - -set -e - -N=/cubian-resize2fs - -case "$1" in - start) - /sbin/resize2fs /dev/root && - /sbin/insserv -r cubian-resize2fs && - rm $N - ;; - *) - echo "Usage: $N {start}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/scripts/disable_led.sh b/scripts/disable_led.sh old mode 100644 new mode 100755 diff --git a/scripts/nand-install.sh b/scripts/nand-install.sh old mode 100644 new mode 100755 index f015a4d..394a21f --- a/scripts/nand-install.sh +++ b/scripts/nand-install.sh @@ -1,4 +1,16 @@ #!/bin/bash +# +# This script formats the Cubietruck NAND flash and +# copies your existing ArchLinux SD card installation to NAND +# +# The script is based on the original Debian script. +# It's improved and adapted to work on ArchLinux for Cubietruck +# +# Revision 2.0 14/02/2014 -- Klaus Schulz aka soundcheck @ cubieforums.com +# +# +################################################################################### +################################################################################### # Check if user is root if [ $(id -u) != "0" ]; then @@ -6,7 +18,23 @@ if [ $(id -u) != "0" ]; then exit 1 fi -cat > .install-exclude < $EXCLUDE < .install-exclude </dev/null -umount /mnt +umount $SYNCMOUNT1 +umount $SYNCMOUNT2 exec 2>&1 -clear_console + + echo " - - - # # ## ##### # # # # # #### - # # # # # # ## # # ## # # # - # # # # # # # # # # # # # # - # ## # ###### ##### # # # # # # # # ### - ## ## # # # # # ## # # ## # # - # # # # # # # # # # # #### - - - -This script will NUKE / erase your NAND partition and copy content of SD card to it +################################################################################################ +## This script will initialize the entire NAND flash of your Cubietruck and +## install your Archlinux SD installation. +## +## All existing data on your NAND flash will be lost!! You run the script at your own risk! +## +## You know what you're doing ??!!?? +################################################################################################ " +read -p "Proceed (y/n)?" -n 1 -r +[[ ! $REPLY =~ ^[Yy]$ ]] && exit 0 ; -echo -n "Proceed (y/n)? (default: y): " -read nandinst - -if [ "$nandinst" == "n" ] -then - exit 0 -fi - -FLAG=".reboot-nand-install.pid" +### check and install all apps required to run the process if [ ! -f $FLAG ]; then -echo "Partitioning" -apt-get -y -qq install dosfstools -(echo y;) | nand-part /dev/nand 32768 'bootloader 32768' 'rootfs 0' >> /dev/null || true -echo " -Press a key to reboot than run this script again! -" -touch $FLAG -read zagon -reboot -exit 0 + + echo "Checking required applications" + + pacman -S --noconfirm dosfstools rsync || exit 1 + + for i in ${APPS[@]} ; do + which $i >/dev/null 2>&1 || { echo "Supporting app $i not found. Please install $i first." ; exit 1 ; } ; + done + + test -f $ARCHBOOTFILES || { echo "Supporting $ARCHBOOTFILES not found. Please check." ; exit 1 ; } ; + fi -echo "Formatting and optimizing NAND rootfs ... up to 30 sec" -mkfs.vfat /dev/nand1 >> /dev/null -mkfs.ext4 /dev/nand2 >> /dev/null -tune2fs -o journal_data_writeback /dev/nand2 >> /dev/null -tune2fs -O ^has_journal /dev/nand2 >> /dev/null + +### partitioning nand +if [ ! -f $FLAG ]; then + echo "Partitioning NAND with nand-part" + touch $FLAG + (echo y;) | nand-part -f a20 /dev/nand 32768 'bootloader 32768' 'rootfs 0' >$LOG + echo + echo "###################################################################################################################" + read -p "The system will be rebooted now. Restart this script after reboot to continue the process! Press key to continue" -n 1 -r + echo "###################################################################################################################" + + shutdown -r now + exit 0 +fi + +### formatting nand +echo "Formatting and optimizing NAND root and boot fs... ...it'll take take a few seconds" + +mkfs.vfat /dev/nand1 >$LOG +mkfs.ext4 /dev/nand2 >$LOG +tune2fs -o journal_data_writeback /dev/nand2 >$LOG +tune2fs -O ^has_journal /dev/nand2 >$LOG e2fsck -f /dev/nand2 -echo "Creating NAND bootfs ... few seconds" -mount /dev/nand1 /mnt -tar xfz nand1-cubietruck-debian-boot.tgz -C /mnt/ -rm nand1-cubietruck-debian-boot.tgz -rm nand_mbr.backup -cp /boot/* /mnt/ -sed -e 's/root=\/dev\/mmcblk0p1/nand_root=\/dev\/nand2/g' /boot/uEnv.txt > /mnt/uEnv.txt -umount /mnt +### rsync boot fs +echo "rSyncing boot fs to /dev/nand1... ...it'll take a few seconds" +test -d $SYNCMOUNT1 || mkdir -p $SYNCMOUNT1 +test -d $SYNCMOUNT2 || mkdir -p $SYNCMOUNT2 -echo "Creating NAND rootfs ... up to 5 min" -mount /dev/nand2 /mnt -rsync -aH --exclude-from=.install-exclude / /mnt -umount /mnt -echo "All done. Press a key to power off, than remove SD and boot from NAND" +mount /dev/nand1 $SYNCMOUNT1 && { + + ##TODO nand1 runs out of space very quickly, it might needs a verification beforehand + tar xfz $ARCHBOOTFILES -C $SYNCMOUNT1/ + rsync -aH /boot/ $SYNCMOUNT1 + # boot dev needs to be adapted in uEnv.txt + sed -i 's/root=\/dev\/mmcblk0p1/nand_root=\/dev\/nand2/g' $SYNCMOUNT1/uEnv.txt + sync + umount $SYNCMOUNT1 +} + +### rsync root fs +echo "rSyncing root fs to /dev/nand2... ...it'll take several minutes" + +mount /dev/nand2 $SYNCMOUNT2 && { + rsync -aH --exclude-from=$EXCLUDE / $SYNCMOUNT2 + sync +} + +umount $SYNCMOUNT1 +umount $SYNCMOUNT2 + +###cleanup rm $FLAG -rm .install-exclude -read konec -poweroff +rm $EXCLUDE +echo +echo +echo "##########################################################################################" +echo "## Done. Shutdown your system, remove SD card and enjoy your nand based Archlinux system!" +echo "##########################################################################################" + +exit 0 diff --git a/scripts/resize2fs-arch.sh b/scripts/resize2fs-arch.sh new file mode 100755 index 0000000..fe0205c --- /dev/null +++ b/scripts/resize2fs-arch.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# +# Script to resize the partition and filesystem on SD card for +# Archlinux - Cubietruck +# +# Written by Klaus Schulz (soundcheck @ cubieforum.com) +# +# Use script at your own risk. There is a high risk that your loose your data +# by using the script, since it repartitions your media in realtime (mounted) +# +##################################################################################### + +REVISION=1.0 +DATE=02132014 + + +DISKID=mmcblk0 +PARTID=mmcblk0p1 + +resizepartition() { +echo "******Resizing partition******************************" +echo + +sync + +##### fdisk commands +#p print (check if first sector @2048 !! very important, if not all data ar elost if you continue !!!) +#d delete partition (just the table!) +#n new partition +#p primary partition +#1 partition number +# confirm default first sector @ 2048 +# confirm default last sector @ max +#p print to verify new setup +#w write to disk +##### + +FIRSTSECTOR="$(( echo p) | fdisk /dev/$DISKID | grep $PARTID | sed "s/\*//g" | tr -s " " | cut -f 2 -d " " )" +( echo d; echo n; echo p; echo 1; echo $FIRSTSECTOR; echo; echo w; ) | fdisk /dev/$DISKID +shutdown -r now +} + +resizefs() { +echo "******Resizing filesystem******************************" +echo + +resize2fs -p /dev/$PARTID +} + + +help() { +echo " +############################################### +Resizing Tool for Partion and Filesystem +Applicable to ArchLinux on Cubietruck. + +Revision $REVISION + +Warning: +You might loose all your data by running this +script. Run at your own risk!!!! +############################################### +Options: + +-p : resizes mounted!! partition and reboots +-f : resizes filesystem +-h : help + +############################################### +" +} + +#####main################################################################################################ + +case $1 in + + p) resizepartition + ;; + f) resizefs + ;; + *) help + ;; +esac + + +exit 0