#use at your own risk
sudo su
apt install dialog progress expect
exec 3>&1;
DEVUSB=/dev/$(dialog --inputbox "/dev/[xxx] of the USB key (without /dev/ and part. no.)" 0 0 2>&1 1>&3);
exitcode=$?;
exec 3>&-;
echo $result $exitcode;
exec 3>&1;
DEVSDC=/dev/$(dialog --inputbox "/dev/[xxx] of the SD card (without /dev/ and part. no.)" 0 0 2>&1 1>&3);exitcode=$?;
exec 3>&-;
clear
echo $DEVUSB $DEVSDC
FDISKU=`fdisk -l | grep $DEVUSB`
FDISKS=`fdisk -l | grep $DEVSDC`
dialog --title "LAST CHANCE" --clear \
--yesno "DISK USB (should not be empty):\n$FDISKU\n\n----------------------\nSD CARD (should not be empty):\n$FDISKS\n\n----------------------\n$DEVUSB $DEVSDC" 20 70
case $? in
0)
echo "OK, continue.";;
1)
echo "Cancelled."
exit;;
255)
echo "Cancelled."
exit;;
esac
umount $DEVUSB*
umount $DEVSDC*
wget https://downloads.raspberrypi.org/raspbian_latest -O raspbian_latest.zip
unzip raspbian_latest.zip
export RASPBIANIMG=`ls *rasp*img`
export RASPBIANIMGSD='Raspbian.SDcard.img'
cat >expect-script <<EOL
#!/usr/bin/expect
eval spawn parted $RASPBIANIMGSD
send "print\r"
expect "Cancel?"
send "Ignore\r"
send "Ignore\r"
send "rm 2\r"
send "quit\r"
expect eof
EOL
string=`parted $RASPBIANIMG -s unit B print | tail -n +8 | head -n 1`
set -f # avoid globbing (expansion of *).
array=(${string//B/ })
blocksize='4096'
taille=`calc \("${array[2]}"+1\)/$blocksize | xargs`
#taille='100'
echo $taille
dd if=$RASPBIANIMG of=$RASPBIANIMGSD count=$taille bs=$blocksize
expect expect-script
rm expect-script
parted $RASPBIANIMGSD print
echo "Run 'sudo progress -m' in another terminal"
dd bs=4M if=$RASPBIANIMG of=$DEVUSB
#tune2fs -U random $DEVUSB'1'
#tune2fs -U random $DEVUSB'2'
mkdir /tmp/mnt_rpi_usb
mount $DEVUSB'1' /tmp/mnt_rpi_usb
cd /tmp/mnt_rpi_usb
mkdir UNUSED
mv * UNUSED
cd -
umount /tmp/mnt_rpi_usb
mount $DEVUSB'2' /tmp/mnt_rpi_usb
sed -i 's/mmcblk0p2/sda2/' /tmp/mnt_rpi_usb/etc/fstab
sed -i 's/mmcblk0p/sda/' /tmp/mnt_rpi_usb/usr/bin/raspi-config
sed -i 's/mmcblk0/sda/' /tmp/mnt_rpi_usb/usr/bin/raspi-config
umount /tmp/mnt_rpi_usb
clearecho "USB key OK"
echo "Run 'sudo progress -m' in another terminal"
dd bs=4M if=$RASPBIANIMGSD of=$DEVSDC
#tune2fs -U random $DEVSDC'p1'
#tune2fs -U random $DEVSDC'p2'
mkdir /tmp/mnt_rpi_sdc
mount $DEVSDC'p1' /tmp/mnt_rpi_sdc
sed -i 's/mmcblk0p2/sda2/' /tmp/mnt_rpi_sdc/cmdline.txt
umount /tmp/mnt_rpi_sdc
clear
echo "SD card OK"
echo "Don't forget to 'apt update' at boot"
# https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=12015
# https://www.raspberrypi.org/forums/viewtopic.php?f=26&t=10914&p=129474&hilit=resizefs#p122476
# https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=104646
# https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=113841&sid=9ea1b54b6dbff237e85be36f2ea93ea6&start=25
Friday, December 30, 2016
Booting Raspberry Pi from USB
Labels:
rpi
Subscribe to:
Post Comments (Atom)
To reach the top of the play bazaar search engine results page, your site needs to offer regular, fresh content. One good way to keep a stream of new content is by including a blog on your site. This will show the search engines that your siteSatta Kingis active, and if your blog is interesting, it will naturally bring in more human traffic.
ReplyDelete