Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.