LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-06-2015, 10:01 AM   #1
dk_zero-cool
LQ Newbie
 
Registered: Mar 2008
Posts: 25

Rep: Reputation: 0
Restore DM-Crypt Headers


Hi.
I have a hard drive encrypted with DMCrypt/Luks without any outer partition table (sdx). Today I needed to format a small USB Pen but ended up writing a new dos partition table to the encrypted drive instead. For now there is no problem as the drive is unlocked and currently mounted. So I can still access the data on it. But blkid on the device now says PTTYPE="dos", so I am guessing that rebooting would be a bad idea. Is there any way to restore the luks headers to this device?
 
Old 09-06-2015, 12:58 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,740

Rep: Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198
You are correct that rebooting would be a very bad idea and would result in permanent loss of your data.

The relevant section of the Cryptsetup FAQ is 6.10.

Before doing anything else, I would get a printable representation of the master key from the device mapper and keep a paper copy.
Code:
# dmsetup table --target crypt --showkey /dev/mapper/some_name

  Typical result, broken into separate lines for readability:
  0 200704 crypt aes-cbc-essiv:sha256
  a1704d9715f73a1bb4db581dcacadaf405e700d591e93e2eaade13ba653d0d09
  0 7:0 4096
Make the obvious substitution for "some_name". The rest of the instructions are in that FAQ section. As long as you have that master key, you can recover from whatever happens to the LUKS header.

Last edited by rknichols; 09-06-2015 at 12:59 PM.
 
Old 09-06-2015, 01:16 PM   #3
dk_zero-cool
LQ Newbie
 
Registered: Mar 2008
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rknichols View Post
You are correct that rebooting would be a very bad idea and ...
Quick reply, thanks for that.
I piped the output of the command from your example into a file. I am guessing that I need to use the below command using that file? Just want to be sure before doing anything. I do have backup of everything since I always keep my desktop and laptop in sync, but coping takes time so fixing the headers would be so much easier.

Code:
cryptsetup luksFormat --master-key-file=<master-key-file> <luks device>
 
Old 09-06-2015, 01:25 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,740

Rep: Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198
Quote:
Originally Posted by dk_zero-cool View Post
I am guessing that I need to use the below command using that file? Just want to be sure before doing anything. I do have backup of everything since I always keep my desktop and laptop in sync, but coping takes time so fixing the headers would be so much easier.

Code:
cryptsetup luksFormat --master-key-file=<master-key-file> <luks device>
Read the FAQ section. There is more to it than that. The FAQ contains a link to a script that you can download and run to automate the recovery process. Having a copy of that master key information somewhere not subject to accidental erasure (which is why I suggest paper) is just the ultimate backup for when the steps in the FAQ go wrong.
 
1 members found this post helpful.
Old 09-07-2015, 02:49 AM   #5
dk_zero-cool
LQ Newbie
 
Registered: Mar 2008
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rknichols View Post
Read the FAQ section. There is more to it than that. The FAQ contains a link to a script that you can download and run to automate the recovery process. Having a copy of that master key information somewhere not subject to accidental erasure (which is why I suggest paper) is just the ultimate backup for when the steps in the FAQ go wrong.
Thanks a lot. This worked and you just saved me a lot of time
 
Old 09-07-2015, 09:04 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,740

Rep: Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198Reputation: 2198
Glad I got there in time. If you had a power failure or anything that caused a reboot, all would have been lost. You really should make a backup of the LUKS header and store it in a secure location. Sections 6.1 and 6.2 of the FAQ deal with that.

Also, anyone who gets ahold of that master key information you saved will always be able to unlock the encrypted volume, and changing a passphrase would not affect that. Make sure that can't happen. That information is far more sensitive than the backed-up LUKS header. To use the latter, you have to know or crack the passphrase. If you have the master key information, you're already in.
 
Old 09-07-2015, 09:50 AM   #7
dk_zero-cool
LQ Newbie
 
Registered: Mar 2008
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rknichols View Post
Glad I got there in time. If you had a power failure or anything that caused a reboot, all would have been lost. You really should make a backup of the LUKS header and store it in a secure location. Sections 6.1 and 6.2 of the FAQ deal with that.
I will. I'm just gonna make a usb disk with similar encryption and store it on that
 
  


Reply

Tags
dmcrypt, luks


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar: restore only non-hidden files during a restore of /home Alan_ Linux - Newbie 4 05-25-2014 06:10 PM
whether Linux as Restore option to Restore Previous Day Setting as Windows sanjay87 Linux - Newbie 2 11-12-2012 04:48 AM
Why Does Linux Headers Keep Including Too Many Headers? minivy Linux - Kernel 2 12-07-2011 02:16 PM
Zypper wants to dl the wrong kernel headers... YaST doesnt have current headers zorb SUSE / openSUSE 2 11-28-2009 11:12 AM
Restore MySQL Dump File But I want it to restore with different names? helptonewbie Linux - Newbie 5 07-08-2009 05:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration