ikluft / piflash

Write ("flash") a Raspberry Pi boot image to an SD card, with features for power users (auto-unwrap archive files) or newbies (safety checks to avoid erasing wrong device)
Apache License 2.0
10 stars 1 forks source link

blkid fails to get fs type #4

Closed mrkskwsnck closed 1 year ago

mrkskwsnck commented 4 years ago

I installed PiFlash v.0.4.3 via cpan inside my home folder on my Ubuntu 18.04 system. When I try to flash an zipped image to a blank SD Card, blkid fails to get the fs type, like that:

$ piflash ./2019-09-26-raspbian-buster-lite.zip /dev/sdg
requested to flash ./2019-09-26-raspbian-buster-lite.zip to /dev/sdg
output device /dev/sdg will be erased
input file is a Zip archive data, at least v2.0 to extract
error: use blkid to get fs type for /dev/sdg command exited with value 2 at /home/[redacted]/perl5/lib/perl5/PiFlash/Command.pm line 193.

What did I get wrong? As far as I debugged it myself, the problem might be the following command:

$ /usr/bin/sudo /sbin/blkid --probe --output=value --match-tag=TYPE /dev/sdg; echo $?
2

I don't know, what the return code 2 means. However, below is my verbose output:

fork_exec running: unzip - list contents /usr/bin/unzip -l 2019-09-26-raspbian-buster-lite.zip
PiFlash::Hook dispatch: no such hook cli_options - ignored
requested to flash 2019-09-26-raspbian-buster-lite.zip to /dev/sdg
output device /dev/sdg will be erased
input file is a Zip archive data, at least v2.0 to extract
fork_exec running: lsblk lookup of MOUNTPOINT /bin/lsblk --bytes --nodeps --noheadings --output MOUNTPOINT /dev/sdg
fork_exec running: lsblk lookup of FSTYPE /bin/lsblk --bytes --nodeps --noheadings --output FSTYPE /dev/sdg
fork_exec running: lsblk lookup of SIZE /bin/lsblk --bytes --nodeps --noheadings --output SIZE /dev/sdg
fork_exec running: lsblk lookup of SUBSYSTEMS /bin/lsblk --bytes --nodeps --noheadings --output SUBSYSTEMS /dev/sdg
fork_exec running: lsblk lookup of TYPE /bin/lsblk --bytes --nodeps --noheadings --output TYPE /dev/sdg
fork_exec running: lsblk lookup of MODEL /bin/lsblk --bytes --nodeps --noheadings --output MODEL /dev/sdg
fork_exec running: lsblk lookup of RO /bin/lsblk --bytes --nodeps --noheadings --output RO /dev/sdg
fork_exec running: lsblk lookup of RM /bin/lsblk --bytes --nodeps --noheadings --output RM /dev/sdg
fork_exec running: lsblk lookup of HOTPLUG /bin/lsblk --bytes --nodeps --noheadings --output HOTPLUG /dev/sdg
fork_exec running: lsblk lookup of PHY-SEC /bin/lsblk --bytes --nodeps --noheadings --output PHY-SEC /dev/sdg
fork_exec running: use lsblk to get fs type for /dev/sdg /usr/bin/sudo /bin/lsblk --nodeps --noheadings --output FSTYPE /dev/sdg
fork_exec running: use blkid to get fs type for /dev/sdg /usr/bin/sudo /sbin/blkid --probe --output=value --match-tag=TYPE /dev/sdg
error: use blkid to get fs type for /dev/sdg command exited with value 2
Program state dump...
cli_opt:
    verbose: 1
config:
hook:
input:
    imgfile: 2019-09-26-raspbian-buster-lite.img
    info:
        description: Zip archive data, at least v2.0 to extract
        encoding: binary
        mime_type: application/zip
        mime_with_encoding: application/zip; charset=binary
    parse:
        name: 2019-09-26-raspbian-buster-lite
        path: ./
        suffix: .zip
    path: 2019-09-26-raspbian-buster-lite.zip
    size: 2248146944
    type: zip
log:
    cmd:
            cmdline:
                /usr/bin/unzip
                -l
                2019-09-26-raspbian-buster-lite.zip
            cmdname: unzip - list contents
            err: undef
            out: Archive:  2019-09-26-raspbian-buster-lite.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
