Menu

#19 restore gpt partition info

v1.0 (example)
open
nobody
5
2024-08-01
2024-07-29
No

Hello
Could you kindly help

I accidentally rewrote the gpt partition info on ntfs gpt partition (/dev/sda1) with the command:

ms-sys --partition /dev/sda1

This is supposed to run on an mbr disk, but I ran it on gpt.
And the partition now is broken
Is it possible to restore gpt partition info for this partition?

Discussion

  • internet-uzver

    internet-uzver - 2024-07-29

    here is the output of that command:

    Start sector 2048 (nr of hidden sectors) successfully written to /dev/sda1
    Physical disk drive id 0x80 (C:) successfully written to /dev/sda1
    Number of heads (255) successfully written to /dev/sda1
    
     
  • internet-uzver

    internet-uzver - 2024-07-29

    I found that the command with specifying the start of the partition as 0 mounts the partiotion fylesystem accurate:

    sudo mount -o ro,offset=0 /dev/sda1 /mnt
    
     

    Last edit: internet-uzver 2024-07-30
  • Henrik Carlqvist

    The --partition switch does not in any way alter the partition table, only the file system of the given partition (in this case sda1). This can be done on FAT or NTFS file systems. Usually ms-sys is able to get everything right automagically except for the number of heads. So ms-sys has the switch -H where you manually can set the expected number of heads of the disk.

    Did you by any chance boot your Linux system with lilo? If so, you can use "lilo -T geom" to see the number of heads of your drive (this might be a remapped LBA number and not the actual number of physical heads). If so, you can use ms-sys again and choose another number of heads, example:

    ms-sys --partition --heads 64 /dev/sda1

     
  • internet-uzver

    internet-uzver - 2024-07-30

    Did you by any chance boot your Linux system with lilo?

    Noup.

    Can you tell please, is it good a idea at all to use ms-sys on GPT disk?
    Or is it designed for MBR only?

     
  • Henrik Carlqvist

    It is fully possible to do a legacy boot also with a GPT partition table. However, most new machines have UEFI boot and ms-sys is not useful for UEFI boot systems. For UEFI boot a GPT partition table is required, but a GPT partition table does not require UEFI boot.

    I am not aware of any other way than lilo to find out the number of heads to give to ms-sys. However, there is another tool called testdisk: https://www.cgsecurity.org/wiki/TestDisk . I have used it a few times to restore erased partitions and I have also used PhotoRec to restore contents of lost files. TestDisk claims to be able to "Rebuild NTFS boot sector", maybe that tool will be able to restore the data in the NTFS boot record that you overwrote with "ms-sys --partition"?

    However whether it is a good idea to use ms-sys on a GPT disk or an UEFI disk totally depends upon the state of that disk. Ms-sys is a tool designed to fix broken boot records. If something isn't broken you should not try to fix it. The --partition feature of ms-sys was added so make file systems bootable which had been formatted by more or less flaky formatting programs. With old versions of the Linux kernel that feature used to work fine and fix everything automagically. With not so old versions of the Linux kernel it might be necessary to manually give the number of heads.

    It would not be a good idea to use brute force to try to guess the right number of heads. That number is stored in a 16 bit integer giving you more than 32000 numbers to guess from. If you have a similar drive with an NTFS partition it might be possible to study the contents of that NTFS boot record to see the number of heads on that drive. If you have some spare space on the same drive as the borked NTFS partition it might be possible to create another NTFS partition on the drive and study its boot record to find out the number of heads.

     
  • internet-uzver

    internet-uzver - 2024-07-31

    Thanks for the explanation

    lilo was not helpfull to find the heads, it's too old.

    I tried sfdisk:

    $ sfdisk -g /dev/sda1
    
    /dev/sda1: 41283 cylinders, 255 heads, 63 sectors/track
    

    I had already backed up the files from the broken /dev/sda1, so I decided to delete it.

     
  • Henrik Carlqvist

    My guess is that the Linux kernel reports the same number of heads (255) to sfdisk as it did to ms-sys. Trying to write 255 again is probably not going to help. Reformatting the file system from scratch and restoring a backup might be the simplest solution.

    Unless you have more questions within the next week I will close this support request.

     
  • internet-uzver

    internet-uzver - 2024-08-01

    Yeap, it does nothing.
    It better to reformatting

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.