1

I Installed ubuntu (20.04 LTS ARM64) preinstalled image on to a SD card. I had a few issues at this stage leading me to keep reinstalling the OS and try again, one particular issue ended with EXT4-FS error, this then began reoccurring every time I flashed the SD card (does this signal an issue with my SD card?) I decided to fix that:

# e2fsck -f /dev/sda2
e2fsck 1.45.5 (07-Jan-2020)
writable: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Entry 'src' in /usr (1528) has deleted/unused inode 44502.  Clear<y>? yes
Entry 'coreutils' in /usr/lib/aarch64-linux-gnu (2459) has deleted/unused inode 2465.  Clear<y>? yes
Entry 'device-mapper' in /usr/lib/aarch64-linux-gnu (2459) has deleted/unused inode 2467.  Clear<y>? yes

I then wanted to shrink the root ext4 volume, understanding this needs to be offline I plugged this in via USB adapter to a second machine. I followed a series of online guides here & on a linux wiki and have documented my steps below. clearly I went wrong, what should the proper order / method have been? listing my SD card on current machine and the SD card in the USB adapter showing as sda

   # lsblk
    sda           8:0    1 59.7G  0 disk 
    ├─sda1        8:1    1  256M  0 part 
    └─sda2        8:2    1 59.4G  0 part 
    mmcblk0     179:0    0  3.7G  0 disk 
    ├─mmcblk0p1 179:1    0  256M  0 part /boot/firmware
    └─mmcblk0p2 179:2    0  3.5G  0 part /

One guide recommended deleting the partition using Parted and rebuilding it before resizing.

# parted /dev/sda
(parted) unit chs 
(parted) print  
Model: Generic Mass-Storage (scsi)
Disk /dev/sda: 61070,63,31
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 61071,64,32.  Each cylinder is 1049kB.
Partition Table: msdos
Disk Flags: 
Number  Start    End          Type     File system  Flags
 1      1,0,0    256,63,31    primary  fat32        boot, lba
 2      257,0,0  61070,62,30  primary  ext4

(parted) rm 2 (parted) mkpart primary 257,0,0 40590,62,30 (parted) mkpart primary fat32 40591,0,0 61070,62,30 (parted) print
Model: Generic Mass-Storage (scsi) Disk /dev/sda: 61070,63,31 Sector size (logical/physical): 512B/512B BIOS cylinder,head,sector geometry: 61071,64,32. Each cylinder is 1049kB. Partition Table: msdos Disk Flags:

Number Start End Type File system Flags 1 1,0,0 256,63,31 primary fat32 boot, lba 2 257,0,0 40590,62,30 primary lba 3 40591,0,0 61070,62,30 primary fat32 lba

List disk shows that this was successful -or so I thought...

# lsblk
sda           8:0    1 59.7G  0 disk 
├─sda1        8:1    1  256M  0 part 
├─sda2        8:2    1 39.4G  0 part 
└─sda3        8:3    1   20G  0 part 
mmcblk0     179:0    0  3.7G  0 disk 
├─mmcblk0p1 179:1    0  256M  0 part /boot/firmware
└─mmcblk0p2 179:2    0  3.5G  0 part /

I ran the recheck and found errors:

e2fsck -f /dev/sda2
e2fsck 1.45.5 (07-Jan-2020)
The filesystem size (according to the superblock) is 15568379 blocks
The physical size of the device is 10325499 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? no
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
Error reading block 10485760 (Invalid argument) while reading inode and block bitmaps.  Ignore error<y>? yes
...
writable: ***** FILE SYSTEM WAS MODIFIED *****
writable: 21160/3777536 files (0.2% non-contiguous), 562061/15568379 blocks

I think about here I switch guide to use Fdisk

# fdisk /dev/sda
: p
Disk /dev/sda: 59.66 GiB, 64037584896 bytes, 125073408 sectors
Disk model: Mass-Storage    
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: 0x4ec8ea53

Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 526335 524288 256M c W95 FAT32 (LBA) /dev/sda2 526336 83130334 82603999 39.4G 83 Linux /dev/sda3 83130368 125073374 41943007 20G c W95 FAT32 (LBA)

For some reason I switched back to parted to delete the partition

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1  *        2048    526335   524288  256M  c W95 FAT32 (LBA)
/dev/sda3       83130368 125073374 41943007   20G  c W95 FAT32 (LBA)

Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (2,4, default 2): 2 First sector (526336-125073407, default 526336): Last sector, +/-sectors or +/-size{K,M,G,T,P} (526336-125073407, default 125073407): 83130367

Created a new partition 2 of type 'Linux' and of size 39.4 GiB. Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: y Filesystem/RAID signature on partition 2 will be wiped.

Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.

e2fsck -fy /dev/sda2

e2fsck 1.45.5 (07-Jan-2020) ext2fs_open2: Bad magic number in super-block e2fsck: Superblock invalid, trying backup blocks... writable: recovering journal e2fsck: unable to set superblock flags on writable

writable: ***** FILE SYSTEM WAS MODIFIED *****

writable: ********** WARNING: Filesystem still has errors **********

and so, here I am now having completely ruined my install.

so I suppose it would be good to have 2 solutions: 1.How to erase and reset the sd card to a working configuration? 2.How to shrink a EXT4 partition with the OS and /root already on it (offline)

mike
  • 11
  • If i need to make changes to a system on a sdcard (for a pi etc), I usually copy the data over to another sdcard and change it during the copy. I don't see the sdcards as ultra-reliable (compared to say a ssd/hdd) being sold primarily on cost. If the card is destroyed (they have no diagnostics), you cannot reset it (it's seen generally as a consumable device; no diagnostics are built into it unlike ssd/hdd). They are devices where the replacement cost is far less than spending time correcting it... – guiverc Mar 04 '21 at 03:03

0 Answers0