update nand-install and resize2fs

This commit is contained in:
soundcheck 2014-02-15 13:06:26 +01:00
parent d0ffe4fab1
commit 3d0c55c1a7
6 changed files with 201 additions and 85 deletions

Binary file not shown.

Binary file not shown.

View file

@ -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

0
scripts/disable_led.sh Normal file → Executable file
View file

169
scripts/nand-install.sh Normal file → Executable file
View file

@ -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 <<EOF
###PARAMS##########################################################################
EXCLUDE=/root/nand-install-exclude ## rsync exclude
FLAG=/root/nand-install.flag
LOG=/root/nand-install.log
SYNCMOUNT1=/mnt/nand1
SYNCMOUNT2=/mnt/nand2
ARCHBOOTFILES=/root/nand1-boot-cubietruck-arch.tgz
###################################################################################
## applications required to get the job done
APPS=( nand-part mkfs.vfat mkfs.ext4 rsync tune2fs e2fsck )
## rsync exclude file for root fs
cat > $EXCLUDE <<EOF
/dev/*
/proc/*
/sys/*
@ -16,72 +44,103 @@ cat > .install-exclude <<EOF
/tmp/*
EOF
## umount sync directory -- just in case it's still mounted
exec 2>/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

87
scripts/resize2fs-arch.sh Executable file
View file

@ -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
#<ret> confirm default first sector @ 2048
#<ret> 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