Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaon/5416809 to your computer and use it in GitHub Desktop.
Save shaon/5416809 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# set -x
# DEBUG='echo'
device=$1
[ ! -f "${device}" ] && exit 1
output_dir=$( echo "${device}" | sed 's/.img//g' )
[ -d "${output_dir}" ] && exit 1
mkdir -p "${output_dir}"
start_block=$( parted ${device} unit b print | grep ' 1 ' | awk '{print $2}' | sed 's/B//g' )
${DEBUG} losetup /dev/loop0 "${device}" -o "${start_block}"
${DEBUG} mount /dev/loop0 /mnt
# ${DEBUG} file -s /dev/loop0
# ls /mnt
${DEBUG} cp /mnt/initr* /mnt/vmlinuz* "${output_dir}"/
${DEBUG} umount /mnt
${DEBUG} losetup -d /dev/loop0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment