#!/bin/bash

# Must be root to run dmsetup

if [ $UID -ne 0 ];then
	echo You must be root to run $0
	exit 1
fi

# Get the status of live-rw
STATUS=`dmsetup status live-rw | awk '{print $NF}'`

# Used sectors
USED_SEC=`echo $STATUS | awk -F/ '{print $1}'`
# Total sectors
TOTAL_SEC=`echo $STATUS | awk -F/ '{print $2}'`

# Used size in MB - sectors*512 bytes/sector / 1024 KB/B / 1024 MB/KB
USED_MB=`echo $[USED_SEC * 512 / 1024 / 1024 ]`
# Total size in MB
TOTAL_MB=`echo $[TOTAL_SEC * 512 / 1024 / 1024 ]`

echo The overlay is using $USED_MB MB out of a total of $TOTAL_MB MB.

#vim:tw=79:ts=4:sw=4
