welshgeekboy
Posts: 24
Joined: Wed Feb 17, 2016 8:59 am
Location: Wales, Carmarthenshire

[RESOLVED] Partition trouble on NOOBS card.

Mon Feb 22, 2016 12:09 am

I have unfortunately deleted my boot partition using fdisk. I was trying to delete the 512MB partition that you can add with NOOBS which I created ages ago but never used, but I seem to have selected the wrong partition to delete. I had my SD card I damaged in a reader and was accessing it with another Raspberry Pi.

I have downloaded gparted and had a look at what remains on the card. My files (in the root partition, I believe?) are untouched and as far as I can see Raspbian is still installed. Obviously though, without the boot partition Raspbian does not load. After NOOBS exits I get a black screen.

How can I replace the partition I have deleted, and put the boot files back? I understand that I will have to edit the files to get them back to how they where. What tool should I use to create the partition, and how should the partition be created? When I looked at the options gparted gave me for creating a partition there appeared to be multiple file system types that I could select but I don't know which to choose.

Thank you for any help I receive.
Last edited by welshgeekboy on Mon Apr 04, 2016 6:34 am, edited 2 times in total.
Pi B r2, Pi Zero (no cam), Pi 3, acid yellow HDMIPi, lots of robot bits.

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I deleted my boot partition.

Mon Feb 22, 2016 6:56 am

fdisk does not delete the contents of partitions, it only modifies the partition table. If you create a new partition in the same place as the deleted one, and set it to the same type, it should work - unless you have overwritten the data by formatting or something.

What does "fdisk -l" show on the card (lowercase "L")?

welshgeekboy
Posts: 24
Joined: Wed Feb 17, 2016 8:59 am
Location: Wales, Carmarthenshire

Re: I deleted my boot partition.

Mon Feb 22, 2016 8:03 am

Ah! Really? That is good news. I really ought to stop fiddling with what I don't properly understand. :lol:

Code: Select all

pi@hdmipi ~ $ sudo fdisk -l /dev/sda

Disk /dev/sda: 7948 MB, 7948206080 bytes
4 heads, 16 sectors/track, 242560 cylinders, total 15523840 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
Disk identifier: 0x0002c95b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192     2009765     1000787    e  W95 FAT16 (LBA)
/dev/sda2         2015232    15458303     6721536   85  Linux extended
/dev/sda3        15458304    15523839       32768   83  Linux
/dev/sda5         3211264    15458303     6123520   83  Linux
It still shows /dev/sda5 for some reason. I thought that was the 512MB data partition? When I look at the card in gparted it tells me this:

