Restoring Deleted Encrypted Partitions: Ext4 vs. LUKS
Accidentally formatting an entire hard disk, which contains multiple partitions with different filesystems (Ext4, encrypted LUKS, and unencrypted Ext4), can be a daunting task. This article will provide a detailed guide on how to restore such partitions, focusing on the key concepts and differences between Ext4 and LUKS filesystems.
Understanding Ext4 and LUKS Filesystems
Ext4 is a popular filesystem for Linux and Unix-like operating systems. It is known for its stability, performance, and reliability. LUKS (Linux Unified Key Setup) is a disk encryption specification for Linux, providing a standard encryption scheme across different Linux distributions.
Recovering Data from an Unencrypted Ext4 Partition
To recover data from an unencrypted Ext4 partition, you can use tools like testdisk or photorec. These tools can scan the disk for lost partitions and recover files even if the filesystem is damaged.
sudo apt-get install testdisk
sudo testdisk /dev/sda
Recovering Data from an Encrypted LUKS Partition
Recovering data from an encrypted LUKS partition is more complex. First, you need to identify the correct device and partition. Then, you can use the cryptsetup tool to open the encrypted partition and mount it.
sudo cryptsetup luksOpen /dev/sda5 encrypted_partition
sudo mkdir /mnt/encrypted_partition
sudo mount /dev/mapper/encrypted_partition /mnt/encrypted_partition
Restoring Deleted Partitions
To restore deleted partitions, you can use the fdisk or gdisk tools. These tools allow you to recreate the partition table and partitions based on the previous layout.
sudo fdisk /dev/sda
(g)
(n)
(p)
(1)
(Enter)
(Enter)
(Enter)
(t)
(83)
(n)
(p)
(2)
(Enter)
(Enter)
(Enter)
(w)
References
- TestDisk - https://www.cgsecurity.org/wiki/TestDisk
- PhotoRec - https://www.cgsecurity.org/wiki/PhotoRec
- Cryptsetup - https://gitlab.com/cryptsetup/cryptsetup/wikis/Cryptsetup
- Fdisk - https://man7.org/linux/man-pages/man8/fdisk.8.html
- Gdisk - https://man7.org/linux/man-pages/man8/gdisk.8.html
Note: This article is intended for educational purposes only and should not be used as a guide for illegal activities. Always ensure that you have proper authorization before accessing or modifying any disk or partition.
--endarticle--