Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a pc with no battery backup and using ubuntu 12.04 with ext4 it will constantly ask me to handle the situation by saying that my superblocks last write is in the future.

So I wonder - can I cheat with something like this - setting the time from the superblock before getting in trouble. Is it a dumb idea - and where should I put it?

#!/bin/bash
# set the time based on last mount of disk

DEVICE="$1"

[ "${DEVICE}" = "" ] && echo "Won't operate without device" > 2 && exit 3

LAST_MOUNT_DATE=$(\
    sudo dumpe2fs -h $DEVICE |\
    grep 'Last mount time:' |\
    sed 's/^[^:]*: *//'
    )
LAST_MOUNT_YEAR=${LAST_MOUNT_DATE//* } # remove all upto last space

THIS_BOOT_DATE=$(date)
THIS_BOOT_YEAR=${THIS_BOOT_DATE//* } # remove all upto last space


if [[ "$THIS_BOOT_YEAR" < "$LAST_MOUNT_YEAR" ]] ; then
    date -s "$LAST_MOUNT_DATE"
fi
share|improve this question
    
Can you replace the battery? –  Michael Hampton May 19 '13 at 18:06
    
No such thing - i only have this option currently - or pressing repair each time –  Jørgen Gårdsted Jørgensen May 19 '13 at 18:22
    
Do you have a dead CMOS/clock battery? It's commonly a CR2032 button cell on the motherboard. –  Dan D. May 19 '13 at 19:00
    
Thank You for Your advice - the pc is seemingly born without a battery - a 'pc in a slot' - it will get some sense of real time not too long after startup - just not right away - so I tried 'errors=continue' en /etc/fstab for the drive, but that didn't seem to cut it. So I thought about just having an 'allowed time' (>= last mount time) until I get the right time - which can take a minute or so –  Jørgen Gårdsted Jørgensen May 19 '13 at 19:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.