0

Has you can guess from the tittle I'm a moron. I got angry against an USB key and try to format it's partitions with a dd and /null , but instead I deleted my sda1 and sda2 partitions.

I realized rapidly my mistake and didn't shutdown my computer, so my OS is still running.

I have now only my sda3

brw-rw---- 1 root disk 8, 0 Jun  6 19:40 /dev/sda
brw-rw---- 1 root disk 8, 3 Jun  6 19:40 /dev/sda3

if I cat my fstab I get

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/mint--vg-root /               ext4    errors=remount-ro 0       1

# /boot was on /dev/sda2 during installation
UUID=f16adf40-841d-48de-afb6-bdbe66bd6eae /boot           ext2    defaults        0       2

# /boot/efi was on /dev/sda1 during installation
UUID=2008-2EBF  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/mint--vg-swap_1 none            swap    sw              0       0

I must say I'm a bit lost and didn't quiet yet understood how the UEFI, GRUB is working, and how fstab works.

If I do ll /boot it's not empty:

-rw-r--r--  1 root root  1249214 Dec 11 15:36 abi-4.4.0-104-generic
-rw-r--r--  1 root root  1243479 Dec  2  2016 abi-4.4.0-53-generic
-rw-r--r--  1 root root   190517 Dec 11 15:36 config-4.4.0-104-generic
-rw-r--r--  1 root root   189877 Dec  2  2016 config-4.4.0-53-generic
drwxr-xr-x  2 root root     1024 Jun 23  2017 efi/
drwxr-xr-x  5 root root     1024 Apr 17 23:05 grub/
-rw-r--r--  1 root root 48667470 Apr 18 07:27 initrd.img-4.4.0-104-generic
-rw-r--r--  1 root root 48377536 Jan  6 14:59 initrd.img-4.4.0-53-generic
drwx------  2 root root    12288 Jun 23  2017 lost+found/
-rw-r--r--  1 root root   182704 Jan 28  2016 memtest86+.bin
-rw-r--r--  1 root root   184380 Jan 28  2016 memtest86+.elf
-rw-r--r--  1 root root   184840 Jan 28  2016 memtest86+_multiboot.bin
-rw-------  1 root root  3887726 Dec 11 15:36 System.map-4.4.0-104-generic
-rw-------  1 root root  3874377 Dec  2  2016 System.map-4.4.0-53-generic
-rw-------  1 root root  7104112 Dec 11 15:36 vmlinuz-4.4.0-104-generic
-rw-r--r--  1 root root  7065648 Dec 13  2016 vmlinuz-4.4.0-53-generic

but ll /boot/efi is empty.

Do I need to remount or recreate the 2 partitions sda1 and sda2? Can I download an EFI? What can I do?

0

People are divided on two categories. Ones are making backups. Others already making backups. I believe that you have backup.

You need to re-create Partition table via interactive fdisk If you have still your OS is running, you may get partition boundaries from kernel memory.

Here is an example from my working system (RHEL7 with UEFI):

# fdisk -l /dev/sda 

Disk /dev/sda: 300.0 GB, 299966445568 bytes, 585871964 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disk label type: dos
Disk identifier: 0x000a146c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      526335      262144   83  Linux
/dev/sda2          526336     1050623      262144    6  FAT16
/dev/sda3         1050624   585871359   292410368   8e  Linux LVM

You have loose /dev/sda1 and /dev/sda2 info, below the way to restore. Find the files with boundary information:

# find /sys -name start
/sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda1/start
/sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda2/start
/sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda3/start
....

Start block of sda1 partition from kernel memory

# cat /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda1/start
2048

End block of sda1 partition from kernel memory

echo end $((
$(cat /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda1/size) \
+ \
$(cat /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda1/start) \
- 1 \
))
end 526335

Start block of sda2 partition from kernel memory

# cat /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda2/start
526336

End block of sda2 partition from kernel memory

echo end $((\
$(cat /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda2/size)\
+ \
$(cat /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0/target0:1:0/0:1:0:0/block/sda/sda2/start)\
- 1 \
))
end 1050623

Now you need to re-create lost partitions with this boundaries with interactive fdisk. Do not forget to set partition type.

After you restore partitions, you need to check their filesystems. You are writing, that /boot/efi is empty, but it should be empty in the only case if you are NOT using UEFI. You could try to restore it with reinstalling grub2-efi-x64 package.

See this topic to continue restoration.

0

I fixed my error. I firstly save everything that was important to me and created an USB bootable just in case. Then I used testDisk, and since my partitions was not overwritten, I had no issues recovering my partition table and my data with a quick search (UEFI sda1, and swupdate sda2). I finally checked that it had worked with gparted and rebooted my system.

For your information don't do a deep-search with testDisk from on your disk and from you disk, it bug and tell you it doesn't have enough space.

Thankfully everything is ok. thank for the help guys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.