First of all - thank you for a great tool! I've used it successfully in the past as well.
I'd like to try to recover a couple of partitions that got wiped in an android update (the partitions are on an EMMC card that can be accessed via a USB mass storage reader and usually lives in an Odroid N2 SBC).
My partitioning scheme was like this before the upgrade:

The unpartitioned space before the first partition and following it is used by android. The first partition is android's /cache and the second one is USERDATA (which combines /data with /sdcard).
Sadly, I don't have their exact addresses.
Well, after android did an upgrade, it cleared the partitions from the MBR, and marked the second partition to extend until the end of the disk. But it did not resize the filesystem, so it still ends where it did before.
I've checked with testdisk and I can still find the missing BOOT and rootfs partitions and can browse their files, but I'd prefer not to let testdisk write them to disk, because, as far as I can tell, it gets tricked and can't reliably find the extended partition, and creates BOOT as a primary partition and rootfs inside an extended partition.
Here is the output log
Code: Select all
Using locale 'en_US.UTF-8'.
Mon Feb 1 16:24:26 2021
Command line: TestDisk /log /dev/sdb
TestDisk 7.1, Data Recovery Utility, July 2019
Christophe GRENIER <grenier@cgsecurity.org>
https://www.cgsecurity.org
OS: Linux, kernel 5.4.0-65-generic (#73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021) x86_64
Compiler: GCC 9.2
ext2fs lib: 1.45.5, ntfs lib: libntfs-3g, reiserfs lib: none, ewf lib: none, curses lib: ncurses 6.1
Hard disk list
Disk /dev/sdb - 31 GB / 29 GiB - CHS 29820 64 32, sector size=512 - Generic MassStorageClass, FW:1538
Partition table type (auto): Intel
Disk /dev/sdb - 31 GB / 29 GiB - Generic MassStorageClass
Partition table type: Intel
Analyse Disk /dev/sdb - 31 GB / 29 GiB - CHS 29820 64 32
BAD_RS LBA=2185488 2048
check_FAT: Unusual number of reserved sectors 6 (FAT), should be 1.
check_FAT: Incorrect number of sectors per FAT
check_part_i386 failed for partition type 0C
BAD_RS LBA=7084304 2048
Current partition structure:
check_FAT: Unusual number of reserved sectors 6 (FAT), should be 1.
check_FAT: Incorrect number of sectors per FAT
Invalid FAT boot sector
1 P FAT32 LBA 1067 8 17 1099 8 16 65536
1 P FAT32 LBA 1067 8 17 1099 8 16 65536
Warning: Bad ending sector (CHS and LBA don't match)
2 P Linux 3459 8 17 29819 63 32 53987056
Warning: Bad ending sector (CHS and LBA don't match)
No partition is bootable
search_part()
Disk /dev/sdb - 31 GB / 29 GiB - CHS 29820 64 32
Filesystem created: Thu Aug 6 15:15:53 2020
Last mount time: Tue Jan 1 02:00:20 2019
Linux 558 1 1 1582 0 32 2097152 [cache]
ext4 blocksize=4096 Large_file Sparse_SB Recover, 1073 MB / 1024 MiB
Filesystem created: Tue Jan 1 02:01:36 2019
Last mount time: Mon Feb 1 13:45:59 2021
Linux 3459 8 17 19658 63 32 33177328
ext4 blocksize=4096 Large_file Sparse_SB Recover, 16 GB / 15 GiB
Filesystem created: Fri Dec 18 07:15:29 2020
Last mount time: Wed Dec 30 14:03:25 2020
Linux 19660 0 1 19915 63 32 524288 [BOOT]
ext2 blocksize=4096 Large_file Sparse_SB, 268 MB / 256 MiB
Filesystem created: Fri Dec 18 07:15:30 2020
Last mount time: Wed Dec 30 15:48:35 2020
Linux 19917 0 1 29819 63 32 20281344 [rootfs]
ext4 blocksize=4096 Large_file Sparse_SB, 10384 MB / 9903 MiB
get_geometry_from_list_part_aux head=64 nbr=5
get_geometry_from_list_part_aux head=8 nbr=5
get_geometry_from_list_part_aux head=16 nbr=5
get_geometry_from_list_part_aux head=32 nbr=5
get_geometry_from_list_part_aux head=64 nbr=5
get_geometry_from_list_part_aux head=128 nbr=3
interface_write()
1 * Linux 558 1 1 1582 63 32 2099168 [cache]
2 P Linux 3459 8 17 19658 63 32 33177328
3 P Linux 19660 0 1 19915 63 32 524288 [BOOT]
4 E extended LBA 19916 0 1 29819 63 32 20283392
5 L Linux 19917 0 1 29819 63 32 20281344 [rootfs]
- use linux fdisk to print the partition offsets in sectors
- delete the second partition
- recreate the second partition with the same start offset, but with the original size (derived as BOOT start offset - 1MB)
- create a new extended partition
- create a new BOOT partition with the offsets retrieved by testdisk
- create a new rootfs partition with the offsets retrieved by testdisk
I was hoping testdisk would provide me (somehow) with the start/end sector of each partition, so I could feed this data into fdisk, but I get only CHS instead. I've looked online for ways to convert between the two, (even tried the code referenced here: https://superuser.com/questions/974581/ ... sk-storage), but I couldn't validate that the data reported by testdisk resembled the data in sectors reported by fdisk (for the first partition, which is unchanged).
So - I'd like to ask - is there a way to ask testdisk to report offsets in sectors, to be compatible with fdisk?
I also tried to use parted and use 'chs' unit, but the disk geometry was completely different than what testdisk reported, so the addresses were incompatible...
Plan b (in my case) is to use tune2fs:
Code: Select all
tune2fs -l /dev/sdb2
tune2fs 1.45.5 (07-Jan-2020)
Filesystem volume name: <none>
Last mounted on: /data
Filesystem UUID: 354d2ccc-bc98-4aba-bf75-1750d8d9d71d
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent sparse_super large_file huge_file uninit_bg dir_nlink extra_isize quota
Filesystem flags: unsigned_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 1040384
Block count: 4147166
Reserved block count: 8192
Free blocks: 689526
Free inodes: 972071
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 1023
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Filesystem created: Tue Jan 1 02:01:36 2019
Last mount time: Mon Feb 1 13:45:59 2021
Last write time: Mon Feb 1 13:45:59 2021
Mount count: 15
Maximum mount count: -1
Last checked: Mon Feb 1 10:36:07 2021
Check interval: 0 (<none>)
Lifetime writes: 40 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 1065 (group unknown)
First inode: 11
Inode size: 256
Required extra isize: 32
Desired extra isize: 32
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 5649bd68-5411-4b6c-865f-c03fe836fd90
Journal backup: inode blocks
User quota inode: 3
Group quota inode: 4