Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I accidentally formatted my entire encrypted Ext4 Hard Drive Disk into FAT32.
I have not mounted it or written anything on it since then, but I have tried to use Testdisk, and the only thing I have been able (by following the suggestion of the programm) is to show a 2.1MB (which is way too small to be my original partition) encrypted partition. I then followed that thread : http://forum.cgsecurity.org/phpBB3/r...ize-t2629.html (ie reformatting my drive using fdisk -c=dos -u=cylinders /dev/sda)
And I am now stuck, still enable to acess my datas.
Here is what I have been able to obain before all those operations :
Code:
Disk /dev/sda: 29185 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
/dev/sda1 2048 468860927 468858880 b W95 FAT32
/dev/sda2 0 - 0 0 Empty
/dev/sda3 0 - 0 0 Empty
/dev/sda4 0 - 0 0 Empty
Disk /dev/sdb: 1021 cylinders, 239 heads, 62 sectors/track
Warning: The partition table looks like it was made
for C/H/S=*/32/63 (instead of 1021/239/62).
For this listing I'll assume that geometry.
Units = sectors of 512 bytes, counting from 0
and
Code:
ubuntu@ubuntu:~$ udisks --show-info /dev/sda
Showing information for /org/freedesktop/UDisks/devices/sda
native-path: /sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
device: 8:0
device-file: /dev/sda
presentation: /dev/sda
by-id: /dev/disk/by-id/ata-KINGSTON_SV300S37A240G_50026B7242045BE7
by-id: /dev/disk/by-id/wwn-0x50026b7242045be7
detected at: Mon 23 Mar 2015 06:16:32 PM UTC
system internal: 1
removable: 0
has media: 1 (detected at Mon 23 Mar 2015 06:16:32 PM UTC)
detects change: 0
detection by polling: 0
detection inhibitable: 0
detection inhibited: 0
is read only: 0
is mounted: 0
mount paths:
mounted by uid: 0
presentation hide: 0
presentation nopolicy: 0
presentation name:
presentation icon:
automount hint:
size: 240057409536
block size: 512
job underway: no
usage:
type:
version:
uuid:
label:
partition table:
scheme: mbr
count: 1
drive:
vendor: ATA
model: KINGSTON SV300S37A240G
revision: 520ABBF0
serial: 50026B7242045BE7
WWN: 50026b7242045be7
detachable: 0
can spindown: 1
rotational media: No
write-cache: enabled
ejectable: 0
adapter: Unknown
ports:
similar devices:
media:
compat:
interface: ata
if speed: (unknown)
ATA SMART: Data not collected
and here is what I currently have
Code:
sudo fdisk -l /dev/sda
Disk /dev/sda: 240.1 GB, 240057409536 bytes
255 heads, 63 sectors/track, 29185 cylinders, total 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000456ec
Device Boot Start End Blocks Id System
/dev/sda1 * 2046 499709 248832 83 Linux
/dev/sda2 501760 505855 2048 83 Linux
The format command should only over-write (some of) the start of the partition. If it over-wrote the LUKS header and you have no backup, your data is lost. That's why you encrypted it remember.
There are others here better versed in LUKS than me, but if it were me, I'd simply make one big partition over the entire drive - doesn't matter if it's bigger than the crypt container. Make sure it starts on sector 2048.
Then use crypsetup display commands to see if it recognises it. If it does you should be able to open then mount it. If not, bad luck.
but I have tried to use Testdisk, and the only thing I have been able (by following the suggestion of the programm) is to show a 2.1MB (which is way too small to be my original partition) encrypted partition.
That is actually very good. The LUKS header does not have any information about the size of the container, so testdisk will always report the minimum possible size (just the size of the LUKS header and key material) with the notation, "Data size unknown." Let testdisk create a partition starting at that header and extend it to the end of the disk. You should be able to unlock that and find your data all there.
Thank you all for your help.
I finally got my data back.
To Veerain : I was using cryptsetup, and I could not use fsck on the encrypted drive, it just would not work.
To syg000 and rkichols : I did some version of what you sugested.
After letting testdisk create the partition, I extended my sda2 partition (the one with the encrypted file) from sector 501760 (the original beginning) to the end of the disk, using fdisk. I after rebooting, I was able to acess my partition.
Thank you again
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.