Rebuilding Disks: Erasing the Wrong Partition and Using a UDF-formatted USB Key
Have you ever paid insufficient attention when using a partitioning tool and ended up erasing the wrong disk, perhaps your main SSD containing your boot OSes? If so, you're not alone. This article will guide you through the process of rebuilding your disks in such a scenario, including creating a UDF-formatted USB key to help you in the recovery process.
Assessing the Damage: Identifying the Erased Partition
The first step in rebuilding your disks is to identify the erased partition. You can use tools such as fdisk or gdisk to list the current partitions on your disk. For example:
# fdisk -l
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: SOME-IDENTIFIER
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 15630591 14579968 6.9G Linux filesystem
...
In this example, you can see that the disk has a GPT label and several partitions, including an EFI system partition and a Linux filesystem partition. If you accidentally erased one of these partitions, you would need to rebuild the disk to recover the lost data.
Creating a UDF-formatted USB Key
To rebuild your disks, you may need to create a UDF-formatted USB key to boot from and restore your data. The Universal Disc Format (UDF) is a widely used optical disc format that can also be used on USB keys. Here's how to create a UDF-formatted USB key using the udftools package:
# apt-get install udftools
# dd if=/dev/zero of=/dev/sdX bs=512 count=2048
# mkudffs -b 512 -f 16 -v /dev/sdX
In this example, /dev/sdX represents your USB key. The first command zeros out the first 2048 sectors of the USB key, and the second command creates a UDF filesystem on the key with a sector size of 512 bytes and a block size of 16 sectors. The resulting USB key can be used to boot from and restore your data.
Rebuilding the Disks
The process of rebuilding the disks will depend on the specific scenario and tools used. However, here are some general steps you can follow:
- Identify the erased partition and its contents.
- Create a backup of any remaining data on the disk.
- Use a partitioning tool such as
fdisk,gdisk, or a graphical tool likegpartedto recreate the partition table and partitions. - Format the partitions using the appropriate filesystems, such as
ext4for Linux filesystems orntfsfor Windows partitions. - Copy the data from the backup onto the newly created partitions.
- Reboot the system and verify that the partitions are working correctly.
References
By following these steps, you can rebuild your disks and recover from accidentally erasing the wrong partition. Be sure to pay close attention when using partitioning tools and always create a backup of your important data before making any major changes.