Sunday, September 16, 2018

Failed attempt to rebuild raspberry pi filesystem (ext4)

My raspberry pi failed to boot, and I tracked it down to being a damaged main linux partition.  I tried to repair the partition, but it didn't work.  This posts lists some of the things I tried for posterity.


  • attached to other raspberry pi running raspbian
  • was able to mount the boot partition
  • was unable to moun the main partition
  • was able to copy the main partition using dd
    • command:  
      nohup sudo dd bs=4M if=/dev/sdc2 of=raid0/cape/2018-09-03_piB_main_partition.img conv=fsync &
    • output:
      3795+0 records in
      3795+0 records out
      15917383680 bytes (16 GB, 15 GiB) copied, 3292.09 s, 4.8 MB/s
  • attempted fsck.ext4 on the disk
    • command:  
      sudo fsck.ext4 /dev/sdc2 
    • output:  
      e2fsck 1.43.4 (31-Jan-2017)
      /dev/sdc2: recovering journal
      Superblock needs_recovery flag is clear, but journal has data.
      Run journal anyway<y>? yes
      fsck.ext4: Unknown code ____ 251 while recovering journal of /dev/sdc2
      fsck.ext4: unable to set superblock flags on /dev/sdc2


      /dev/sdc2: ********** WARNING: Filesystem still has errors **********
    • from this stack exchange on unix & linux it appears that the attempts to write to the SD card are failing - probably need a new SD card
  • attempted fsck.ext4 on image of filesystem  (seems possible based on this other StackExchange Unix & Linux)
    • 1st made copy of image
    • then command:  
      sudo fsck.ext4 2018-09-03_piB_main_partition_copy.img 
    • output:  
      e2fsck 1.43.4 (31-Jan-2017)
      2018-09-03_piB_main_partition_copy.img: recovering journal
      fsck.ext4: Bad magic number in super-block while trying to re-open 2018-09-03_piB_main_partition_copy.img

      2018-09-03_piB_main_partition_copy.img: ********** WARNING: Filesystem still has errors **********
  • find backup superblocks & attempt to use to repair:
    • find backup superblocks - command: 
      sudo mke2fs -n 2018-09-03_piB_main_partition_copy02.img 
    • output:  
      mke2fs 1.43.4 (31-Jan-2017)
      2018-09-03_piB_main_partition_copy02.img contains a ext4 file system
      last mounted on / on Mon May 28 19:03:51 2018
      Proceed anyway? (y,N) y
      warning: Unable to get device geometry for 2018-09-03_piB_main_partition_copy02.img
      Creating filesystem with 3886080 4k blocks and 972944 inodes
      Filesystem UUID: 16542ed2-1cc7-45ea-a49c-4d3213eab6a1
      Superblock backups stored on blocks: 
      32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
    • attempt repair using first backup superblock - command:  
      sudo fsck.ext4 -b 32768 2018-09-03_piB_main_partition_copy02.img 
    • output:  
      e2fsck 1.43.4 (31-Jan-2017)
      2018-09-03_piB_main_partition_copy02.img: recovering journal
      fsck.ext4: unable to set superblock flags on 2018-09-03_piB_main_partition_copy02.img


      2018-09-03_piB_main_partition_copy02.img: ***** FILE SYSTEM WAS MODIFIED *****

      2018-09-03_piB_main_partition_copy02.img: ********** WARNING: Filesystem still has errors **********
    • despite the error, was able to then mount, albeit with errors - command:  
      sudo mount 2018-09-03_piB_main_partition_copy02.img ~/temp/
    • output:  
      ls: cannot access '/home/lahr/temp/bin': Structure needs cleaning
      ls: cannot access '/home/lahr/temp/tmp': Structure needs cleaning
      ls: cannot access '/home/lahr/temp/sbin': Structure needs cleaning
      ls: cannot access '/home/lahr/temp/boot': Structure needs cleaning
      ls: cannot access '/home/lahr/temp/home': Structure needs cleaning
      ls: cannot access '/home/lahr/temp/mnt': Structure needs cleaning
      ls: cannot access '/home/lahr/temp/root': Structure needs cleaning
      ls: cannot access '/home/lahr/temp/dev': Structure needs cleaning
      total 60
      d?????????   ? ?    ?        ?            ? bin
      d?????????   ? ?    ?        ?            ? boot
      d?????????   ? ?    ?        ?            ? dev
      drwxr-xr-x 111 root root  4096 Aug 22 18:27 etc
      d?????????   ? ?    ?        ?            ? home
      drwxr-xr-x  12 root root  4096 Oct 24  2017 lib
      drwx------   2 root root 16384 Feb 15  2015 lost+found
      drwxr-xr-x   6 root root  4096 Dec 18  2017 media
      d?????????   ? ?    ?        ?            ? mnt
      drwxr-xr-x   6 root root  4096 Feb 16  2015 opt
      drwxr-xr-x   2 root root  4096 Jan 11  2015 proc
      d?????????   ? ?    ?        ?            ? root
      drwxr-xr-x   7 root root  4096 Feb 16  2015 run
      d?????????   ? ?    ?        ?            ? sbin
      drwxr-xr-x   2 root root  4096 Jun 20  2012 selinux
      -rw-r--r--   1 lahr 1004    16 Nov 27  2017 srv
      drwxr-xr-x   2 root root  4096 Oct 12  2013 sys
      d?????????   ? ?    ?        ?            ? tmp
      drwxr-xr-x  10 root root  4096 Feb 15  2015 usr
      drwxr-xr-x  11 root root  4096 Feb 16  2015 var
    • attempt cleaning with 2nd backup superblock - command:  
    • attempt regular cleaning - command:  sudo fsck.ext4 2018-09-03_piB_main_partition_copy02.img
      • lots of prompts for repairs; eventually chose "all" option
    • still mounted with problems, ran cleaning above, was mounted, reported output:  
e2fsck 1.43.4 (31-Jan-2017)
2018-09-03_piB_main_partition_copy02.img contains a file system with errors, 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
Block bitmap differences:  -41468
Fix? yes
Free blocks count wrong for group #1 (15656, counted=15657).
Fix? yes
Free blocks count wrong (3188435, counted=3069400).
Fix? yes
Free inodes count wrong (887659, counted=869921).
Fix? yes

2018-09-03_piB_main_partition_copy02.img: ***** FILE SYSTEM WAS MODIFIED *****
2018-09-03_piB_main_partition_copy02.img: 103023/972944 files (0.2% non-contiguous), 816680/3886080 blocks
    • further fsck reported filesystem as clean - however, the mounted filesystem is missing /home and other critical directories.

No comments:

Post a Comment