2248146944  2019-09-26 02:24   2019-09-26-raspbian-buster-lite.img
---------                     -------
2248146944                     1 file

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                MOUNTPOINT
                /dev/sdg
            cmdname: lsblk lookup of MOUNTPOINT
            err: undef
            out: 

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                FSTYPE
                /dev/sdg
            cmdname: lsblk lookup of FSTYPE
            err: undef
            out: 

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                SIZE
                /dev/sdg
            cmdname: lsblk lookup of SIZE
            err: undef
            out: 3965190144

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                SUBSYSTEMS
                /dev/sdg
            cmdname: lsblk lookup of SUBSYSTEMS
            err: undef
            out: block:scsi:usb:pci

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                TYPE
                /dev/sdg
            cmdname: lsblk lookup of TYPE
            err: undef
            out: disk

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                MODEL
                /dev/sdg
            cmdname: lsblk lookup of MODEL
            err: undef
            out: WorkflowSR2     

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                RO
                /dev/sdg
            cmdname: lsblk lookup of RO
            err: undef
            out:  0

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                RM
                /dev/sdg
            cmdname: lsblk lookup of RM
            err: undef
            out:  1

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                HOTPLUG
                /dev/sdg
            cmdname: lsblk lookup of HOTPLUG
            err: undef
            out:       1

            returncode: 0
            cmdline:
                /bin/lsblk
                --bytes
                --nodeps
                --noheadings
                --output
                PHY-SEC
                /dev/sdg
            cmdname: lsblk lookup of PHY-SEC
            err: undef
            out:     512

            returncode: 0
            cmdline:
                /usr/bin/sudo
                /bin/lsblk
                --nodeps
                --noheadings
                --output
                FSTYPE
                /dev/sdg
            cmdname: use lsblk to get fs type for /dev/sdg
            err: undef
            out: 

            returncode: 0
            cmdline:
                /usr/bin/sudo
                /sbin/blkid
                --probe
                --output=value
                --match-tag=TYPE
                /dev/sdg
            cmdname: use blkid to get fs type for /dev/sdg
            err: undef
            out: undef
            returncode: 2
output:
    fstype: 
    hotplug: 1
    model: WorkflowSR2
    mountpoint: 
    path: /dev/sdg
    phy-sec: 512
    rm: 1
    ro: 0
    size: 3965190144
    subsystems: block:scsi:usb:pci
    type: disk
plugin:
system:
    filesystems:
        vfat
        ext4
        ext3
        ext2
        squashfs
        fuseblk
    machine: x86_64
    media_dir: /media
    nodename: [redacted]
    PATH: /sbin:/usr/sbin:/bin:/usr/bin
    primary_fs: vfat
    prog:
        blkid: /sbin/blkid
        lsblk: /bin/lsblk
        sudo: /usr/bin/sudo
        unzip: /usr/bin/unzip
    release: 5.0.0-32-generic
    sysname: Linux
    version: #34~18.04.2-Ubuntu SMP Thu Oct 10 10:36:02 UTC 2019
 at /home/[redacted]/perl5/lib/perl5/PiFlash/Command.pm line 193.

I'm looking forward to get this mystery solved :-)

mrkskwsnck commented 4 years ago

In the meanwhile I discovered the fact, that PiFlash needs the SD Card to have at least a partition table (sometimes called disk label) present. That's why blkid script fails to get the fs type.

ikluft commented 1 year ago

The fix will go into PiFlash 0.5.0.

I found what was causing this when I tripped over it myself and was finally able to duplicate the error. It only occurred when flashing a blank media without any kind of filesystem. We knew the blkid command was returning an error. Now we know why. But it should not have been a fatal error. A try-catch-block was placed around it to catch the exception and continue to the next fallback method of determining the filesystem type. This code to check the output device before writing is necessary to catch and prevent an accidental formatting of a user data drive instead of an SD card.

mrkskwsnck commented 1 year ago

That's great news, indeed. When do you plan to make v0.5.0 public?

ikluft commented 1 year ago

I was planning to post it soon after that. Tests on a RasPi 4 didn't make a bootable SD. That will need to be solved first.