dolorosus / RaspiBackup

Backup your raspi
GNU General Public License v3.0
13 stars 4 forks source link

FR: fstab inconsistecy detection for SD/USB combined installs #9

Closed ephestione closed 5 years ago

ephestione commented 5 years ago

The script should detect when the cmdline.txt contains a PARTUUID different from the actual partuuid of rootfs, which could mean that /etc/fstab was not updated with the correct PARTUUID for boot. It could give both false positives and false negatives, but it's still something relatively easy to do, and useful to have.

dolorosus commented 5 years ago

Yes, I will take a closer look to implement this

ephestione commented 5 years ago

There is just one way to go about this IMO: rootfs PARTUUID is already extracted by the script, and a similar regexp to what was used to extract partuuid from /etc/fstab can be applied to /boot/cmdline.txt (which I seem to not be able to reproduce by altering the expression used in /etc/fstab...) If the two aren't equal, the script reports an inconsistency and alert the user of the possibility he's mounting the wrong partition as /boot

dolorosus commented 5 years ago

1 Shell substitution:

CMDLPU=$(cat /boot/cmdline.txt) CMDLPU=${CMDLPU##PARTUUID=} CMDLPU=${CMDLPU%% } echo ${CMDLPU}

dolorosus commented 5 years ago

2 Multiple grep:

grep "/boot" /etc/fstab |grep -o -E "PARTUUID=[0-9a-fA-F]+-[0-9a-fA-F]+" grep "/ " /etc/fstab |grep -o -E "PARTUUID=[0-9a-fA-F]+-[0-9a-fA-F]+"

ephestione commented 5 years ago

I didn't work on this in the past few days, your approach is an alternative to regex match on /etc/fstab, which works also on /boot/cmdline.txt like so: grep -o -E "PARTUUID=[0-9a-fA-F]+-[0-9a-fA-F]+" /boot/cmdline.txt | grep -o -E "[0-9a-fA-F]+-[0-9a-fA-F]+"

ephestione commented 5 years ago

Or better yet: grep "^[^#;]" /boot/cmdline.txt | grep -o -E "PARTUUID=[0-9a-fA-F]+-[0-9a-fA-F]+" | grep -o -E "[0-9a-fA-F]+-[0-9a-fA-F]+" since on one of my raspi's there was a commented line of an old config which generated a double output

ephestione commented 5 years ago

Just updated my branch: https://github.com/ephestione/RaspiBackup/commit/4eb358545dfa4847d71af10af00db41f9e3a32e8#diff-d46c976bdfd36fb8b6a994d76544d08c