Skip to content

Instantly share code, notes, and snippets.

@wavezhang
Last active October 21, 2025 11:22
Show Gist options
  • Save wavezhang/d5724f46e2734c1d054380d6bb071783 to your computer and use it in GitHub Desktop.
Save wavezhang/d5724f46e2734c1d054380d6bb071783 to your computer and use it in GitHub Desktop.

Revisions

  1. wavezhang revised this gist Mar 26, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions mountraw
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,12 @@
    file=$1
    part=$2
    dest=$3
    mkdir -p $dest
    if [ -z $part || -z $file || -z $dest ];then

    if [[ -z $part || -z $file || -z $dest ]];then
    echo "usage $0 file part dest"
    exit 1
    fi
    mkdir -p $dest
    npart=$(fdisk -l $file | grep "^$file" | sed 's/*//g' | wc -l)
    t=$(( $npart - $part + 1))
    sector=$(fdisk -l $file | grep "^$file" | sed 's/*//g' | awk '{print $2}' | tail -$t | head -1)
  2. wavezhang created this gist Mar 26, 2020.
    15 changes: 15 additions & 0 deletions mountraw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/bin/bash

    file=$1
    part=$2
    dest=$3
    mkdir -p $dest
    if [ -z $part || -z $file || -z $dest ];then
    echo "usage $0 file part dest"
    exit 1
    fi
    npart=$(fdisk -l $file | grep "^$file" | sed 's/*//g' | wc -l)
    t=$(( $npart - $part + 1))
    sector=$(fdisk -l $file | grep "^$file" | sed 's/*//g' | awk '{print $2}' | tail -$t | head -1)
    offset=$(( $sector * 512 ))
    mount -o loop,offset=$offset $file $dest