* recovery from mkswap on mounted raid1 ext3 filesystem?
@ 2006-05-16 2:19 Dan Christensen
2006-05-16 2:41 ` Neil Brown
0 siblings, 1 reply; 3+ messages in thread
From: Dan Christensen @ 2006-05-16 2:19 UTC (permalink / raw)
To: linux-raid
I accidentally ran mkswap on an md raid1 device which had a mounted
ext3 filesystem on it. I also did a swapon, but I don't think
anything was written to swap before I noticed the mistake. How much
of the partition is toast, and is it something e2fsck might fix?
Luckily I have a recent full backup, but it would be easier if
there was a quick fix! :-)
Thanks,
Dan
(For the curious: I made the mistake because my fstab file had md0 and
md1 reversed, because a few kernel revisions back the kernel decided
to name them differently. And for some reason, the "mount" command
reports the wrong information from my fstab rather than the right
information which is (for example) in /proc/mounts. Is this a bug?
Moreover, shouldn't the mkswap command check whether a device is in
use before overwriting it?
I realize this isn't the right list for these questions...)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: recovery from mkswap on mounted raid1 ext3 filesystem?
2006-05-16 2:19 recovery from mkswap on mounted raid1 ext3 filesystem? Dan Christensen
@ 2006-05-16 2:41 ` Neil Brown
2006-05-16 3:22 ` Dan Christensen
0 siblings, 1 reply; 3+ messages in thread
From: Neil Brown @ 2006-05-16 2:41 UTC (permalink / raw)
To: Dan Christensen; +Cc: linux-raid, Adrian Bunk
On Monday May 15, jdc@uwo.ca wrote:
> I accidentally ran mkswap on an md raid1 device which had a mounted
> ext3 filesystem on it. I also did a swapon, but I don't think
> anything was written to swap before I noticed the mistake. How much
> of the partition is toast, and is it something e2fsck might fix?
oh dear....
I think (and an strace seems to confirm) that mkswap only writes in
the first 4k of the device. This will have held the superblock, but
there is always at least one backup - I think it is as block 8193.
But 'fsck -n' should help you out, though you might need
'fsck.ext2 -n' as 'fsck' might think it is a swap device...
Ofcourse, if the filesystem is mounted, then unmounting the filesystem
should write the superblock, which might fix any corruption you
caused..
I'm very surprised that swapon worked if the fs was mounted - there
should be mutual exclusion there.
>
> Moreover, shouldn't the mkswap command check whether a device is in
> use before overwriting it?
Yes, but before 2.6 this was very hard to do (in 2.6 it is easy, just
open with O_EXCL). I doubt mkswap has seen much maintenance
later.... not since Dec 2004 in fact. And the only checks it does is
to make sure you aren't running mkswap on /dev/hda or /dev/hdb !!!
Adrian: You seem to be the MAINTAINER of mkswap.. any chance of
opening for O_EXCL as well as O_RDWR. That would make it a lot safer.
NeilBrown
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: recovery from mkswap on mounted raid1 ext3 filesystem?
2006-05-16 2:41 ` Neil Brown
@ 2006-05-16 3:22 ` Dan Christensen
0 siblings, 0 replies; 3+ messages in thread
From: Dan Christensen @ 2006-05-16 3:22 UTC (permalink / raw)
To: linux-raid; +Cc: Adrian Bunk
Neil Brown <neilb@suse.de> writes:
> On Monday May 15, jdc@uwo.ca wrote:
>> I accidentally ran mkswap on an md raid1 device which had a mounted
>> ext3 filesystem on it. I also did a swapon, but I don't think
>> anything was written to swap before I noticed the mistake. How much
>> of the partition is toast, and is it something e2fsck might fix?
>
> I think (and an strace seems to confirm) that mkswap only writes in
> the first 4k of the device. This will have held the superblock, but
> there is always at least one backup - I think it is as block 8193.
> But 'fsck -n' should help you out, though you might need
> 'fsck.ext2 -n' as 'fsck' might think it is a swap device...
Thanks for the quick response! I tried e2fsck, and it found the
backup superblock on its own. I answered yes to dozens of questions,
and the filesystem is now intact.
> Ofcourse, if the filesystem is mounted, then unmounting the filesystem
> should write the superblock, which might fix any corruption you
> caused..
I decided to do a Alt-Sysrq-u Alt-Sysrq-b reboot to minimize what
was written to disk when things were already messed up.
> Adrian: You seem to be the MAINTAINER of mkswap.. any chance of
> opening for O_EXCL as well as O_RDWR. That would make it a lot safer.
That would have saved me lots of worry!
Thanks again,
Dan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-05-16 3:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-16 2:19 recovery from mkswap on mounted raid1 ext3 filesystem? Dan Christensen
2006-05-16 2:41 ` Neil Brown
2006-05-16 3:22 ` Dan Christensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).