Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

Thread: Partitioning with sfdisk

  1. #1
    Join Date
    Oct 2018
    Beans
    18

    Partitioning with sfdisk

    I've messed up my dual 750GB dual boot (Windows 8.1-preinstalled & Ubuntu 14.04) HDD. I am trying to restore my partition table without formatting as I want to try and recover some files with a Windows search. I only have a partial Deja-dup backup and this photo of the fdisk and lsblk output of the partition table taken shortly after I started having problems. I'm using a Ubuntu Live USB on the 4GB (3.5GB) drive. The 114GB drive is a USB I'm using for downloading & storage to limit writing on the HDD.
    screen.jpg

    I tried Testdisk and saved some files but when restoring the partition table I get a mess of 20 1.5-22MB partitions and one 600+MB. Gparted is graphical and, as far as I know, will not allow me to numerically set the partition start and end--hence sfdisk,

    If I write a file identical to an sfdisk (old version) dump
    Code:
    sfdisk -d /dev/sda
    named "created_dump.txt" using the info from my fdisk photo, I can use
    Code:
    sfdisk --force /dev/sdX < created_dump.txt
    to make a new partition table identical to the fdisk output photo without formatting.

    As you will see, sfdisk does not have "end" and "sectors" columns so using the columns from fdisk and the formula below I have calculated the sizes. When I do, my total is -1 from the fdisk results in the photo so I have added the "+".

    End-Start=Sectors
    Sectors*bytes (512)=bytes
    bytes/1024=kilobytes
    kilobytes/1024= megabytes
    megabytes/1024=gigabytes

    created_dump.txt
    Code:
    # partition table of /dev/sda
    unit: sectors
      
    /dev/sda1 :      start=     2048,         size=    4194304+,         Id=   7      Recovery
    /dev/sda2 :      start=     821248,       size=    3145728+,         Id=   7      ESP
    /dev/sda3 :      start=     1697792,      size=    469203156992+,    Id=   7      Gateway
    /dev/sda4 :      start=     918110208,    size=    253961913586+,    Id=  83
    /dev/sda5 :      start=     1450706944,   size=    3443351269+,      Id=  82
    /dev/sda6 :      start=     1457928184,   size=    15+,              Id=  82
    My questions:
    Does everything in the created_dump.txt look correct? fdisk says that sda4 is Microsoft basic data which would be NTFS Id=82 but lsblk says sda4 is ext4 which would be Id=83. Which one is it and how would I know?

    I would appreciate any help. I need step-by-step detailed instructions. If there is a better way to accomplish what I'm trying to do please let me know, I am open to whatever works.

  2. #2
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Partitioning with sfdisk

    Fdisk & sfdisk recently got major updates to support gpt partitioned drives.

    You need to be using the newer version. My 18.04 has it and file looks like this:
    Code:
    label: gpt
    label-id: 1AB0DBE4-1876-4F34-81EA-F2C2B2B55B74
    device: /dev/sdb
    unit: sectors
    first-lba: 34
    last-lba: 1953525134
    
    /dev/sdb1 : start=        2048, size=     1044480, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=E58602B1-8FC4-46D1-991F-1D6511D9CDF4, name="EFI System Partition"

    You may be able to use gdisk, but I think it is a binary file.
    sudo sgdisk --backup=table /dev/sda
    UEFI boot install & repair info - Regularly Updated :
    https://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  3. #3
    Join Date
    Oct 2018
    Beans
    18

    Re: Partitioning with sfdisk

    Hmm, okay. Upgrading to 16.03 then downgrading back to 14.04 is what started my problems. I used a Live CD 18.04 and took a look at sfdisk. For rebuilding my partition table via text, how is sfdisk after v.2.26 any better? The GUID string for GPT in the new version, but if I use the old version why would the GUID strings be of any benefit?

  4. #4
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Partitioning with sfdisk

    I have been using gpt on all Ubuntu only drives since about 10.04 install to repartitioned gpt drive.
    If using on a MBR(msdos) partitioned drive, I would assume it should be ok.

    GPT Advantages (older 2010 but still valid) see post#2 by srs5694:
    http://ubuntuforums.org/showthread.php?t=1457901
    https://wiki.archlinux.org/index.php...antages_of_GPT
    http://en.wikipedia.org/wiki/Unified...ware_Interface
    UEFI boot install & repair info - Regularly Updated :
    https://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  5. #5
    Join Date
    Oct 2018
    Beans
    18

    Re: Partitioning with sfdisk

    I cannot understand why you are highlighting the fact that it is a GPT. The disk has never been a MBR. The info from fdisk (see photo in original post) says "Disklabel type: gpt". I'm trying to redo the partition table on the same disk the same way it was when the photo of the fdisk info was taken. I did not know to do a sfdisk dump three weeks ago and now it is pointless because everything is messed up. So, I wrote/created a new text file (created_dump.txt)to look like an a sfdisk dump (-d) and I'm trying to confirm that I created it correctly before I -force it to remake the partition table.

    Does sfdisk -force with a text file only work on MBR and not GPT? If so does anything like that exist for GPT?

  6. #6
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Partitioning with sfdisk

    If using the older sfdisk, why
    I believe both the new sfdisk & gdisk work with gpt drives. Just do not use old sfdisk or fdisk as you found out.
    I was pointing out that you only should use the older fdisk & sfdisk with the old MBR partitioning.

    What ever you do you should have all data backed up, so if something does not work, it is not the end of the world.
    Whenever you hand edit a file like that you have to be very careful to make sure spacing & structure match correctly.
    Best to have sfdisk create file and only do minor edits.

    If trying to recover existing partitions, often better to use testdisk or parted rescue (again from newer Ubuntu live).
    The use of sfdisk is considered a last resort when other tools have totally failed.

    Used parted rescue
    https://ubuntuforums.org/showthread.php?t=2362656
    http://ubuntuforums.org/showthread.php?t=2315405

    http://ubuntuforums.org/showthread.php?t=1775331
    https://www.gnu.org/software/parted/...ed.html#rescue
    http://gparted.sourceforge.net/faq.php/#faq-22
    Parted rescue seems easier than testdisk
    https://askubuntu.com/questions/6654...untu-partition
    Testdisk Instructions, new versions use sectors, old ones were CHS
    http://www.cgsecurity.org/wiki/TestDisk_Step_By_Step

    UEFI boot install & repair info - Regularly Updated :
    https://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  7. #7
    Join Date
    Oct 2018
    Beans
    18

    Re: Partitioning with sfdisk

    Okay, now I understand about using old sfdisk.

    I've gotten some sleep and not so panicky. Remembering, some of the data is still on the disk, it is just not accessible by the old references.

    I ran Testdisk, again, v7.0 on 18.04 after update. I got a lot of warnings that I am supposed to ignore but ended up with the same 20 +/- partitions. I read the GNU Parted (rescue) and I am hopeful and will try it next instead of sfdisk.
    Will post results.

  8. #8
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Partitioning with sfdisk

    If you have edit partitions multiple times, testdisk finds all the old versions, most will overlap and cannot be selected.
    Best if you know or have good idea of which partitions you last have and at least approximate sizes.
    UEFI boot install & repair info - Regularly Updated :
    https://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  9. #9
    Join Date
    Oct 2018
    Beans
    18

    Re: Partitioning with sfdisk

    Yes, I have them from the fdisk photo.

  10. #10
    Join Date
    Oct 2018
    Beans
    18

    Re: Partitioning with sfdisk

    Code:
    (parted) print                                                            
    Model: ATA TOSHIBA MQ01ABD0 (scsi)
    Disk /dev/sda: 1465149168s
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start        End          Size        File system  Name  Flags
     2      2048s        821247s      819200s
     3      821248s      1435647s     614400s     ntfs
     4      1697792s     918110207s   916412416s  ntfs
     5      918110208s   1450706943s  532596736s  ext4
     6      1450706944s  1457928175s  7221232s    ext2
     1      1457928184s  1465147391s  7219208s
    This is so annoying. Above is the closest I ever got to what I had, but I no longer have that now. NOTE: Number 1 End: 1465147391 not 1465147399 when I try
    Code:
     (parted) mkpart
    I get "is outside of the device". I have 20+ partitions thanks to Testdisk. Since, I have learned I cannot merge partitions so I used Testdisk again and restored one partition with the correct start and end. Then expanded it with Gparted where I get "Failed to load module "canberra-gtk-module"" and then "invalid argument during seek for read on /dev/sda". I still could not get No. 1 to End on the correct sector. Is there any way I can force the partition original starts and ends without formatting?
    Last edited by 1awc; November 3rd, 2018 at 02:19 PM.

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •