Skip to content
Snippets Groups Projects
common.sh 895 B
Newer Older
#!/bin/bash

###
# A Helper function to get partition start offset and total size
# ARG 1 : Partition type
#    Accepted Values : 'root', 'boot'
# ARG 2 : Image path
###
get_partition_start_offset() {
    if [ $1 = "root" ]; then
        partnum=2
    elif [ $1 = "boot" ]; then
        partnum=1
    else
        echo "Invalid partition type $1"
        exit 1
    fi

    echo $(($(fdisk -lu $2 | grep $(basename $2)$partnum | awk '{print $2}') * 512))
}

###
# A Helper function to get partition start offset and total size
# ARG 1 : Partition type
#    Accepted Values : 'root', 'boot'
# ARG 2 : Image path
###
get_partition_size() {
    if [ $1 = "root" ]; then
        partnum=2
    elif [ $1 = "boot" ]; then
        partnum=1
    else
        echo "Invalid partition type $1"
        exit 1
    fi

    echo $(($(fdisk -lu $2 | grep $(basename $2)$partnum | awk '{print $4}') * 512))
}