Re: recovery from mkswap on mounted raid1 ext3 filesystem?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday May 15, jdc@xxxxxx 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
-
To unsubscribe from this list: send the line "unsubscribe linux-raid" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux