sdinstall-rpi.sh: various changes
- ask confirmation before proceeding unless -y (assume yes) flag is passed from command line - use parted to create partition table and partitions - add some info and error messages and exit points in case of error
This commit is contained in:
parent
2139bc2ac6
commit
bd01ee2e19
@ -5,9 +5,12 @@
|
||||
#
|
||||
DRIVE=$1
|
||||
ROOTFSARCHIVE=$2
|
||||
[ "$3" = "-y" ] && ASSUMEYES=1
|
||||
|
||||
[ "$DRIVE" -a "$ROOTFSARCHIVE" ] || {
|
||||
echo "Usage: $0 device rootfs-archive"
|
||||
echo "Usage: $0 device rootfs-archive [-y]"
|
||||
echo
|
||||
echo "-y: assume yes to all questions (script mode)"
|
||||
echo
|
||||
echo "Example: $0 /dev/sdb /tmp/openmamba-rootfs-light.arm.tar.xz"
|
||||
exit 1
|
||||
@ -26,37 +29,42 @@ else
|
||||
PARTITION2=${DRIVE}2
|
||||
fi
|
||||
|
||||
dd if=/dev/zero of=$DRIVE bs=1024 count=1024 || {
|
||||
echo "ERROR: dd returned an error code of $?; aborting."
|
||||
exit $?
|
||||
[ "$ASSUMEYES" ] || {
|
||||
echo -n "All current data in ${DRIVE} will be lost, do you want to proceed [y/N]?"
|
||||
read ans
|
||||
[ "$ans" = "y" -o "$ans" = "Y" ] || exit 0
|
||||
}
|
||||
|
||||
set -- $(LC_ALL=C fdisk -l "$DRIVE" | grep "^Disk.*bytes")
|
||||
SIZE="$5"
|
||||
sudo parted -s ${DRIVE} mktable msdos
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
|
||||
fi
|
||||
# FAT partition
|
||||
sudo parted -s -a cyl -- ${DRIVE} mkpart primary fat32 0 40M
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting."
|
||||
fi
|
||||
# openmamba partition
|
||||
sudo parted -s -a cyl -- ${DRIVE} mkpart primary ext4 40M -1
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
|
||||
fi
|
||||
|
||||
[ "$SIZE" ] || {
|
||||
echo "ERROR: unable to detect disk size; aborting."
|
||||
echo "Formatting $PARTITION1..."
|
||||
mkfs.vfat -s 1 -F 32 -n "BOOT" $PARTITION1 || {
|
||||
echo "ERROR: unable to format $PARTITION1; aborting."
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "Disk Size: $SIZE bytes"
|
||||
|
||||
CYLINDERS=`echo $SIZE/255/63/512 | bc`
|
||||
echo "Cylinders: $CYLINDERS"
|
||||
|
||||
{
|
||||
echo ,9,0x0C,*
|
||||
echo ,,,-
|
||||
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE || {
|
||||
echo "ERROR: sfdisk returned an error code of $?; aborting."
|
||||
exit $?
|
||||
echo "Formatting $PARTITION2..."
|
||||
mke2fs -q -t ext4 -j -L "openmamba" $PARTITION2 || {
|
||||
echo "ERROR: unable to format $PARTITION2; aborting."
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkfs.vfat -F 32 -n "BOOT" $PARTITION1
|
||||
mke2fs -t ext4 -j -L "openmamba" $PARTITION2
|
||||
|
||||
### SD-Card: install software
|
||||
|
||||
echo "Fetching firmware from git..."
|
||||
SWHOME=`mktemp -d`
|
||||
|
||||
cd $SWHOME
|
||||
@ -70,8 +78,14 @@ ROOTMP=/media/openmamba
|
||||
exit 1
|
||||
}
|
||||
|
||||
udisks --mount $PARTITION1
|
||||
udisks --mount $PARTITION2
|
||||
udisks --mount $PARTITION1 || {
|
||||
echo "ERROR: unable to mount partition $PARTITION1; aborting."
|
||||
exit 1
|
||||
}
|
||||
udisks --mount $PARTITION2 || {
|
||||
echo "ERROR: unable to mount partition $PARTITION2; aborting."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# bootcode.bin: 2nd stage bootloader, starts with SDRAM disabled
|
||||
# loader.bin : 3rd stage bootloader, starts with SDRAM enabled
|
||||
@ -113,7 +127,8 @@ framebuffer_ignore_alpha=1" > $BOOTMP/config.txt
|
||||
# Not present in the initial release.
|
||||
|
||||
pushd $ROOTMP >/dev/null
|
||||
tar xvf $ROOTFSARCHIVE
|
||||
echo "Uncompressing $ROOTFSARCHIVE..."
|
||||
tar xf $ROOTFSARCHIVE
|
||||
popd >/dev/null
|
||||
|
||||
# copy kernel modules
|
||||
@ -136,9 +151,11 @@ cp -a $SWHOME/firmware/modules/* $ROOTMP/lib/modules/
|
||||
#s@#no_auto_depmod.*@no_auto_depmod=1@" \
|
||||
# $ROOTMP/etc/sysconfig/rc
|
||||
|
||||
sync
|
||||
udisks --unmount $PARTITION1
|
||||
udisks --unmount $PARTITION2
|
||||
|
||||
[ "$SWHOME" -a "${SWHOME:0:4}" = "/tmp" ] && rm -rf $SWHOME
|
||||
|
||||
echo "Done."
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user