Open espoelstra opened 3 years ago
# Helper functions to handle the config file and image zipfile.
unzip() {
local recoveryzip
recoveryzip="$1"
local destfile
destfile="$2"
# python -m zipfile -e $recoveryzip .
mkdir -p $(pwd)/recoveryZip
# mount zip to path
fuse-zip -r $recoveryzip $(pwd)/recoveryZip # specify -r for read-only to avoid accidents
# Initial behavior maintains default extract flow
cp $(pwd)/recoveryZip/$destfile $(pwd)/$destfile
# Can use dd or pv to write direct to device
# dd if=$(pwd)/recoveryZip/chromeos_* of=/dev/sdX bs=4M status=progress
# pv /tmp/recoveryZip/chromeos_* > /dev/sdX
fusermount -u $(pwd)/recoveryZip
}
https://github.com/ComputerPhreaks/chromiumos_user-recovery-tools/blob/70aee97ccebc1a2534cc6eff47f8b5db777e0c20/linux/recovery.sh#L117
I originally assumed that Python was available in Crosh, forgetting that they removed it as a point of security. Currently to get Python in the Crosh shell you need to run
sudo su - ; dev_install
and since this is broken in more recent ChromeOS versions you might not be able to run it by the time you need to create a recovery if you are low on space.As an alternative you can download a statically linked
busybox
binary from busybox.net for your architecture as it has anunzip
implementation that works just as well as thepython -m zipfile -e somefile.zip
and if it is "installed" to/usr/local/bin/busybox
can be invoked withbusybox unzip somefile.zip
After pondering on grabbing random binaries from the internet and trying to account for the different possible architectures that could be involved, I discovered that Crosh does have
fuse-zip
available, so it can mount a zip allowing other processes to copy files out by treating it as a folder.This has the HUGE advantage that if you didn't have enough space for both the recovery and the extracted .bin image, you won't actually need space for the .bin because it can be read from the mounted zip without consuming any extra space and written directly to the target USB or microSD card.