Find out where the first partition starts and set the MBR size accordingly

This commit is contained in:
tastytea 2015-10-03 15:35:52 +02:00
parent d1391f653f
commit 5fcf6abad7
3 changed files with 11 additions and 3 deletions

1
TODO
View File

@ -1,5 +1,4 @@
* Debian package * Debian package
* Ubuntu package * Ubuntu package
* Supress dd output while staying Debian 7 compatible * Supress dd output while staying Debian 7 compatible
* Find out if we are raspbian compatible (first partition starts at 4MiB)
* Debian and Ubuntu repositories * Debian and Ubuntu repositories

View File

@ -18,6 +18,7 @@ RDEPEND="
sys-apps/grep sys-apps/grep
virtual/awk virtual/awk
app-shells/bash app-shells/bash
sys-apps/util-linux
" "
DEPEND="${RDEPEND} DEPEND="${RDEPEND}
" "

View File

@ -46,6 +46,14 @@ read_config ()
fi fi
} }
mbr_size ()
{
# Find out where the first partition starts returns(prints) size in KiB
sectorsize=$(LC_ALL=C fdisk -l /dev/sda | grep '^Units:' | awk '{print $8}')
startsector=$(LC_ALL=C fdisk -l /dev/sda | grep -A1 '^Device' | tail -n1 | awk '{print $3}')
expr ${sectorsize} \* ${startsector} / 1024
}
#If we're not root: exit #If we're not root: exit
if [ ${UID} -ne 0 ] if [ ${UID} -ne 0 ]
then then
@ -78,7 +86,7 @@ then
#Write header #Write header
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE} echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${DIGEST_FILE}
#Write MBR of MBR_DEVICE to ${DIGEST_FILE} #Write MBR of MBR_DEVICE to ${DIGEST_FILE}
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=noxfer || die 8 dd if=${MBR_DEVICE} of=${MBR_TMP} bs=$(mbr_size)K count=1 status=noxfer || die 8
#Write hashes of all regular files to ${DIGEST_FILE} #Write hashes of all regular files to ${DIGEST_FILE}
${HASHER} ${MBR_TMP} >> ${DIGEST_FILE} ${HASHER} ${MBR_TMP} >> ${DIGEST_FILE}
find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} + find /boot -type f -exec ${HASHER} --binary {} >> ${DIGEST_FILE} +
@ -103,7 +111,7 @@ then
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}') HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
read_config read_config
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=1M count=1 status=noxfer || die 8 dd if=${MBR_DEVICE} of=${MBR_TMP} bs=$(mbr_size)K count=1 status=noxfer || die 8
if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE}) if ! $(grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict > ${LOG_FILE})
then then
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!" echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"