Repair a Damaged MBR Layout Safely with fixparts
You will use fixparts to inspect an MBR partition table, correct a supported layout problem, and save it only after checking the proposed result. The examples use FixParts 1.0.10 from the installed gdisk package, version 1.0.10-1build1.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about 20 minutes for inspection and a little longer if you need to shut down services or boot from rescue media. You need a root shell for the disk write, a backup destination on a different disk, and a disk that really uses MBR partitioning. This is a partition-table repair tool, not a general partition editor.
1. Confirm the target before opening it
List disks and their partition-table types first. This is an ordinary, read-only check:
$ lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,PTTYPE,MODEL
$ command -v fixparts
/usr/sbin/fixparts
$ dpkg-query -W -f='${Package} ${Version}\n' gdisk
gdisk 1.0.10-1build1
Replace /dev/DEVICE below with the whole disk, such as /dev/sdb, not a partition such as /dev/sdb1. The PTTYPE column should identify an MBR disk. Stop if the target is the wrong device or is a conventional GPT disk: fixparts refuses conventional GPT layouts, and using a partition path is not a safe shortcut.
Checkpoint: record the exact device name and model from lsblk. Do not continue from memory if several disks have similar sizes.
2. Save a partition-table backup
Before using a tool that can rewrite the first sectors of a disk, save a textual partition-table dump to another storage device. The command below is unprivileged if you can read the disk, but use sudo if it reports a permission error:
$ sudo sfdisk --dump /dev/DEVICE > /path/on/another-disk/DEVICE-partitions.txt
$ test -s /path/on/another-disk/DEVICE-partitions.txt && echo 'backup is non-empty'
backup is non-empty
Replace both placeholders. Do not put the backup on the disk being repaired. Keep it until the machine has booted and the filesystems have been checked. The dump is useful for reconstruction with sfdisk, but it is not a substitute for a filesystem backup.
Destructive action
Saving in fixparts rewrites partition-table data. It can change partition numbers and ordering, and a mistake can make filesystems inaccessible. If the data matters, make a separate file-level or image backup and plan a recovery boot before continuing.
3. Inspect the table without saving
Start fixparts with elevated privileges because the device normally requires them:
$ sudo fixparts /dev/DEVICE
FixParts 1.0.10
Loading MBR data from /dev/DEVICE
MBR command (? for help): p
The exact banner and partition rows depend on the disk. The p command prints partition numbers, active flags, sector ranges, primary or logical status, omission state, convertibility and type codes.
FixParts hides the extended partition in its interface and regenerates one when needed. Its displayed numbers are not guaranteed to become the kernel's final numbers. That is expected behaviour, not evidence that the display is corrupt.
Checkpoint: use p, compare every start and end sector with your backup and earlier notes, then type q if you only meant to inspect:
MBR command (? for help): q
Do you really want to quit? (Y/N): y
q abandons in-memory changes. It does not undo the optional GPT-signature cleanup described in the next step.
4. Handle leftover GPT data carefully
When fixparts starts, it scans for GPT headers. A disk that looks like MBR but still has stray GPT data may prompt to erase that data. Read the prompt and confirm the device before accepting. If it looks like a normal GPT disk, stop rather than forcing an MBR interpretation.
This initial cleanup is the exception to the normal in-memory rule: accepting it can erase a GPT header immediately. There is no fixparts q action that restores an erased header. Only accept the cleanup when you have established that the MBR table is the intended layout and your backup is available.
5. Apply one supported repair
At the MBR command prompt, use the smallest change that addresses the problem. Common commands are:
lchanges a selected partition to logical when the layout permits it.rchanges a selected partition to primary when the layout permits it.oomits a partition from the saved table. It remains visible while editing, but is lost if you write.atoggles the active or boot flag.tchanges a partition type code entered as one-byte hexadecimal.ssorts the display by on-disk position.crecomputes CHS values, which are obsolete but can matter to old software.
Do not use fixparts to create partitions: it cannot do that. For ordinary type-code, flag or deletion work, the manual recommends fdisk because fixparts may renumber partitions even when you did not request a layout conversion.
If a conversion is refused, inspect the layout rather than forcing it. Primary and logical partitions cannot be interleaved arbitrarily. Omitting a preceding partition can sometimes create the space needed for a logical conversion, but omission is destructive when saved.
6. Review, then write exactly once
After the intended edit, type p again. Check that the sector ranges, selected status, active flag and type code are what you expect. Use ? if you lose your place:
MBR command (? for help): p
MBR command (? for help): ?
MBR command (? for help): w
The w command writes the table and exits. Treat its confirmation prompt as the final checkpoint. If anything is unclear, type q instead. Once the write completes, stop using the old partition numbers until the kernel and your tools have rediscovered the table.
7. Re-read the result and check dependencies
After fixparts exits, ask the kernel and a partitioning tool what they now see:
$ lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,PTTYPE /dev/DEVICE
$ sudo fdisk -l /dev/DEVICE
Some running kernels do not immediately re-read a changed table, especially when partitions are mounted. A reboot into a maintenance or rescue environment is often the cleanest next step. Do not continue mounting filesystems or starting services until the device and partition numbers match your plan.
Check configuration that names partitions directly. A renumbered table can break boot-loader entries and /etc/fstab references such as /dev/sdb1. Prefer filesystem UUIDs where appropriate, but verify them against the actual filesystems before editing anything. If the result is wrong, stop, boot from recovery media if necessary, and use the saved dump or a tested image backup to restore the previous table. Do not run a guessed restore command against the disk.
Common traps
- A GPT disk is not an MBR repair target. Choose a GPT-aware tool or restore the intended GPT layout instead.
- Displayed fixparts numbers are temporary editor numbers. They do not promise final Linux device names.
- CHS values are mostly obsolete, and fixparts warns that its values may be wrong on disks smaller than about 8 GiB except on Linux.
- The tool can load at most 128 partitions: four primary entries and 124 logical entries.
- Keep partitions unmounted where possible. A live root or boot disk is a poor repair target; use a rescue environment and a maintenance window.
Done means
- The target was confirmed as the intended MBR disk.
- A non-empty partition-table backup exists on different storage.
- The proposed table was reviewed with
pbeforewwas used. - Post-write tools show the expected ranges, types and flags.
- Mounts, boot configuration and
/etc/fstabhave been checked for changed partition numbers. - The backup remains available until normal boot and filesystem checks succeed.