Deleted partition causing no boot

This forum is for discussion about general software issues.

Deleted partition causing no boot

Postby onomou » Fri Jun 01, 2018 3:43 pm

I made a mistake yesterday and deleted a partition that I thought was overlapping another partition. I've tried using TestDisk to find the original structure, but without success. After I ran the following series of fateful commands, nothing boots now. Can anyone help me?

$this->bbcode_second_pass_code('', '
[root@alarmpi ~]# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.24.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 1.9 GiB, 2007498752 bytes, 3920896 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x417ee54b

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 186367 92160 c W95 FAT32 (LBA)
/dev/mmcblk0p2 186368 3667967 1740800 5 Extended
/dev/mmcblk0p5 188416 3667967 1739776 83 Linux

Command (m for help): d
Partition number (1,2,5, default 5): 2

Partition 2 has been deleted.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

[root@alarmpi ~]# reboot
')

Before all this trouble, I thought /dev/mmcblk0p2 looked very strange, as it starts just a few thousand blocks before /dev/mmcblk0p5, but ends the same. I guessed (incorrectly) that just removing /dev/mmcblk0p2 (which was not in use by the system, as far as I could tell) would be okay. But I think it removed both partitions at the same time. I am hoping that there is a way to directly edit the partition table and manually define the start, end, and type of each partition, in the hopes that everything will boot again.

Output of TestDisk searching for partitions:

$this->bbcode_second_pass_code('', '
Hard disk list
Disk /dev/sda - 256 GB / 238 GiB - CHS 31130 255 63, sector size=512 - SAMSUNG MZMTD256HAGM-000L1, S/N:S15GNEACC02484, FW:DXT42L0Q
Disk /dev/sdc - 2007 MB / 1914 MiB - CHS 244 255 63, sector size=512 - Kingston FCR-HS219/1, S/N:094602011451, FW:9738

Partition table type (auto): Intel
Disk /dev/sdc - 2007 MB / 1914 MiB - Kingston FCR-HS219/1
Partition table type: Intel

Analyse Disk /dev/sdc - 2007 MB / 1914 MiB - CHS 244 255 63
Geometry from i386 MBR: head=154 sector=45
FAT16 at 0/32/33
Info: size boot_sector 184320, partition 184320
FAT1 : 1-180
FAT2 : 181-360
start_rootdir : 361
Data : 393-184316
sectors : 184320
cluster_size : 4
no_of_cluster : 45981 (2 - 45982)
fat_length 180 calculated 180
heads/cylinder 61 (FAT) != 255 (HD)
sect/track 62 (FAT) != 63 (HD)
Current partition structure:
Warning: number of heads/cylinder mismatches 61 (FAT) != 255 (HD)
Warning: number of sectors per track mismatches 62 (FAT) != 63 (HD)
1 * FAT16 >32M 0 32 33 11 153 14 184320 [NO NAME]
2 P Linux 11 153 15 228 81 45 3481600

search_part()
Disk /dev/sdc - 2007 MB / 1914 MiB - CHS 244 255 63
FAT16 at 0/32/33
FAT1 : 1-180
FAT2 : 181-360
start_rootdir : 361
Data : 393-184316
sectors : 184320
cluster_size : 4
no_of_cluster : 45981 (2 - 45982)
fat_length 180 calculated 180
heads/cylinder 61 (FAT) != 255 (HD)
sect/track 62 (FAT) != 63 (HD)

FAT16 at 0/32/33
FAT16 >32M 0 32 33 11 153 14 184320 [NO NAME]
FAT16, blocksize=2048, 94 MB / 90 MiB
')
onomou
 
Posts: 2
Joined: Fri Jun 01, 2018 3:29 pm

Re: Deleted partition causing no boot

Postby summers » Sat Jun 02, 2018 1:26 pm

The old disk partition table, the MBR style, only allowed 4 primary partitions. So to get more partitions, one was created as an extended partition:

http://www.linfo.org/extended_partition.html

And that contained the extra partitions. That is what you had. What happens if you use fdisk to recreate the same partition table, my guess is then you could could still access the old partition. That is you have rewritten the partition table, but not rewritten the partition, so recreating the partition table, and hopefully you'll have the old partition back again ...

Modern partition tables, e.g GPT, can have more than four partitions ...
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm

Re: Deleted partition causing no boot

Postby onomou » Fri Jun 08, 2018 6:04 am

I see now that I shouldn't have deleted that extended partition. How do I get it back? I was hoping that having the log with start/end/blocks would enable me to write that information back again and have it work. But I don't understand how to put that information into fdisk to do that. Can you help me with that?
onomou
 
Posts: 2
Joined: Fri Jun 01, 2018 3:29 pm

Re: Deleted partition causing no boot

Postby summers » Fri Jun 08, 2018 10:16 am

Am at work right now, I'll check when I get home. Don't think I've used extended partitions in 20 years, usually these days use GPT, and back when I used MBR only had 4 partitions (/ /boot /home and swap).

IIRC when you create a new partition (command "n" in fdisk) it asks if you want a primary or extended partition. Now what i can't remember is if you have to create the extended partition holder in the first place. If so its creating a partition and changing the type to something like 5 (use command "t" in fdisk).

Whats worth remembering is fdisk only writes the partition at the end ("w" command in fdisk), so you can try rewrtiting the partition table, check its what you want ("p" command in fdisk), and if it isn't what you what then just quit without saving ("q" command in fdisk)
summers
 
Posts: 984
Joined: Sat Sep 06, 2014 12:56 pm


Return to General

Who is online

Users browsing this forum: No registered users and 8 guests