Bug 208634 - mkswap "works" without warning on a device containing a mounted filesystem
Summary: mkswap "works" without warning on a device containing a mounted filesystem
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: util-linux
Version: 5
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Karel Zak
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-09-29 19:42 UTC by Jim Wright
Modified: 2007-11-30 22:11 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-10-12 13:38:06 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Jim Wright 2006-09-29 19:42:14 UTC
Description of problem:

In my case I meant to turn hdb5 into swap but accidentally specified hda5 so I
lost data (until I fixed it with e2fsck as below).

If this is a feature and not a bug (e.g. some conformance requirement) then I
think it may be worth reviewing anyway because the ability to turn a mounted
filesystem into a swap partition is not just dangerous but useless.

How reproducible:

In what follows I make temporary use of a spare swap partition. First I make it
into an ext3 partition and mount it.

  [root@wright-d600 ~]# swapon -s
  Filename                                Type            Size    Used    Priority
  /dev/hda3                               partition       1052248 0       -1
  /dev/hda8                               partition       1052216 0       -2
  [root@wright-d600 ~]# swapoff /dev/hda8
  [root@wright-d600 ~]# mke2fs -j /dev/hda8
  mke2fs 1.38 (30-Jun-2005)
  Filesystem label=
  OS type: Linux
  Block size=4096 (log=2)
  Fragment size=4096 (log=2)
  131616 inodes, 263056 blocks
  13152 blocks (5.00%) reserved for the super user
  First data block=0
  Maximum filesystem blocks=272629760
  9 block groups
  32768 blocks per group, 32768 fragments per group
  14624 inodes per group
  Superblock backups stored on blocks:
          32768, 98304, 163840, 229376
  
  Writing inode tables: done
  Creating journal (8192 blocks): done
  Writing superblocks and filesystem accounting information: done
  
  This filesystem will be automatically checked every 29 mounts or
  180 days, whichever comes first.  Use tune2fs -c or -i to override.
  [root@wright-d600 ~]# mount /dev/hda8 /mnt/tmp
  [root@wright-d600 ~]# ls /mnt/tmp
  lost+found
  [root@wright-d600 ~]# # ****THIS IS WHERE THE DISASTER OCCURS****
  [root@wright-d600 ~]# mkswap /dev/hda8
  Setting up swapspace version 1, size = 1077473 kB
  [root@wright-d600 ~]# ls /mnt/tmp
  [root@wright-d600 ~]# # ... NOTHING THERE NOW

Version-Release number of selected component (if applicable):

e2fsprogs-1.38-12 under FC5
e2fsprogs-1.38-0.FC3.1 under FC3

Steps to Reproduce:

See above.
  
Actual results:

mkswap corrupts the mounted filesystem by overwriting the first superblock with
swap format info. 

Expected results:

An error - "cannot format a mounted partition as swap partition". Failing that a
warning and request for confirmation.

Additional info:

In case you found this bug after a similar experience, here is how to recover
your data:

  [root@wright-d600 ~]# umount -l /mnt/tmp
  [root@wright-d600 ~]# e2fsck -y /dev/hda8
  e2fsck 1.38 (30-Jun-2005)
  Couldn't find ext2 superblock, trying backup blocks...
  /dev/hda8 was not cleanly unmounted, check forced.
  Pass 1: Checking inodes, blocks, and sizes
  Pass 2: Checking directory structure
  Pass 3: Checking directory connectivity
  Pass 4: Checking reference counts
  Pass 5: Checking group summary information
  
  /dev/hda8: ***** FILE SYSTEM WAS MODIFIED *****
  /dev/hda8: 11/131616 files (9.1% non-contiguous), 12669/263056 blocks

Now you can remount, unless you had to umount a busy filesystem in which case
probably reboot first.

Comment 1 Thomas Woerner 2006-10-02 08:10:59 UTC
mkswap is not part of e2fsprogs. Reassigning to util-linux.

Comment 2 Thomas Woerner 2006-10-02 08:11:11 UTC
mkswap is not part of e2fsprogs. Reassigning to util-linux.

Comment 3 Karel Zak 2006-10-12 09:58:39 UTC
Fixed in the devel branch.

Comment 4 Karel Zak 2006-10-12 13:38:06 UTC
This will be fixed in FC6.

Comment 5 Jim Wright 2006-10-12 18:30:48 UTC
Thanks. I'm impressed and surprised at your rapid response.


Note You need to log in before you can comment on or make changes to this bug.