You are not logged in.

#1 2019-07-16 13:12:07

emonhaque
Member
Registered: 2019-07-11
Posts: 14

How to recover data from resized partition? [Solved]

I'd a partition /dev/sda3, resized it using cfdisk, created /dev/sda4 out of it, executed command mkfs.ext4 /dev/sda4 and now I can't access the resized /dev/sda3!

Dolphin says: "Error mounting /dev/sda3 .... : wrong fs type"! Is there a way to recover the partition /dev/sda3 along with the data in it?

Last edited by emonhaque (2019-07-16 15:07:43)

Offline

#2 2019-07-16 13:50:51

seth
Member
Registered: 2012-09-03
Posts: 51,312

Re: How to recover data from resized partition? [Solved]

What do you mean "resized it using cfdisk"??
Restore the *exact* old partition table, do *NOT* call mkfs on it.
Anything you might have overridden w/ the sd4 FS header is gone.
If you cannot recreate the *exact* old partitioning or you managed to override the FS headers of sda3, you're w/ tools like photorec and testdisk.

Repartitioning is NOT done this way: https://wiki.archlinux.org/index.php/Pa … partitions
If you manage to rescue your data, MAKE A BACKUP FIRST.

Offline

#3 2019-07-16 13:59:23

emonhaque
Member
Registered: 2019-07-11
Posts: 14

Re: How to recover data from resized partition? [Solved]

There's an option [Resize] in cfdisk and using that option I've reduced the size of /dev/sda3 and created /dev/sda4. Here's what cfdisk shows now about /dev/sda4