The card has 6 parts.
4.00 MiB unallocated
977.33 MiB /dev/sda1 with file system fat16 and flag 'lba'
2.67 MiB unallocated
6.41 MiB /dev/sda2 with file system 'extended'
Inside sda2:
584 MiB unallocated
5.84 GiB /dev/sda5 with file system ext4 (says it is mounted at /media/root and it is labelled 'root' so I think it's the root partition. This would make sense given its size)
Back outside sda2:
32 MiB /dev/sda3 with file system ext4 (says it is mounted on /media/SETTINGS and it is labelled as 'SETTINGS')

I hope this helps. :mrgreen:
Pi B r2, Pi Zero (no cam), Pi 3, acid yellow HDMIPi, lots of robot bits.

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I deleted my boot partition.

Mon Feb 22, 2016 1:49 pm

Thanks, that information is very useful. I think we can salvage this. I just need to look up a few details first and I'll get back to you.

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I deleted my boot partition.

Mon Feb 22, 2016 5:00 pm

Slightly more complex than I thought. I think NOOBS aligns partitions on 8MB boundaries.

Right, first thing to do in fdisk is to delete partition 5. This is because we need to renumber the partitions. Don't worry, it doesn't affect the contents at all, and you've still got the start and length for that one.

I reckon the data partition, which will be number 5, needs to start at 2,031,616 and will be (512MB) 1,048,576 sectors long.

The boot partition, number 6, will start immediately after that, at 3,080,192 and be 131,072 sectors (it might be smaller than that, but it shouldn't matter). They type for that one needs to be set to 0c (FAT32). The other partitions will default to Linux in fdisk.

Finally the root partition, which we know starts at 3,211,264 and uses the rest of the card.

Write those values out with fdisk, then use blkid to see if the labels show up properly. If they do, you should be able to mount the partitions to see that everything looks ok.
Last edited by rpdom on Mon Feb 22, 2016 8:19 pm, edited 1 time in total.

welshgeekboy
Posts: 24
Joined: Wed Feb 17, 2016 8:59 am
Location: Wales, Carmarthenshire

Re: I deleted my boot partition.

Mon Feb 22, 2016 7:33 pm

Thank you for your help. So what you are suggesting I do will undo the damage I caused, but not remove the data partition? Is that right? First you are focusing on sorting out the problem, then afterwards I can remove the data partition (probably using a different tool) if the damage is undone successfully?

I have used fdisk in command mode and typed 'd' for delete then '5' for deleting partition 5 already, which is what caused the problem. Why is partition 5 still present? Are gparted and fdisk both displaying what is actually on the SD card, not what the partition table says? Or are the partitions being renamed automatically or something?

I will attempt what you have instructed and post my results in a minute...
Pi B r2, Pi Zero (no cam), Pi 3, acid yellow HDMIPi, lots of robot bits.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: I deleted my boot partition.

Mon Feb 22, 2016 7:57 pm

welshgeekboy wrote: My files (in the root partition, I believe?) are untouched and as far as I can see Raspbian is still installed.
Before you do anything, I would make sure that any data on the partitions that you can still see is safely backed up and verified as backed up.

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I deleted my boot partition.

Mon Feb 22, 2016 8:11 pm

welshgeekboy wrote:Thank you for your help. So what you are suggesting I do will undo the damage I caused, but not remove the data partition? Is that right? First you are focusing on sorting out the problem, then afterwards I can remove the data partition (probably using a different tool) if the damage is undone successfully?
Yes, pretty much. However removing the data partition will cause the other partitions to be renumbered again, and that will probably make your Pi unbootable again. It might be a better idea to just leave it there. It's not that big.
I have used fdisk in command mode and typed 'd' for delete then '5' for deleting partition 5 already, which is what caused the problem. Why is partition 5 still present? Are gparted and fdisk both displaying what is actually on the SD card, not what the partition table says? Or are the partitions being renamed automatically or something?
Yes, partitions from 5 onwards get renamed automatically.
I will attempt what you have instructed and post my results in a minute...
Fingers crossed :)

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: I deleted my boot partition.

Mon Feb 22, 2016 8:13 pm

I'm a little bit dubious about the "and will be (512MB) 1,048,675 sectors long" part myself. Shouldn't that be 1,048,576?
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I deleted my boot partition.

Mon Feb 22, 2016 8:18 pm

GTR2Fan wrote:I'm a little bit dubious about the "and will be (512MB) 1,048,675 sectors long" part myself. Shouldn't that be 1,048,576?
Indeed. That was a tyop :oops:
Corrected now.

welshgeekboy
Posts: 24
Joined: Wed Feb 17, 2016 8:59 am
Location: Wales, Carmarthenshire

Re: I deleted my boot partition.

Tue Feb 23, 2016 11:33 pm

Okay, I'm working on it now. Progress so far:
Deleted old partition 5
Created new (correctly positioned) partition 5
Failed to create partition 6- the start sector is already allocated?

Code: Select all

pi@hdmipi ~ $ sudo fdisk /dev/sda

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


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

Partition 5 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).

Code: Select all

pi@hdmipi ~ $ sudo fdisk /dev/sda

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


Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (2017280-15458303, default 2017280): 2031616
Last sector, +sectors or +size{K,M,G,T,P} (2031616-15458303, default 15458303): +1048576

Created a new partition 5 of type 'Linux' and of size 512 MiB.

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).

Code: Select all

pi@hdmipi ~ $ sudo fdisk /dev/sda

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


Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 6
First sector (2017280-15458303, default 2017280): 3080192

