Disk corruption on berry


Symptom


    $ sudo apt-get update
    $ sudo apt-get upgrade
    ...
    Do you want to continue? [Y/n] 
    Get:1 http://archive.raspberrypi.org/debian stretch/main armhf wolframscript armhf 1.3.0+2019062801 [1,248 kB]
    E: Failed to fetch http://archive.raspberrypi.org/debian/pool/main/w/wolframscript/wolframscript_1.3.0+2019062801_armhf.deb  rename failed, Structure needs cleaning (/var/cache/apt/archives/partial/wolframscript_1.3.0+2019062801_armhf.deb -> /var/cache/apt/archives/wolframscript_1.3.0+2019062801_armhf.deb).
    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
    $ sudo apt-get clean
    W: Problem unlinking the file wolframscript_1.3.0+2019062801_armhf.deb - Clean (117: Structure needs cleaning)
    $ sudo rm -rf /var/lib/apt/lists
    $ sudo apt-get update
    $ sudo ls -la /var/cache/apt/archives/
    ls: cannot access '/var/cache/apt/archives/wolframscript_1.3.0+2019062801_armhf.deb': Structure needs cleaning
    total 144
    drwxr-xr-x 3 root root 135168 Aug 17 14:19 .
    drwxr-xr-x 3 root root   4096 Aug 18 08:49 ..
    -rw-r----- 1 root root      0 Jun 20  2014 lock
    drwx------ 2 _apt root   4096 Aug 18 08:45 partial
    -????????? ? ?    ?         ?            ? wolframscript_1.3.0+2019062801_armhf.deb
    $ sudo rm /var/cache/apt/archives/lock 
    $ sudo rm -f /var/cache/apt/archives/wolframscript_1.3.0+2019062801_armhf.deb 
    rm: cannot remove '/var/cache/apt/archives/wolframscript_1.3.0+2019062801_armhf.deb': Structure needs cleaning
    $ df /var/cache
    Filesystem     1K-blocks     Used Available Use% Mounted on
    /dev/root       29359188 16887628  10957116  61% /
    $ cat /etc/fstab
    proc            /proc           proc    defaults          0       0
    /dev/mmcblk0p5  /boot           vfat    defaults          0       2
    /dev/mmcblk0p6  /               ext4    defaults,noatime  0       1
    # a swapfile is not a swap partition, no line here
    #   use  dphys-swapfile swap[on|off]  for that

Single user mode

In order to umount the root file system, I needed to reboot in single user mode
I added to /boot/cmdline.txt to argument: init=/bin/sh and restarted sudo shutdown -r now
Once in single user mode, I mounted:

    # mount /dev/mmcblk0p5 /boot
But fsck.ext4 / fails as it cannot determine whether /dev/mmcblk0p6 is mounted or not (no /etc/mtab, mount returns an error).
In fact, it is mounted, per:

# cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait init=/bin/sh
But that's where I get fsck.ext4:

    public_html> ll /sbin/fsck.ext4 
    lrwxrwxrwx 1 root root 6 Feb  1  2017 /sbin/fsck.ext4 -> e2fsck
    public_html> ldd /sbin/e2fsck 
	/usr/lib/arm-linux-gnueabihf/libarmmem.so (0xb6fac000)
	libext2fs.so.2 => /lib/arm-linux-gnueabihf/libext2fs.so.2 (0xb6f42000)
	libcom_err.so.2 => /lib/arm-linux-gnueabihf/libcom_err.so.2 (0xb6f2f000)
	libblkid.so.1 => /lib/arm-linux-gnueabihf/libblkid.so.1 (0xb6ee2000)
	libuuid.so.1 => /lib/arm-linux-gnueabihf/libuuid.so.1 (0xb6ece000)
	libe2p.so.2 => /lib/arm-linux-gnueabihf/libe2p.so.2 (0xb6eb6000)
	libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6ea3000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6d64000)
	/lib/ld-linux-armhf.so.3 (0xb6fc2000)
	libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6d3b000)
    public_html> df /lib
    Filesystem     1K-blocks     Used Available Use% Mounted on
    /dev/root       29359188 16880772  10963972  61% /

New version: buster

If doing a reinstall, probably I'd rather upgrade to the latest version.
Buy a micro SD card with adapter, of 32G (or more if Raspberry 1B supports).

Actions

Bought an adapter to be able to write to the 32G standard size SD card from the laptop, as well as a new, 32G micro-SD card with adapter, to be able to replace the faulty old card with a new one.

Note that the 1B Raspberry Pi doesn't support larger SD cards, but the 4B would (64G)

Attempted an fdisk on the /root file system from the laptop, but found nothing wrong (!) Note that this was a readonly check, probably as I could not use the berry root account.

Tried again an apt-get update/upgrade (worked) and even dist-upgrade. Extremely slow, but progressing.
Completed OK.

Looking now at the new micro-SD card. Checked that it is correctly preformatted (single partition in FAT32):


public_html> sudo fdisk -l | grep -B1 -A5 /dev/mm

Disk /dev/mmcblk0: 29.1 GiB, 31281119232 bytes, 61095936 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
--
Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       8192 61095935 61087744 29.1G  c W95 FAT32 (LBA)
Although... maybe the LBA is not right.

public_html> sudo fdisk /dev/mmcblk0
...
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): l
...
Hex code (type L to list all codes): b
Changed type of partition 'W95 FAT32 (LBA)' to 'W95 FAT32'.

Command (m for help): p
Disk /dev/mmcblk0: 29.1 GiB, 31281119232 bytes, 61095936 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       8192 61095935 61087744 29.1G  b W95 FAT32

Command (m for help): w
The partition table has been altered.
Synching disks.

public_html> mount | grep -i mmcblk0p1
/dev/mmcblk0p1 on /media/marc/0403-0201 type vfat (rw,nosuid,nodev,relatime,uid=1001,gid=1001,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
public_html> sudo umount /dev/mmcblk0p1 /media/marc/0403-0201
umount: /media/marc/0403-0201: no mount point specified.
public_html> sudo mkfs.vfat /dev/mmcblk0p1
mkfs.fat 4.1 (2017-01-24)
Next, downloaded the NOOBS zip file (3.2.0)

public_html> du -h ~/Downloads/NOOBS_v3_2_0.zip 
2.1G	/home/marc/Downloads/NOOBS_v3_2_0.zip
public_html> sha256sum ~/Downloads/NOOBS_v3_2_0.zip 
d05bd794368ccfb516a9e7116d1c659c3d139f4393ee1f4450900080e877434e  /home/marc/Downloads/NOOBS_v3_2_0.zip
Ejected manually

public_html> mount | grep -i mmcblk0p1
/dev/mmcblk0p1 on /media/marc/746C-3A2D type vfat (rw,nosuid,nodev,relatime,uid=1001,gid=1001,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
public_html> cd /media/marc/746C-3A2D/
746C-3A2D> unzip ~/Downloads/NOOBS_v3_2_0.zip 
746C-3A2D> cd
~> sudo umount /dev/mmcblk0p1
Installed Buster from NOOB.
Now, the old SD card doesn't boot anymore...
Tried to fsck /BOOT and probably broken completely And the new one lacks sshd, and the accounts.
Added sshd and marc account
Missing: Following instructions, I disabled @include common-auth from /etc/pamd/sshd and in /etc/ssh/sshd_config, Plugged in. Checked that I can connect as myself, but as as pi.
Added my keys, and checked that I can login using them.
Added to /etc/ssh/sshd_config: AuthenticationMethods publickey
Marc Girod
Sun Aug 18 11:37:54 2019