Hello.
Is there an easy way to merge two non-empty partitions which have the same filesystem without losing data?
In my case, I have 300GB hard drive broken into two partitions, each has about 80GB of data in it. The goal is to merge them without formatting or moving data from one to another and gradually increasing the size of the end partition.
P.S.: I tried changing partition table with fdisk (deleted one, then increased another) and now I only have data from the partition I haven’t deleted. So the lost data is still there, just need to find the way to make it visible again.
First and foremost it seems important to you to restore what you have done, even before contemplating about how to do what you want.
You can only undo what you did by using fdisk again and recreating the removed partition with EXACT the same parameters (especialy the begin/end addresses) it had before. I hope you have a backup of a former *fdisk -l *somewhere or has written them down or can reconstruct them from the start/end addresses of the still existing partitions.
When this is not the case, you have to restore the data later from the backup you made before you started changing the partition table.
When you want more suggestions about your partitioning please post the output of
fdisk -l
(and of course between CODE tags: Posting in Code Tags - A Guide).
One more option for repairing the damage you have done is TestDisk - CGSecurityyou can find it on the PartedMagic liveCD downloads
As for the rest of the question, I would simply delete one partition, resize the other and restore from my backup.
On 2011-04-26 10:36, RotogloK wrote:
>
> Hello.
> Is there an easy way to merge two non-empty partitions which have the
> same filesystem without losing data?
Easy, no.
> In my case, I have 300GB hard drive broken into two partitions, each
> has about 80GB of data in it. The goal is to merge them without
> formatting or moving data from one to another and gradually increasing
> the size of the end partition.
Not possible.
If they are contiguous, you could backup the second partition, assuming
they are contiguous, then grow the first, repartitioning.
> P.S.: I tried changing partition table with fdisk (deleted one, then
> increased another) and now I only have data from the partition I haven’t
> deleted. So the lost data is still there, just need to find the way to
> make it visible again.
Good grief, man!
And you did not make a backup. And you did grow the first one… so data in
the second one will be trashed.
Did you grow the filesystem, or just repartitioned? As anything being
written? If the answer is no, then just repartition exactly as it were.
You can find out, perhaps, where the old partitions were with gpart.
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
I deleted the partition, not the filesystem. Then I changed end sector of another partition. I know that the first partition was 119 GB, but I don’t know the exact number of sectors it had. I somehow thought that deleting the partition won’t erase the data on it, seems my memory is tricking me.
On 2011-04-26 21:06, RotogloK wrote:
>
> robin_listas;2330001 Wrote:
>>
>> Did you grow the filesystem, or just repartitioned?
>
> I deleted the partition, not the filesystem. Then I changed end sector
> of another partition. I know that the first partition was 119 GB, but I
> don’t know the exact number of sectors it had. I somehow thought that
> deleting the partition won’t erase the data on it, seems my memory is
> tricking me.
Deleting a partition doesn’t destroy the data, but it makes it not
accessible. There is no way to merge both filesystems into one.
You could recover your data if you replace the partition as it was, unless
anything is written there.
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
Your assumption about the data not changing when changing the partition table is correct. That is why we say you can recover your data when you can recover your partitions table (of course only when you data is not overwritten by any other means).
But your misconception lies imho in the fact that you think that a file system is just a continuous thing with no proper begin end end in such a way that you can put two of them behind each other and that they then miraculous become a new file system. A bit like two rectangle boxes neighbouring each other filled with water where you just remove the divider between them to have one big box filed with water.
This is not true. A file system is an organised thing with a start and an end and a lot of other special places in between. That organisation is spread all over that file system and does not change when you simply remove a divider. When he new space is at the end of the existing file system, software that knows how this type of file system (e.g. ext4) works may be abl to change that organisation and add new structures into the new space. Thus the file system is extended. But of course all organisation data that was in that new space wll be then of nil value (as this will overwrite pieces of file system organisation and data in the new space).
But your biggest error may be that you did not make any backups before you started to play with your partition table. Every partition table thread here has this advice at least one time.
It might sound silly but … would it be a big deal to have a daemon or something making regular snapshots of the partition table… or in the worst case fdisk -l in a cron job? Among all features that are supposed to make life easier, that would be more usefull than automatic mounting of unreadable partitions.
On 2011-04-26 23:36, please try again wrote:
>
> It might sound silly but … would it be a big deal to have a daemon or
> something making regular snapshots of the partition table… or in the
> worst case fdisk -l in a cron job? Among all features that are
> supposed to make life easier, that would be more usefull than automatic
> mounting of unreadable partitions.
Propose it as a junior job or summer project in the project mail list. It
is not that difficult to do
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
Indeed, it is not! Next time someone comes in the development forum and asks how he could be helpful.
I deleted the partition, not the filesystem. Then I changed end sector of another partition.
From my testing TestDisk handles one as simple as this with ease. Have you checked the link I gave?
I, once a week, run a bunch of scripts on all of my systems. They gather important information about them (fdisk -l output being amongst it). These are downloaded to one of the systems where they are available (they are in HTML format) for reference by the system manager. Of course they are also backed up in the normal way.
In my professional life I gathered data in this way from more then a hundred systems (not all Linux, many HP-UX, SunOS, AIX, etc.)
But yes, e.g. a crontab entry running once a day (in /etc/cron.daily) with
fdisk -l >/root/saved-partition-tables/$(date +'%A')
would give you a week of fall back data.
On 2011-04-27 10:36, hcvv wrote:
> But yes, e.g. a crontab entry running once a day (in -/etc/cron.daily-)
> with
That would be a lot of data, over months. No, it has to generate the data
and then compare with the previous set of data. Only save if there is a
difference.
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
Sure, thanks, recovering in progress. For now, it has only recovered a lot of textfiles, all broken inside with texts like “aaaaaaaaaaDIEDIEDIEDIE”. Looks like some kind of demon speaking.
Big thanks to everyone who admitted to this thread, next time I will make a backup. As soon as recovering is done I report.
On 2011-04-27 22:06, RotogloK wrote:
> Sure, thanks, recovering in progress. For now, it has only recovered a
> lot of textfiles, all broken inside with texts like
Something is wrong. It should be a question of minutes after changing the
partition table back, and all files should be intact.
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
But how would I know the exact size of deleted partition?
On 2011-04-28 00:06, RotogloK wrote:
>
> But how would I know the exact size of deleted partition?
gpart. It is just for that situation.
–
Cheers / Saludos,
Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)
Sure, thanks, recovering in progress. For now, it has only recovered a lot of textfiles, all broken inside with texts like “aaaaaaaaaaDIEDIEDIEDIE”. Looks like some kind of demon speaking.
I hope you are recovering these files to a different disc to the one you are working on! From what you had reportedly done, you should not have needed to run a deep search or any of the advanced features. I had hoped you would read the info available in the link provided and follow the procedure required for your situation. What file system is on the partition you are attempting to recover?
Hmm, I should have suggested a dry run without writing anything to disc, and for you to report back.
Finally, testdisk finished its work. What do I have now is
TestDisk 6.12-WIP, Data Recovery Utility, March 2011
Christophe GRENIER <grenier@cgsecurity.org>
http://www.cgsecurity.org
Disk /dev/sdb - 300 GB / 279 GiB - CHS 36482 255 63
The harddisk (300 GB / 279 GiB) seems too small! (< 437 GB / 407 GiB)
Check the harddisk size: HD jumpers settings, BIOS detection...
The following partitions can't be recovered:
Partition Start End Size in sectors
> Linux 19350 97 12 53220 183 19 544126976
Linux 19350 227 14 53221 58 21 544126976
[Continue]
EXT4 Large file Sparse superblock Recover, 278 GB / 259 GiB
So, the program found two ext4 partitions which seem too big for the hard drive. They might have had another cluster size or something. First, there was only one ext4 filesystem on the whole device. Then I split it up, formatted one as NTFS, moved files to another and formatted it as NTFS. Then, what was the first stupid thing I did was that I started downloading 77 GB software, so both filesystems had data on them. And the rest is history.
I would exit testdisk and post the output of *fdisk -l *as suggested by @hcvv in post #2.
I’m still confused as to exactly what you have done, can you try again to clearly explain?