deleted ext4 partition

8 risposte [Ultimo contenuto]
chaosmonk

I am a member!

I am a translator!

Offline
Iscritto: 07/07/2017

I think I screwed up really bad. In following a tutorial on clearing a USB drive using 'dd' I accidentally typed 'sda' instead of 'sdb' and cleared the ext4 partition instead because I am a f*cking idiot. I don't have enough knowledge to know exactly how bad this is, but I believe that I just deleted everything on my disk. The exact command I used was

$ sudo dd if=/dev/zero of=/dev/sda1 bs=1k count=2048

All of my files are backed up, so I hoped that if I could just manage to install Trisquel again I'd be okay. However, when I select 'Search ISOLINUX Menu (USB)' from the GRUB menu nothing comes up and I am returned to the GRUB menu after a few minutes, so I can't even run Trisquel live let alone install it.

The bright side is that I've learned a valuable lesson about running commands before I understand them, but it would be nice to salvage my computer too. How bad is this? What can I do?

Legimet
Offline
Iscritto: 12/10/2013

Well, you have a backup, so it's not that bad. Reinstall Trisquel, and restore your backup. To boot from your USB drive, just use your BIOS options. You can also use GRUB (edit one of the existing entries).

chaosmonk

I am a member!

I am a translator!

Offline
Iscritto: 07/07/2017

Thanks. I reformatted the USB drive and re-burnt the ISO and now I'm able to boot it and am installing.

Magic Banana

I am a member!

I am a translator!

Offline
Iscritto: 07/24/2010

You overwrote with zeros ("if=/dev/zero") the beginning of /dev/sda1 ("of=/dev/sda1"), 2048 blocks ("count=2048") of size 1k ("bs=1k"). 2 MB. Almost nothing! There is much to be rescued if you want to: the other partitions are intact and a program like PhotoRec can recover almost all files on /dev/sda1: http://www.cgsecurity.org/wiki/PhotoRec

But does /dev/sda1 even contain user data? It makes no sense recovering system files: reinstall. Now if /dev/sda1 only contains user data, there is nothing to reinstall: the system is intact.

SuperTramp83

I am a translator!

Offline
Iscritto: 10/31/2014

I can confirm that photorec is gold, pure gold. It will recover 99% of your data. But then again you have it backed up so I don't see how waiting 20 hours for it to finish (recovery takes a lot of time) makes any sense here. Reinstall and profit!

chaosmonk

I am a member!

I am a translator!

Offline
Iscritto: 07/07/2017

Yep, reinstalling worked.

happy_gnu
Offline
Iscritto: 08/06/2017

I avoid this type of mistakes using # whenever I am doing something delicate

The symbol # is for comments so if you do

$ # sudo command
Nothing will happen because of the # after I did that I make sure everything is well written by pressing up and then when I am sure everything is OK is when I delete the # and hit enter

This have saved me from mistakes when using rm for example.

chaosmonk

I am a member!

I am a translator!

Offline
Iscritto: 07/07/2017

Good advice. Thank you.

Magic Banana

I am a member!

I am a translator!

Offline
Iscritto: 07/24/2010

Substitute "#" with "echo" and type Enter. The command will be printed but after Shell expansion (typically the wildcard, *, but also the variables, etc.). Try for instance:
$ echo cp /var/log/syslog* $HOME
Here it outputs:
cp /var/log/syslog /var/log/syslog.1 /var/log/syslog.2.gz /var/log/syslog.3.gz /var/log/syslog.4.gz /var/log/syslog.5.gz /home/banana
Once the command checked, go back a line in the history (C-p or the up arrow), move the cursor to the beginning of the line (C-a or Home) delete "echo" (M-d) and type Enter to execute.