среда, 7 мая 2014 г.

AAAhhh! Recovering after "dd"!!!

dd if=/dev/zero of=/dev/sda bs=1M

Yeeeah, i did it on my laptop (F**n copy-pasting):

Ctrl+C after 1sec and ~700MB zeroed. Perfect evening!!!

But system is still alive. So no problem, let's start:

#0 I'm lucky, because 700MB equal "sda1 (/boot) + part of sda2 (old Ubuntu partition, i don't need it). My root (sda5 with Arch) not affected. I need to recover partition table itself and "/boot".

#1 Old partition table still in memory
cat /proc/partitions                                                                                                                                                              [23:32:52]
major minor  #blocks  name

 179        0    1966080 mmcblk0
 179        1    1965952 mmcblk0p1
   8        0  488386584 sda
   8        1     194560 sda1
   8        2  195221504 sda2
   8        3     976896 sda3
   8        4          1 sda4
   8        5  104856576 sda5
   8        6  187133976 sda6
 254        0   36700160 dm-0
 254        1   31457280 dm-1
 254        2   31457280 dm-2
 254        3   20971520 dm-3

#2 Recreating same partition table with fdisk
fdisk /dev/sda

"o"   create a new empty DOS partition table
"n"   add a new partition. For Last sector use +<BLOCKs from /proc/partitions>

After double (or more) checking:
"w"   write table to disk and exit

#3 recovering /boot
unmount /boot
mkfs.ext2 /dev/sda1
mount /boot
WARN: Special for Arch only (https://wiki.archlinux.org/index.php/syslinux)
pacman -U /var/cache/pacman/pkg/linux-3.13.8-1-x86_64.pkg.tar.xz
pacman -U /var/cache/pacman/pkg/syslinux-6.02-8-x86_64.pkg.tar.xz
syslinux-install_update -i -a -m
vim /boot/syslinux/syslinux.cfg <-- Set right root partition to sda5

That's it. And KISS for everyone.