Sector 3080192 is already allocated.
First sector (3082240-15458303, default 3082240): ^C
Pi B r2, Pi Zero (no cam), Pi 3, acid yellow HDMIPi, lots of robot bits.

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: I deleted my boot partition.

Wed Feb 24, 2016 5:26 pm

Ok, I didn't check the layout with fdisk. Mea Culpea :(

I'm still having to gues about the partitioning scheme slightly, but try this one. Coincidentally my card is exactly the same size as yours! That's pretty rare.

Code: Select all

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            8192     2009765     1000787   83  Linux
/dev/sdb2         2015232    15458303     6721536    5  Extended
/dev/sdb3        15458304    15523839       32768   83  Linux
/dev/sdb5         2017280     3065855      524288   83  Linux
/dev/sdb6         3067904     3209215       70656    c  W95 FAT32 (LBA)
/dev/sdb7         3211264    15458303     6123520   83  Linux
If that doesn't work we'll try something else.

welshgeekboy
Posts: 24
Joined: Wed Feb 17, 2016 8:59 am
Location: Wales, Carmarthenshire

Re: I deleted my boot partition.

Thu Mar 10, 2016 10:21 am

I'm really sorry I haven't replied sooner. I have not been focusing on Pi at all since my last posts, I haven't even been on the Pi forum until now. I'll do what you saythis evening, hopefully.
Pi B r2, Pi Zero (no cam), Pi 3, acid yellow HDMIPi, lots of robot bits.

welshgeekboy
Posts: 24
Joined: Wed Feb 17, 2016 8:59 am
Location: Wales, Carmarthenshire

Re: I deleted my boot partition.

Thu Mar 24, 2016 8:13 pm

Hello again, I'm sorry to be slack with this, you've all been a great help so far. Unfortunately you still have not given me enough information to be able to follow out your advice. Could you pretty much hold my hand through every step? Also the partition layout right from the beginning appears to be different to your card (I presume the last post by rpdom was a copy / paste of what fdisk tells you about the partitions of rpdom's card). I unfortunately cannot post what my Pi says about the card right now, but I know it's different. I think the start and length of the first partition is the same as yours, but then the number of blocks is different? I will post the info as soon as I can.

Do you want me to remove all partitions using fdisk, then put them back in place using the start, length, stop etc. points in your last post? Because I *think* I could do that.
Pi B r2, Pi Zero (no cam), Pi 3, acid yellow HDMIPi, lots of robot bits.

welshgeekboy
Posts: 24
Joined: Wed Feb 17, 2016 8:59 am
Location: Wales, Carmarthenshire

Re: Partition trouble on NOOBS card.

Mon Apr 04, 2016 6:34 am

Thank you all very much for your help, but I have now erased the card with NOOBS and reimaged Raspbian. I spent a good few hours trying to get it to work but kept running into problems. When I got the first partition (sda5) in the right place according to rpdom, the next wouldn't go in the right place. Fdisk said the start point was already allocated (though it wasn't as far as I could see) and then when I looked at the card in Gparted (I use this because it is easier to do things with a GUI) it didn't seem to know the partition type (83, I think, for Linux type).

Code: Select all

dmesg | tail
(I think that was the command) said this:

Code: Select all

sda5: bad geometry: block count 132864 exceeds size of device 131072
so my problem with sda5 was still not sorted out. This may have been why fdisk said the start point of sda6 was already allocated? I don't know. Anyway eventually I gave up. I haven't lost anything as all my work is backed up in numerous places (such as Github for those nosey https://github.com/welshgeekboy/Lobsang_Pi_Wars and it was just a case of updating Wheezy from about a year ago to the current Wheezy installation! The card now boots fine.

Again, thank you for your help. I have learnt a little more about SD cards and partitioning. Perhaps one day I will understand enough to be able to fix one! :lol:
Pi B r2, Pi Zero (no cam), Pi 3, acid yellow HDMIPi, lots of robot bits.

Return to “Raspberry Pi OS”