Comment 24 for bug 428435

Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote : Re: external harddrive (luks encrypted) will not mount automatically

OK. I now have a python program (attached) that I successfully used to make my karmic upgrade bootable again.
The idea is to remove all additional signatures from superblock. Currently only removing ext[234] signature is supported, but the program can be extended if needed.

The idea is that you can use live-CD to download the script and run it without needing to install any dependencies or what so ever.

I've tried very hard not to mess with people's hard drives:
 - superblock is not altered without --force option
 - a backup is made before superblock is altered so that changes can be reverted
 - if there's unsupported signatures detected the program refuses to alter the superblock
 - trying to restore a backup of a wrong partition is not allowed
 - I used vbindiff to check that only the right bytes get altered and that the restore works

But of course there might be bugs or it might not work for everyone so here's a quote from the license:
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

If you use live-CD or something like that make sure to mount, copy and run the script from unencrypted /boot partition so that the backups get really written to disk and you won't loose them when you try to do a reboot.

And last: You have to know which signature is the right one to keep! If you choose a wrong signature and mount the partition as read/write or run wrong fsck on it you will most probably loose your data and a simple superblock backup won't save you.

$ sudo python fix_superblock.py help

Usage:

    # fix_superblock.py [command] [options]

    Available commands:
       - help
       - check
       - fix
       - restore

    check:
      check [partition]

      Print signatures from superblock of [partition].

    fix:
      fix [partition] [type] --force

      Fix the superblock of [partition] to contain only
      the the signature of filesystem [type].

      If --force is omitted the superblock is not altered

    restore:
      restore [backup] [partition] --force

      Restore a superblock backup.

      If --force is omitted the superblock is not altered

$ mkdir boot
$ sudo mount /dev/sda5 boot
$ sudo cp fix_superblock.py boot/
$ cd boot/

$ sudo python fix_superblock.py check /dev/sda1

Found 2 signatures on partition /dev/sda1:
    - crypto_LUKS
    - ext3

$ sudo python fix_superblock.py fix /dev/sda1 crypto_LUKS

Found the wanted signature from superblock.
adding ext3 remove handler
creating backup 'sda1_superblock_20091017130751_701226'
1+0 records in
1+0 records out
65536 bytes (66 kB) copied, 0.000174184 s, 376 MB/s
backup done.
EXT remove handler
EXT signature found
Not removing EXT signature (--force needed)

$ sudo python fix_superblock.py fix /dev/sda1 crypto_LUKS --force

Found the wanted signature from superblock.
adding ext3 remove handler
creating backup 'sda1_superblock_20091017130757_475293'
1+0 records in
1+0 records out
65536 bytes (66 kB) copied, 0.000177885 s, 368 MB/s
backup done.
EXT remove handler
May the Force be With You
EXT signature found
Removing EXT signature
EXT signature removed.

$ sudo python fix_superblock.py check /dev/sda1

Found 1 signatures on partition /dev/sda1:
    - crypto_LUKS