Mount error when automounting a LUKS-encrypted USB flashdrive

487

Solution 1

It looks as though the journal has become corrupt, doing some searches over the past few days, this seems to not be uncommon on devices that use LUKS.

You could try running an fsck on the device, acknowledging that any data on the device may not be accessible after - you may like to use dd to make a copy of the drive before this.

A common resolution appears to be to create the EXT4 file system from scratch with journaling disabled using mke2fs -t ext4 -O ^has_journal /dev/device. Obviously you would lose the advantages of having a journaled file system by doing this, and lose any data on the device!


Problem

This problem is that the EXT4 file system’s journal has become corrupt. The problem is perhaps made a little obscure due to the fact that the device is encrypted and the file system resides “inside” the encryption.

Resolution

There is a thread of comments below, however I thought a summary here would be more beneficial to anyone who might come across this in the future.

  1. Unencrypt the device, this allows us to get at the device that the EXT4 file system resides on: sudo cryptsetup luksOpen /dev/sdb1 luks_USB

  2. Create an image of the device that has been created in the previous step. We need to do this because file system checking utils generally won’t work on mounted devices, and although the device with EXT4 on isn’t mounted, it’s “parent” is. sudo dd if=/dev/dm-3 of=/tmp/USBimage.dd (add bs and count arguments as you see fit).

  3. Now we have an image, we can run the file system checks: sudo e2fsck /tmp/USBimage.dd any problems found can be evaluated and fixed as required.

  4. You can check to see if your file system has been fixed by attempting to mount the image: sudo mount -o loop /tmp/USBimage.dd /mnt

At this point the OP was able to gain access to their files.

While I would suggest wiping the USB stick and starting over (back to a known state, etc), I think it would be possible to unmount the image from /mnt and then copy if back onto the device that become corrupt: sudo dd if=/tmp/USBimage.dd of=/dev/dm-3

Solution 2

I often get errors like this for no apparent reason and often simply unmounting and remounting fixes it. You can do this with the following commands.

unmount - I know it never mounted in the first place, and will likely throw an error, but I would run to ensure a clean state for running luksClose

sudo umount "/media/userone/New Volume"

lukClose

sudo cryptsetup luksClose /dev/mapper/luks-04cb4ea7-7bba-4202-9056-a65006fe52d7

now remount, first obtain the partition number that the luks container is on with:

sudo lsblk 

or

sudo fdisk -l

then use that partition here, from the looks of your error message your partition may be
/dev/dm-3, but I would confirm first with sudo lsblk

sudo cryptsetup luksOpen </dev/luks_partition_here> luks_USB

sudo mkdir /media/userone/luks_USB
sudo mount /dev/mapper/luks_USB /media/userone/luks_USB
Share:
487

Related videos on Youtube

Eddy
Author by

Eddy

Updated on September 18, 2022

