Disk problems prevent me from booting, or set the disk to read-only. How do I fix the disk?

7,005

Solution 1

You're trying to fsck the wrong thing. Thankfully, it failed...

You want to run fsck -f /dev/mapper/ubuntu-root. You can add in -c if you want. You'll also want to check smartctl -a /dev/sda to see if the disk is indicating either SMART failure (backup, replace disk immediately) or pending sectors (try -c).

If that gives an error along the lines of "not found", you need to start LVM first. You'd do something like this:

# vgscan 
# vgchange -ay

then try the fsck above again.

(You can tell that sda1 is wrong because gdisk and parted both say its 200MB. Also, that its FAT32, not EXT4. You can tell the LVM stuff because the 1T partition is listed as LVM. You ignore fdisk because, well, it told you that it doesn't support GPT).

edit: Another approach, since your system does boot, is to just run shutdown -F -r now, which will cause your machine to do a reboot and do a full fsck. It won't do fsck -c, though. Also, you can safely run smartctl -a on the disk you're booted from.

Solution 2

You haven't mentioned what you intend to accomplish. Do you need to save important data from that disk, or do you just want to find out if it's broken?

I think my WD 1T hard drive has some errors that needed to be fixed.

This is a contradiction in terms. There are two possible scenarios here:

1) Your hard drive has errors (i.e. it is failing). You should then try to save your data as soon as possibly, preferably by imaging the disk to another hard disk with dd. "Fixing" the hard disk is impossible. When you have successfully saved your data you can throw it away.

2) Your filesystem has errors (i.e. is inconsistent in some way), but the disk itself is not damaged. This is something that you can usually fix with e2fsck, though it can't hurt to create a backup image before you try to fsck the filesystem, because in some cases fsck can make it worse.


If you just want to figure out if your hard disk is damaged, run a SMART selftest on it. As root, execute the following command:

smartctl -t long /dev/sda

This will take several hours. When it's completed, you can query the result with

smartctl -a /dev/sda | less

Scroll down to the SMART Selective self-test log block. If the topmost result says Completed without error, your hard disk is fine. If it reports an error, it is damaged and you need to save your data as soon as possible.

Share:
7,005

Related videos on Youtube

Fashandge
Author by

Fashandge

Updated on September 18, 2022

Comments

  • Fashandge
    Fashandge over 1 year

    Problem:

    Since about one week ago, my Ubuntu system encounters various severe and strange problems. Sometimes the whole system suddenly freezes. I have to push the power button to shut down the machine by brute force. Sometimes, all files suddenly become read-only. I have to reboot the machine, and then it seems normal, but might have the above problems later. When I am trying to shut down Ubuntu, sometimes a black screen shows message about disk error.


    Attempts to Fix:

    I think my WD 1T hard drive has some errors that needed to be fixed. So I run the following commands in Ubuntu installation disc or Ubuntu in another hard drive, after unload the hard drive in problem. However, I cannot fix the problem. In particular, when I try to run sudo e2fsck -b 8193 /dev/sda1, there is error message saying "invalid argument". The details are as follows,

    1) first of all, fdisk -l shows the following message (copy only the part relevant to /dev/sda1 I am trying to fix):

    WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.
    
    Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
    255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0x00000000
    Device Boot      Start         End      Blocks   Id  System
    /dev/sda1              1    1953525167   976762583+  ee  GPT
    Partition 1 does not start on physical sector boundary.
    

    2) run sudo fsck.ext4 -ck /dev/sda1, trying to fix the hard drive

    e2fsck 1.42.5 (29-Jul-2012)
    ext2fs_open2: Bad magic number in super-block
    fsck.ext4: Superblock invalid, trying backup blocks...
    fsck.ext4: Bad magic number in super-block while trying to open /dev/sda1
    The superblock could not be read or does not describe a correct ext2
    filesystem.  If the device is valid and it really contains an ext2
    filesystem (and not swap or ufs or something else), then the superblock
    is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 
    

    3) sudo e2fsck -b 8193 /dev/sda1, trying to recover super block from block 8193

    e2fsck 1.42.5 (29-Jul-2012) e2fsck: Invalid argument while trying to
    open /dev/sda1
    
    The superblock could not be read or does not describe a correct ext2
    filesystem.  If the device is valid and it really contains an ext2
    filesystem (and not swap or ufs or something else), then the
    superblock is corrupt, and you might try running e2fsck with an
    alternate superblock:
        e2fsck -b 8193 
    

    4) sudo mke2fs -n /dev/sda1, to locate other backup blocks

    mke2fs 1.42.5 (29-Jul-2012)
    Filesystem label=
    OS type: Linux
    Block size=1024 (log=0)
    Fragment size=1024 (log=0)
    Stride=4 blocks, Stripe width=4 blocks
    48768 inodes, 194560 blocks
    9728 blocks (5.00%) reserved for the super user
    First data block=1
    Maximum filesystem blocks=67371008
    24 block groups
    8192 blocks per group, 8192 fragments per group
    2032 inodes per group
    Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729
    

    5) redo step 3 for all other superblock backups returned in 4. The same error is shown as step 3.

    PS: according to comments, I paste the output of gdisk and parted as follows:

    sudo gdisk -l /dev/sda
    
    GPT fdisk (gdisk) version 0.8.5
    
    Partition table scan:
      MBR: protective
      BSD: not present
      APM: not present
      GPT: present
    
    Found valid GPT with protective MBR; using GPT.
    Disk /dev/sda: 1953525168 sectors, 931.5 GiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 6166B96C-AD2A-4EF1-8967-1ACFA23FE2E4
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 1953525134
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 3437 sectors (1.7 MiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048          391167   190.0 MiB   EF00  
       2          391168          890879   244.0 MiB   0700  
       3          890880      1953523711   931.1 GiB   8E00  
    
    `sudo parted -l `
    
    Model: ATA WDC WD10EZEX-00R (scsi) (note: this is the disk in problem)
    Disk /dev/sda: 1000GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    
    Number  Start   End     Size    File system  Name  Flags
     1      1049kB  200MB   199MB   fat32              boot
     2      200MB   456MB   256MB   ext2
     3      456MB   1000GB  1000GB                     lvm
    
    
    Model: ATA SAMSUNG HD103SJ (scsi)  (note: this is another normal disk)
    Disk /dev/sdb: 1000GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start   End     Size    Type      File system     Flags
     1      1049kB  30.0GB  30.0GB  primary   ext4
     4      30.0GB  1000GB  970GB   extended                  lba
     6      30.0GB  983GB   953GB   logical   ext4
     5      983GB   1000GB  16.9GB  logical   linux-swap(v1)
    
    
    Model: Linux device-mapper (linear) (dm)
    Disk /dev/mapper/ubuntu-root: 983GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: loop
    
    Number  Start  End    Size   File system  Flags
     1      0.00B  983GB  983GB  ext4
    
    
    Model: Linux device-mapper (linear) (dm)
    Disk /dev/mapper/ubuntu-swap_1: 16.9GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: loop
    
    Number  Start  End     Size    File system     Flags
     1      0.00B  16.9GB  16.9GB  linux-swap(v1)
    
  • derobert
    derobert over 10 years
    Self-test will fail if there is a pending sector (at least, on disks I've used). That happens pretty frequently on SATA disks, and doesn't mean the disk is about to die.
  • Fashandge
    Fashandge over 10 years
    I guess there is some problem with the partition or file system. I think the disk can be fixed. I want to fix the disk without losing the data.