ComputerPhreaks / chromiumos_user-recovery-tools

A copy of the Chromium user-recovery-tools repository from chromium.googlesource.com to make improvements to a couple scripts that might not otherwise get fixed
3 stars 0 forks source link

Need to check for `fuse-zip` and `fusermount` or `python` or `busybox` to ensure we are able to unzip the recovery file #2

Open espoelstra opened 3 years ago

espoelstra commented 3 years ago

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 an unzip implementation that works just as well as the python -m zipfile -e somefile.zip and if it is "installed" to /usr/local/bin/busybox can be invoked with busybox 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.

mkdir -p /tmp/recoveryZip
fuse-zip -r chromeos_* /tmp/recoveryZip # specify -r for read-only to avoid accidents
# Can use dd or pv
dd if=/tmp/recoveryZip/chromeos_* of=/dev/sdX bs=4M status=progress
pv /tmp/recoveryZip/chromeos_* > /dev/sdX
fusermount -u /tmp/recoveryZip

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.

espoelstra commented 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
}