Bug 208634 - mkswap "works" without warning on a device containing a mounted filesystem
mkswap "works" without warning on a device containing a mounted filesystem
Status: CLOSED NEXTRELEASE
Product: Fedora
Classification: Fedora
Component: util-linux (Show other bugs)
5
All Linux
medium Severity medium
: ---
: ---
Assigned To: Karel Zak
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2006-09-29 15:42 EDT by Jim Wright
Modified: 2007-11-30 17:11 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-10-12 09:38:06 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jim Wright 2006-09-29 15:42:14 EDT
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 04:10:59 EDT
mkswap is not part of e2fsprogs. Reassigning to util-linux.
Comment 2 Thomas Woerner 2006-10-02 04:11:11 EDT
mkswap is not part of e2fsprogs. Reassigning to util-linux.
Comment 3 Karel Zak 2006-10-12 05:58:39 EDT
Fixed in the devel branch.
Comment 4 Karel Zak 2006-10-12 09:38:06 EDT
This will be fixed in FC6.
Comment 5 Jim Wright 2006-10-12 14:30:48 EDT
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.