How To Restore Partition Table on Running Linux Mint Ubuntu Debian Machine

Here is an easy way to restore things if you have the starting point and size of each partition using fdisk:

In this example we pretend that /dev/sda was wiped out, but the running system still has the info in /sys/class/block/sda

Go into each partition and record the "start" and "size"

hostdev@box /sys/class/block/sda/sda1 $ cat start
2048
hostdev@box /sys/class/block/sda/sda1 $ cat size
2097152


hostdev@box /sys/class/block/sda $ cat sda2/start
2099200
hostdev@box /sys/class/block/sda $ cat sda2/size
62914560


hostdev@box /sys/class/block/sda $ cat sda3/start
65013760
hostdev@box /sys/class/block/sda $ cat sda3/size
520923740

Now create the same 3 partitions at the same starting point and with the same size using fdisk:


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

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x8e7672df.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (1-4, default 1):
First sector (2048-585524838, default 2048): 2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-585524838, default 585524838): 2097152

Created a new partition 1 of type 'Linux' and of size 1023 MiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (2-4, default 2):
First sector (2097153-585524838, default 2099200): 2099200
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-585524838, default 585524838): 62914560

Created a new partition 2 of type 'Linux' and of size 29 GiB.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (3,4, default 3): 65013760
Value out of range.
Partition number (3,4, default 3):
First sector (2097153-585524838, default 62916608): 65013760
Last sector, +/-sectors or +/-size{K,M,G,T,P} (65013760-585524838, default 585524838): 520923740

Created a new partition 3 of type 'Linux' and of size 217.4 GiB.


Tags:

restore, partition, linux, mint, ubuntu, debian, machinehere, fdisk, dev, sda, info, sys, quot, hostdev, partitions, util, contain, dos, disklabel, disk, identifier, df, primary, extended, container, select, default, sector, sectors, mib, gib,

Latest Articles

  • How To Upgrade Debian 8,9,10 to Debian 12 Bookworm
  • Linux dhcp dhclient Mint Redhat Ubuntu Debian How To Use Local Domain DNS Server Instead of ISPs
  • Docker dockerd swarm high CPU usage cause solution
  • Docker Minimum Requirements/How Efficient is Docker? How Much Memory Does Dockerd Use?
  • qemu-nbd: Failed to set NBD socket solution qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end-of-file before all bytes were read
  • apache2 httpd apache server will not start [pid 22449:tid 139972160445760] AH00052: child pid 23248 exit signal Aborted (6) solution Mint Debian Ubuntu Redhat
  • How to use the FTDI USB serial cable to RJ45 adapter to connect to the console on Cisco/Juniper Switch Router Firewall in Linux Ubuntu Debian Redhat
  • How To Setup Python3 in Ubuntu Docker Image for AI Deep Learning
  • How to Configure NVIDIA GPUs with Docker on Ubuntu: A Comprehensive Guide for AI Deep Learning CUDA Solution
  • Linux Ubuntu Mint how to check nameservers when /etc/resolv.conf disabled solution
  • Docker cannot work on other overlayfs filesystems such as ecryptfs won't start overlayfs: filesystem on '/home/docker/overlay2/check-overlayfs-support130645871/upper' not supported as upperdir
  • Linux How To Access Original Contents of Directory Mounted Debian Mint CentOS Redhat Solution
  • ecryptfs how to manually encrypt your existing home directory or other directory
  • How to Reset CIPC Cisco IP Communicator for CME CUCM CallManager
  • Internet Explorer Cannot Download File "Your security settings do not allow for this file to be downloaded." Security Settings Solution
  • Linux How To Upgrade To The Latest Kernel Debian Mint Ubuntu
  • Firefox how to restore and backup saved passwords and history which files/location
  • Linux How To echo as root solution to use tee permission denied solution Ubuntu Debian Mint Redhat CentOS
  • Linux how to keep command line bash process running if you are disconnected or need to logout of SSH remotely
  • Linux swapping too much? How to check the swappiness and stop swapping