Gparted Empty Partition Table 1

Posted by JD 06/07/2011 at 04:02

Today I wanted to add another OS to a netbook, an Asus Eee. My common practice is to boot a gparted ISO from a USB flash drive, move some data and partitions around and add a new logical partition to the end of the extended partition space. Write everything back out to disk. Then I’d boot the install disk/ISO and install to that newly created partition. Life was good, usually.

Today, I was greeted with gparted showing unallocated for the entire drive, all 160GB – unallocated. Ouch. This is the first time I’ve had partition table issues, ever, in over 20 yrs.

A Few Tools

Ok, fine. I’ll take a look at some other tools and see which actually help.

  1. Gparted – well, we know how well that works. It doesn’t even see the partition table on the disk. Sweet! Gparted is the go-to tool for partition management regardless of OS. It appears it doesn’t like corrupt partition tables and chokes.
  2. WinXP Disk Management – this tool sees all the primary partitions, but is basically worthless. I can delete them, but that’s it. Not very useful.
  3. fdisk – under the gparted USB boot, I was able to run fdisk which saw all the partitions, including some extended ones. After reading the table, I toggle a bootable flag on a linux primary partition and tell the tool to write the table. Reboot, no help. Gparted still doesn’t see anything.
  4. cfdisk – under the gparted USB boot, I used cfdisk, but it produced a FATAL ERRORBad primary partition 3: Partition ends after end-of-disk, then it exits.
  5. sfdisk – also under the gparted USB boot, I use sfisk to export the current partition table, then import it, hoping this writes everything to both copies and cleans up any issues in the table. There is a warning that DOS and Linux will interpret the partition table differently since one of the partitions isn’t on a cylinder boundary. I’ve seen this error previously, but ignored it since all the partitions were created using gparted.

Anyway, I’m still stuck, but figured that sharing how to store your partition table for use later could be helpful to someone.

How To Save Your Partition Table Data

To save the current partition table to a file, use:

$ sudo sfdisk -d /dev/sda > part.yyyy.mm.dd.txt

Store that file lots of places, perhaps inside your password database, so it is always available. Here’s what it may look like:

$ sudo sfdisk -d /dev/sda
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 2048, size= 19980288, Id=83, bootable
/dev/sda2 : start= 19984382, size= 985090, Id= 5
/dev/sda3 : start= 0, size= 0, Id= 0
/dev/sda4 : start= 0, size= 0, Id= 0
/dev/sda5 : start= 19984384, size= 985088, Id=82


This is not what my problem disk has, just to be clear. Above is the partitions seen on this virtual machine.

Many laptop users will see some strange partitions. WindowsXP, diagnostics, XP-reload and whatever Linux partitions there are. It can be confusing too, since each OS may see the different partitions differently.

How To Restore Your Partition Table Data

To restore that text file with the partition table data (just the partition table, not any of the actual data stored in each partition, use:

$ sudo sfdisk  —no-reread -f /dev/sda -O PT.save < part.yyyy.mm.dd.txt

this will write the input file, force the changes, and save any previously existing data to a file (binary).

Mirror A Complete HDD

Sometimes you’d like to mirror a complete hard disk – data, partitions, everything. Clonezilla, Partimage, and other, similar, tools can do this, but sometimes you have little time to babysit this process, but lots of time to leave a computer running overnight or for a few hours unattended. When you have that 2nd option, dd may be the tool to use.

A few caveats.

  • You must be root for this to work.
  • The target disk needs to be the same size or larger as the source disk.
  • The source disk should be unmounted (or at least in single-user mode). Unmounted is best. You really should not be running this program of the source and cannot run it from the target disk.
  • The target disk will be completely wiped – up to the size of the source disk, but, since you are over-writing the partition table, all the data from the remaining, unwritten, parts of the disk will only be recoverable though forensic methods. Not for the faint of heart.
  • The type of partition doesn’t matter at all. DOS, NTFS, TiVo, Mac, Linux, EXT2/3/4, JFS, XFS, whatever. It will all get mirrored – partition data, data, everything.
  • Drives in a RAID set probably cannot be mirrored successfully, but it might work if the source and target disks are itentical. I’ve never tried this.

I usually boot a Linux live CD or Linux Flash Drive for this. Any of them will include the dd program.

# dd if=/dev/sda of=/dev/sdh  bs=1024000

The larger bs is useful to provide more buffers for the read/write operations. There’s probably a better, more efficient, block size, but 1MB seems reasonable. I’ve used this many times.

  • /dev/sda = is the in-file or source disk. You’ll need to select the disk for your needs. /dev/hd{x} may be needed for IDE disks.
  • /dev/sdh = is the out-file or target disk. /dev/sdb or /dev/sdc may be used for 2nd or 3rd HDDs inside a PC.

Mirroring an ISO, Boot CDROM or DVD

Sometimes you have an ISO CDROM and need to mirror it. To make a CDROM into an ISO file, dd rocks.

# dd if=/dev/hdc of=/tmp/live-cd.iso bs=10240000

Simple.
To shove that data back to a CDROM, you probably want to use an optical disk writer like k3b or nero.

Backups and Disaster Recovery Plans

Having a good backup is critical. Having a mirror of a running system can be the difference between a simple disk swap and quick recovery or a long bare metal recovery process. Not all backup solutions are created equal.

You probably want to test these restore procedures before it becomes an emergency.

The Fix

So after all that, the thing that fixed my netbook was reinstalling grub. From the same gparted USB boot, I found grub v1.98xxxxxxxx. This is grub2, which seems really dumb to me, since they were already near the 2.0 release number, why didn’t they simply bump it to 2.0000001 to show it was alpha quality code?

The grub command was nowhere to be found on this system, but there were lots of grub-this and grub-that commands. Anyway here’s the command:

\# mount /dev/sda3 /mnt
\# grub-install --root-directory=/mnt /dev/sda

That was it. I can see all the partitions and can boot some of them again, however a few seem to have superblock issues on the partition and fsck couldn’t fix. Time to figure out how to load GRC Spinrite onto a USB flash drive.

Not having floppy or CDROM disks on netbooks really is a pain.

  1. topernic 07/01/2011 at 21:22

    Good article. Thanks