Comments

  • Eddy
    Eddy almost 2 years

    My iOS app stopped receiving push notifications although I upgraded the code as per the documentations and this.

    Here's the code I'm using:

    In my AppDelegate's didFinishLaunchingWithOptions:

    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
         UIUserNotificationTypeBadge | UIUserNotificationTypeSound  categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert |
         UIRemoteNotificationTypeBadge |
         UIRemoteNotificationTypeSound];
    }
    

    The didRegisterForRemoteNotificationsWithDeviceToken method is getting called, as it was before, so everything seems fine.

    Also, my test device has the notifications enabled.

    But when sending a push from Parse.com it no longer arrives.

    EDIT 1:

    None of the answers work. I updated my Parse.com framework to version 1.6.2 (the latest) which doesn't help either, and I'm copying my code again - this time the updated version based on the answers:

    Inside didFinishLaunchingWithOptions:

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
                                                                                             |UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert) categories:nil];
        [application registerUserNotificationSettings:settings];
        //        [application registerForRemoteNotifications];
    } else {
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
    }
    

    And these are the delegate methods:

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
        NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken CALLED");
    
        // Store the deviceToken in the current installation and save it to Parse.
        PFInstallation *currentInstallation = [PFInstallation currentInstallation];
        [currentInstallation setDeviceTokenFromData:newDeviceToken];
        [currentInstallation addUniqueObject:@"Test8Channel" forKey:@"channels"];
    
        if([PFUser currentUser]/* && [[PFUser currentUser] objectId] != nil*/) {
            [currentInstallation addUniqueObject:[PFUser currentUser] forKey:kOwnerKey];
        }
        [currentInstallation saveInBackground];
    
    }
    
    #ifdef IS_OS_8_OR_LATER
    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
        [application registerForRemoteNotifications];
        NSLog(@"didRegisterUserNotificationSettings CALLED");
    }
    
    - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString*)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler {
    NSLog(@"handleActionWithIdentifier CALLED");
    //handle the actions
    if ([identifier isEqualToString:@"declineAction"]){
        NSLog(@"handleActionWithIdentifier %@", @"declineAction");
    }
    else if ([identifier isEqualToString:@"answerAction"]){
        NSLog(@"handleActionWithIdentifier %@", @"answerAction");
    }
    }
    #endif
    
    
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
        if (error.code == 3010) {
            NSLog(@"Push notifications are not supported in the iOS Simulator.");
        } else {
            // show some alert or otherwise handle the failure to register.
            NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
        }
    }
    

    Both didRegisterUserNotificationSettings and didRegisterForRemoteNotificationsWithDeviceToken are getting called and it seems fine. But the push doesn't arrive.

    EDIT 2:

    I'm noticing that if I call both

    [application registerUserNotificationSettings:settings];
    

    and

    [application registerForRemoteNotifications];
    

    inside the if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {

    the delegate's didRegisterForRemoteNotificationsWithDeviceToken is getting called twice. I'm not sure how meaningful this is.

    Getting desperate here.

    • soulshined
      soulshined over 9 years
      how are you sending from the console i.e, plain text/json? and are you waiting to receive it will in background or foreground?
    • Eddy
      Eddy over 9 years
      I'm taking the default, which is plain text, and I've tried both in the background and foreground. I also put a printf in the didReceiveRemoteNotification method but it's not getting called.
    • soulshined
      soulshined over 9 years
      And the provisioning profiles or certificates haven't been altered?
    • Eddy
      Eddy over 9 years
      No, nothing changed.
    • bllakjakk
      bllakjakk over 9 years
      Just wanna do a quick check. while going to background, check result of [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; and let know the result.
    • Eddy
      Eddy over 9 years
      It's 1. Thanks for responding, @bllakjakk
  • Eddy
    Eddy over 9 years
    I edited the question to reflect the code after the advice here. It's still not working.
  • Eddy
    Eddy over 9 years
    I edited the question to reflect the code after the advice here. It's still not working.
  • emotality
    emotality over 9 years
    There must be something wrong, if you try the above code on a different Xcode and still not works it's definitely the device? Have you tried different devices? The above is the only code I got and works 100%. Every time I start my app all the methods are being called.
  • emotality
    emotality over 9 years
    "conditional block" It's definitely not a block, and a block isn't even necessary in this case. And your answer is exactly the same as all the other answers, just 10 times more code...
  • oshirowanen
    oshirowanen about 8 years
    Please see update 1 above.
  • oshirowanen
    oshirowanen about 8 years
    Would it be worth DD'ing the device to make a bit identical copy before fsck'ing it?
  • forquare
    forquare about 8 years
    @oshirowanen most certainly. It would allow you to try multiple options
  • oshirowanen
    oshirowanen about 8 years
    Made a DD and have not tried fsck, but I get this message user1@laptop:~$ sudo fsck /dev/sdb1 fsck from util-linux 2.20.1 fsck: fsck.crypto_LUKS: not found fsck: error 2 while executing fsck.crypto_LUKS for /dev/sdb1 user1@laptop:~$ . Any idea why?
  • forquare
    forquare about 8 years
    Ah ha, perhaps try a copy/DD of the dm-3 device (might have changed, but what was shown in your example above) and then try fsck'ing that? I don't think fsck likes the unencrypted LUKS wrapper.
  • oshirowanen
    oshirowanen about 8 years
    Not sure I fully understand, you mean fsck the DD image? As in mount the DD image using the -o loop option and fsck that?
  • forquare
    forquare about 8 years
    From the looks of things, you DD'd and fsck'd the partition that is encrypted (/dev/sdb1). What I think you need to do is run the sudo cryptsetup luksOpen /dev/sdb1 luks_USB, which then creates /dev/dm-3 and it is this device that you want to backup with DD and try to fsck as this has the EXT4 file system that I believe is corrupt.
  • oshirowanen
    oshirowanen about 8 years
    Making DD of /dev/dm-3, Then will test fsck on /dev/dm-3. DD taking it's time. Will report back soon. Thanks for the help so far.
  • oshirowanen
    oshirowanen about 8 years
    It finally finished DD, but when I do fsck I get: sudo fsck /dev/dm-3 fsck from util-linux 2.27.1 e2fsck 1.42.13 (17-May-2015) /dev/mapper/luks-7bf56e6e-a29e-43d1-9f2f-34310d5c9db1 is mounted. e2fsck: Cannot continue, aborting.. I tried unmounting and I got this sudo cryptsetup luksClose /dev/mapper/luks-7bf56e6e-a29e-43d1-9f2f-34310d5c9db1 device-mapper: remove ioctl on luks-7bf56e6e-a29e-43d1-9f2f-34310d5c9db1 failed: Device or resource busy Device /dev/mapper/luks-7bf56e6e-a29e-43d1-9f2f-34310d5c9db1 is still in use..
  • forquare
    forquare about 8 years
    OK, since that doesn't like it, I wonder if you'll have success doing an e2fsck on your DD image of dm-3? My like to make a cp of it before you try.
  • oshirowanen
    oshirowanen about 8 years
    Copied and e2fsck found some issues and fixed them apparently. How would I now go about checking the image to make sure it's all good?
  • forquare
    forquare about 8 years
    Try mounting with something like mount -o loop image.dd /mnt.
  • forquare
    forquare about 8 years
    Awesome! You should be able to DD the image back over dm-3, but I would consider remaking your USB stick without the journal
  • forquare
    forquare about 8 years
    You are more than welcome, Best of luck with it going forward
  • PAT-O-MATION
    PAT-O-MATION about 3 years
    Finally trying mke2fs -t ext4 -O ^has_journal /dev/device worked for me While I was getting the bad superblock error when I was trying to mount. I guess I don't have journaling now correct?