LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-18-2021, 04:30 AM   #1
questionderby
Member
 
Registered: May 2021
Posts: 32

Rep: Reputation: 0
Lost partitions


Hi, so I was making an install script and accidentally ran it as root... I now have a new partition table(I think) and two partitions. How can I undo this/ recover those partitions? I realized this when I rebooted, grub froze and didn't show anything. Tried a liveos to mount a partition, here's the message:

"mount: /mnt: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error."

I wanted to do an fsck, and got a message. I would copy it here but I don't wanna interact with the hard drive any more. Something about the partition sizes, saying that the superblock says partition is "big number" blocks, but the partition is "smaller number".

I had three partitions before, one was 20G at the beginning of the drive, one was 35G right next to it, the last one took up the rest of the drive. Now I have 1 partition at the beginning of the drive, 30G. And the other one takes up the rest of the drive. I don't know what to do or where to go or what to read up on, please help or redirect me to somewhere.


EDIT: Thanks guys, I now have all my partitions back, all (seemingly) working fine!

Last edited by questionderby; 05-21-2021 at 12:55 PM.
 
Old 05-18-2021, 04:45 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
The canonical answer is testdisk. Freeware and very good. Run it from a liveUSB - your install USB should do; install testdisk on the liveUSB itself if it isn't already there and fix the disk from there.

Have a look at the step by step tutorial.
 
Old 05-18-2021, 01:00 PM   #3
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,490

Rep: Reputation: Disabled
Just re partition it - or do you mean that you had data on it, but didn't have a back up - (always have a back up of your personal data).

As above, if you had data on it, & no back up, (but it won't be easy).
 
Old 05-19-2021, 04:57 AM   #4
questionderby
Member
 
Registered: May 2021
Posts: 32

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by fatmac View Post
Just re partition it - or do you mean that you had data on it, but didn't have a back up - (always have a back up of your personal data).

As above, if you had data on it, & no back up, (but it won't be easy).
Yes, I had data on it, and two OSes installed. I want to recover those partitions and partition table so I don't have to bother with installing again, and I didn't have a back up. I would just repartition if I didn't have anything on it
 
Old 05-19-2021, 05:37 AM   #5
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 924

Rep: Reputation: 43
Try what @syg00 told you - TestDisk - or alternatively - Ext4Magic if it was ext partition.
But Im rather skeptical u will recover whole partition(s). Maybe some files.


TestDisk:
https://www.cgsecurity.org/wiki/TestDisk

Ext4Magic:
http://ext4magic.sourceforge.net/howto_en.html
 
Old 05-19-2021, 09:37 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Without knowing exactly what your script changed it is difficult to post exactly what needs to be accomplished to undo/recover from your mishap.

A partition is just a container for the filesystem and basically a pointer to where it is located on the disk. Just changing the partition table does not delete the filesystem and iff you recreate the table exactly as it was before everything should be as it was. If you reformatted or if fsck changed anything then you are stuck with trying to recover files byte by byte. Reformatting removes the metadata that basically tells the OS where a file is located but in addition since you changed the partition table it will overwrite anything at the physical location at the beginning of the new partition.

As posted testdisk is a good starting point.
 
Old 05-19-2021, 03:55 PM   #7
questionderby
Member
 
Registered: May 2021
Posts: 32

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
Without knowing exactly what your script changed it is difficult to post exactly what needs to be accomplished to undo/recover from your mishap.

A partition is just a container for the filesystem and basically a pointer to where it is located on the disk. Just changing the partition table does not delete the filesystem and iff you recreate the table exactly as it was before everything should be as it was. If you reformatted or if fsck changed anything then you are stuck with trying to recover files byte by byte. Reformatting removes the metadata that basically tells the OS where a file is located but in addition since you changed the partition table it will overwrite anything at the physical location at the beginning of the new partition.

As posted testdisk is a good starting point.
I wrote the script. Here are the lines that did the changes:

Code:
fdisk /dev/sda << FDISK_CMDS
o
n
p
1

+30G
n
p
2


w
FDISK_CMDS
partx /dev/sda
from the script itself. I had a DOS partition table before as well, and three partitions as mentioned above:
35G ext4 partition at the beginning of the disk
20G partition right next to the above one, ext4
The last partition which takes up the rest of the disk space, ext4

Now I have:
A new DOS partition table
A 30G partition at the beginning of the disk, ext4
A partition right next to it taking up the rest of the disk, with no fs on it apparently... at least lsblk doesn't show any.
I don't see or remember putting anything like mkfs.ext4 or anything in my script, so I don't think it made a new filesystem. As for fsck, it asked to change something, but I aborted it(answered n).

Last edited by questionderby; 05-20-2021 at 05:06 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto recover lost and formatted data on lost partitions. Sören Schneider LinuxQuestions.org Member Success Stories 2 04-05-2006 06:38 AM
Lost mouse after reboot+lost modem BACTRATE Mandriva 3 04-07-2005 06:45 AM
power lost from cable modem, interface lost a10392 Linux - Networking 4 11-16-2004 09:01 AM
C++ templates + linked lists... lost.. very lost.. exodist Programming 2 05-12-2004 11:04 PM
Partitions, partitions, partitions..... Clueless in VA Linux - Newbie 7 08-08-2001 03:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration