linux – Unable to format micro SD card after using Raspberry Pi OS “Expand filesystem”

I’m having trouble formatting my 16GB micro SD card after using it with Raspberry Pi OS. I installed Raspberry Pi OS Lite on the micro SD card for Pi Zero 2 W. After installation I boot up Pi Zero 2 W with this card on abd used “Expand filesystem” option in raspi-config to use full 16GB. However, now I am trying to format the card because I want to resintall the OS, but it fails.

I have tried fdisk, parted, etc but no success. See below complete logs.

$ lsblk | grep -B 3 disk
loop27        7:27   0 226.3M  1 loop /snap/thunderbird/915
loop28        7:28   0 321.1M  1 loop /snap/vlc/3777
loop29        7:29   0 226.4M  1 loop /snap/thunderbird/919
sda           8:0    0   1.8T  0 disk 
└─sda1        8:1    0   1.8T  0 part /media/hdd
sdb           8:16   1  14.7G  0 disk 
├─sdb1        8:17   1   512M  0 part /media/pi/bootfs
└─sdb2        8:18   1  14.2G  0 part /media/pi/rootfs
nvme0n1     259:0    0 465.8G  0 disk 

$ sudo umount /dev/sdb1
$ sudo umount /dev/sdb2

$ sudo dd if=/dev/zero of=/dev/sdb bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0290349 s, 36.1 MB/s

$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): o
Created a new DOS (MBR) disklabel with disk identifier 0x358597cd.
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-30898175, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-30898175, default 30898175): 
Created a new partition 1 of type 'Linux' and of size 14.7 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

$ sudo mkfs.vfat -F 32 /dev/sdb1
mkfs.fat 4.2 (2021-01-31)

$ sudo dd if=/dev/zero of=/dev/sdb bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.285302 s, 36.8 MB/s

$ sudo parted /dev/sdb mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be
lost. Do you want to continue?
Yes/No? Yes                                                               
Information: You may need to update /etc/fstab.

$ sudo parted /dev/sdb mkpart primary fat32 0% 100%  
Warning: You requested a partition from 0.00B to 15.8GB (sectors 0..30898175).
The closest location we can manage is 512B to 8388kB (sectors 1..16383).
Is this still acceptable to you?
Yes/No? Yes                                                               
Warning: The resulting partition is not properly aligned for best performance: 1s % 2048s != 0s
Ignore/Cancel? Ignore                                                     
Information: You may need to update /etc/fstab.

$ sudo mkfs.vfat -F 32 /dev/sdb1                     
mkfs.fat 4.2 (2021-01-31)

$ lsblk | grep -B 3 disk
loop27        7:27   0 226.3M  1 loop /snap/thunderbird/915
loop28        7:28   0 321.1M  1 loop /snap/vlc/3777
loop29        7:29   0 226.4M  1 loop /snap/thunderbird/919
sda           8:0    0   1.8T  0 disk 
└─sda1        8:1    0   1.8T  0 part /media/hdd
sdb           8:16   1  14.7G  0 disk 
├─sdb1        8:17   1   512M  0 part 
└─sdb2        8:18   1  14.2G  0 part 
nvme0n1     259:0    0 465.8G  0 disk 

All of the above commands are performed on Ubuntu 24.04.3 LTS with 6.14.0-37-generic kernel.

Read more here: Source link