Partition UUID: BF898C73-109A-8442-9C7A-40A48856E3B9                                             
Partition type: Linux filesystem (0FC63DAF-8483-4772-8E79-3D69D8477DE4)                           
Filesystem UUID: b36e96c4-6b1e-4b16-baaa-743ae14a021b                                             
Filesystem: ext4                                                                             
Mountpoint: /run/media/emon/b16e96c4-6b1e-4b26-baaa-743ae14a026b (mount

and for /dev/sda3

Partition UUID: 80E6DB56-2462-344C-BFEA-A9B017615EC1                                               
Partition type: Linux filesystem (0FC63DAF-8483-4772-8E79-3D69D8477                               
Filesystem UUID: 251447bf-985c-4c73-bb9e-8010bfd53fd3                                               
Filesystem: ext4

Last edited by emonhaque (2019-07-16 14:07:55)

Offline

#4 2019-07-16 14:04:42

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: How to recover data from resized partition? [Solved]

How did you resize /dev/sda3, exactly?

Looks like you wanted to shrink sda3 to make space for a new sda4.
To shrink a EXT2/3/4 partition, one must first use resize2fs to shrink the filesystem, then, change the partition table to match the new size. Using cfdisk alone would have only altered the partition table.
Your great mistake is to have run mkfs.ext4 on the new partition sda4. Some of your data was likely overwritten on disk, as seth said above.

If your data is important enough, do a disk backup now using dd. I'd then try to recover things from the disk image file first, and avoid touching the physical disk until I'm certain what works.

EDIT

I don't know about cfdisk, but I think fdisk is more straightforward. Post the output of

fdisk -l /dev/sda

But first of all, you shouldn't mount the partitions at this point. If your data is important, and you want the best chance of recovery, don't touch the disk now. Make a disk image first.

Once you have done that, you can proceed to try and restore the partition table.
You don't seem to have done too much damage, I think...

Last edited by lolilolicon (2019-07-16 14:18:18)


This silver ladybug at line 28...

Offline

#5 2019-07-16 14:12:20

emonhaque
Member
Registered: 2019-07-11
Posts: 14

Re: How to recover data from resized partition? [Solved]

I just selected /dev/sda3, then selected [Resize], hit enter and put the size (500G) and hit enter again. After resizing /dev/sda3, I'd got some free space automatically, selected that free space and selected [New] and hit enter with the default size it gave. After all that, I'd selected [Write] and hit enter.

Last edited by emonhaque (2019-07-16 14:15:04)

Offline

#6 2019-07-16 14:18:55

frostschutz
Member
Registered: 2013-11-15
Posts: 1,418

Re: How to recover data from resized partition? [Solved]

you have to restore sda3 to its original size (same start sector, same size or larger than before is fine too)

I'm unfamiliar with cfdisk resize, but parted resizepart would do it. It just resizes the partition, it does not concern itself with the contents or filesystems of that partition.

obviously first you have to delete the offending partition now occupying the freed space. do not delete sda3.

if the new partition was formatted and the disk is SSD (or virtual machine disk), there is a risk all data in that partition has been discarded already... mkfs.ext4 discards data if the storage supports it

Last edited by frostschutz (2019-07-16 14:20:36)

Offline

#7 2019-07-16 14:20:10

seth
Member
Registered: 2012-09-03
Posts: 51,312

Re: How to recover data from resized partition? [Solved]

Yeah, again: THIS IS NOT HOW IT'S DONE!

Do not write onto that disk. Not sda3, not sda4 either (if you have, you can kiss more data bye-bye)

Operating on a copy is probably a very good idea in this case, then restore the former partition table (essentially remove sda4 and re-grow sda3 (to the exact former size!)
Run partprobe and pray.

In case that's not clear, you data is not stored like this

##################......................................

but like this

##.#...###...#.#.......####.###.#....#....#.............

Offline

#8 2019-07-16 14:23:05

frostschutz
Member
Registered: 2013-11-15
Posts: 1,418

Re: How to recover data from resized partition? [Solved]

yep, have to shrink filesystem first (resize2fs) before you shrink partition. even if there was no data, it would complain out of principle, simply because the size the filesytem remembers is larger than the size of the partition now.

Offline

#9 2019-07-16 14:34:36

emonhaque
Member
Registered: 2019-07-11
Posts: 14

Re: How to recover data from resized partition? [Solved]

hmm! deleting /dev/sda4 and resizing /dev/sda3 to its original size caused some data loss! I've lost a 25GB folder I copied from my desktop last night! I'm not sure whether it's SSD.

Offline

#10 2019-07-16 14:37:30

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: How to recover data from resized partition? [Solved]

You're pretty lucky!
Now you can consider setting up regular backups.
BTW, you can mark this [SOLVED] by editing the title.

Last edited by lolilolicon (2019-07-16 14:47:18)


This silver ladybug at line 28...

Offline

#11 2019-07-16 14:45:37

frostschutz
Member
Registered: 2013-11-15
Posts: 1,418

Re: How to recover data from resized partition? [Solved]

emonhaque wrote:

hmm! deleting /dev/sda4 and resizing /dev/sda3 to its original size caused some data loss! I've lost a 25GB folder I copied from my desktop last night! I'm not sure whether it's SSD.

even if it's not, the mkfs.ext4 on sda4 has written data all over the place (new superblock, backup superblocks, etc. - more if you actually copied anything to it) so natuarlly some damage may be in the sda3 filesystem that previously occupied this space.

it's also possible for files to be there but contain bad data (file metadata, and file contents, are stored in different places)

that 25GB you copied might still be "somewhere" just the metadata pointing to it damaged... who knows.

make backups in future

Last edited by frostschutz (2019-07-16 14:47:22)

Offline

#12 2019-07-16 14:55:10

emonhaque
Member
Registered: 2019-07-11
Posts: 14

Re: How to recover data from resized partition? [Solved]

I didn't have that much in /dev/sda3 other than that 25GB folder. Beside that, I'd Qt Installer, texlive2019 installer, archlinux2019 iso, Etcher and a few other text and pdf docs, everything recovered seems alright.

Qt and texlive2019 has been installed without any issue, Etcher also runs without any issue and documents open without any issue.

Offline

#13 2019-07-16 14:57:53

emonhaque
Member
Registered: 2019-07-11
Posts: 14

Re: How to recover data from resized partition? [Solved]

@frostschutz, is there any tool to recover that 25 GB? I used to use a tool in windows (can't recall the name right now) to recover deleted data from a disk.

Offline

#14 2019-07-16 15:05:07

seth
Member
Registered: 2012-09-03
Posts: 51,312

Offline

Board footer

Powered by FluxBB