sda2 is corrupted (HOWTO NOT HELP)

Bryn M. Reeves bmr at redhat.com
Fri Jul 6 17:41:59 UTC 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/06/2012 05:35 PM, Jim wrote:
> Thanks Rick I have done all that you have said but now I'm running
> into read-only file systems, what command would I use to change the
> ro to rw on external hard drive sdb1 ?
> 

Since the original dd command:

dd if=/dev/sda2 of=/dev/sdb1

Probably overwrote the file system that was on sdb1 (even though it
was mounted - Linux/UNIX will not stop you from doing that) this is
the most likely cause of the file system now being read only.

If you give dd the path of a block device (for e.g. /dev/sda2 or
/dev/sdb1) then it will write or read directly to or from the device.

This is useful for copying file system images between devices but is
probably not what you wanted here.

The "if=" argument to dd is the input file - where to read from - and
the "of=" argument is the output - where to write to. If this command
ran for any length of time it will have overwritten the file system on
sdb1.

When creating an image in another file system the "if=" argument must
be a device and the "of=" argument needs to be a path that refers to a
location on the target file system.

For instance, if I have /dev/sdc5 mounted on /home:

# mount | grep home
/dev/sdc5 on /home type ext3 (rw)

And if I want to take an image of /dev/sda2 and store it in a file
named "sda2.img" in my home directory I would run:

# dd if=/dev/sda2 of=/home/bmr/sda2.img

You need to do something similar but specifying a path that
corresponds to the correct mount path for your sdb1 file system. When
taking an image like this "if" is a device node in /dev and "of" is a
path in the mounted file system.

The reason your file system is now read-only is that when ext2/3/4 (or
other file systems) detect an inconsistency with what's expected to be
on the disk they will place the fs in read-only mode to prevent
further damage.

When the kernel started reading unexpected data from sdb1 it triggered
this mechanism and aborted the file system.

The file system on sdb1 is possible damaged beyond repair at this
point so if there was nothing valuable on it already you are probably
best off unmounting it and creating a new file system on the device.

You should take some time to make sure you have everything correct
this time and ask questions if you're unsure about the right commands
to use but assuming sdb1 did not contain anything you want to recover
you could create a new file system on it, mount it, and create the
image with steps like the following:

# umount /dev/sdb1    [ ensure that the device is not mounted before
                       proceeding ]

This umount is probably the step you missed if you're still seeing
read-only messages.

# mkfs.ext4 /dev/sdb1 [ or mke2fs -t ext3 as Rick suggested - they
                        will both give you the same result ]
# mount /dev/sdb1 /mnt
# dd if=/dev/sda2 of=/mnt/sda2.img

This will create a new file named sda2.img in the top-level directory
of the new file system on sdb1 that is mounted at /mnt.

You can check that the mount command worked by running:

# dmesg | tail
EXT4-fs (loop7): mounted filesystem with ordered data mode
SELinux: initialized (dev loop7, type ext4), uses xattr

The device name will be different but you should see the mount message.

If you try this and get any errors it's probably a good idea to check
them out before carrying on.

You can find an example of all these commands and their output in
fpaste here: http://fpaste.org/XYNU/

Don't expect the output to be identical on your system but it should
provide a guide (I've tried to highlight where you should see
something different).

Regards,
Bryn.
`
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk/3I2cACgkQ6YSQoMYUY977BgCgmgUjvNItw7ZQnyOA2QWeVmhW
XkwAoJ35Dy24Wc7VoEBz5OkkVg0orJoH
=PUag
-----END PGP SIGNATURE-----


More information about the users mailing list