Skip to content

Commit

Permalink
Replace xxd with dd for google_nvme_id
Browse files Browse the repository at this point in the history
`google_nvme_id` script currently uses `xxd` to parse nvme device
info, but we need to install additional package `xxd` for fedora,
`vim-common` and `vim-filesystem` for centos (or rhel) before
using it. Replace it with `dd` and we do not need to install
additional packages.

See coreos/fedora-coreos-config#2412 (comment)

We initially tried to replace it with cut, creating a different
result expected.
See: GoogleCloudPlatform#49 Discussing about the use of `dd`vs `cut`.

Tests for Fedora CoreOS:
nvme id-ns -b /dev/nvme0n1 | xxd -p --seek 384 | xxd -p -r | od -x
0000000 227b 6564 6976 6563 6e5f 6d61 2265 223a
0000020 6570 7372 7369 6574 746e 642d 7369 2d6b
0000040 2230 222c 6964 6b73 745f 7079 2265 223a
0000060 4550 5352 5349 4554 544e 7d22 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000
*
0007200

nvme id-ns -b /dev/nvme0n1 | dd bs=1 skip=384 2>/dev/null  | od -x
0000000 227b 6564 6976 6563 6e5f 6d61 2265 223a
0000020 6570 7372 7369 6574 746e 642d 7369 2d6b
0000040 2230 222c 6964 6b73 745f 7079 2265 223a
0000060 4550 5352 5349 4554 544e 7d22 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000
*
0007200

Tests for Debian  12

nvme id-ns -b /dev/nvme0n1 | dd bs=1 skip=384 2>/dev/null  | od -x
0000000 227b 6564 6976 6563 6e5f 6d61 2265 223a
0000020 6f6c 6163 2d6c 766e 656d 732d 6473 312d
0000040 2c22 6422 7369 5f6b 7974 6570 3a22 4c22
0000060 434f 4c41 535f 4453 7d22 0000 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000
*
0007200

nvme id-ns -b /dev/nvme0n1 | dd bs=1 skip=384 2>/dev/null  | od -x
0000000 227b 6564 6976 6563 6e5f 6d61 2265 223a
0000020 6f6c 6163 2d6c 766e 656d 732d 6473 312d
0000040 2c22 6422 7369 5f6b 7974 6570 3a22 4c22
0000060 434f 4c41 535f 4453 7d22 0000 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000
*
0007200

Signed-off-by: Renata Ravanelli <rravanel@redhat.com>
  • Loading branch information
ravanelli committed Jul 27, 2023
1 parent 480f02a commit 1de263e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/udev/google_nvme_id
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function err() {
#######################################
function get_namespace_device_name() {
local nvme_json
nvme_json="$("$nvme_cli_bin" id-ns -b "$1" | xxd -p -seek 384 | xxd -p -r)"
nvme_json="$("$nvme_cli_bin" id-ns -b "$1" | dd bs=1 skip=384 2>/dev/null | od -x)"
if [[ $? -ne 0 ]]; then
return 1
fi
Expand Down

0 comments on commit 1de263e

Please sign in to comment.