99

I'm trying to write a script which will determine actions based on the architecture of the machine. I already use uname -m to gather the architecture line, however I do not know how many ARM architectures there are, nor do I know whether one is armhf, armel, or arm64.

As this is required for this script to determine whether portions of the script can be run or not, I am trying to find a simple way to determine if the architecture is armhf, armel or arm64. Is there any one-liner or simple command that can be used to output either armhf, armel, or arm64?

The script is specifically written for Debian and Ubuntu systems, and I am tagging as such with this in mind (it quits automatically if you aren't on one of those distros, but this could be applied in a much wider way as well if the command(s) exist)


EDIT: Recently learned that armel is dead, and arm64 software builders (PPA or virtual based) aren't the most stable. So I have a wildcard search finding arm* and assuming armhf, but it's still necessary to figure out a one liner that returns one of the three - whether it's a Ubuntu/Debian command or a kernel call or something.

1
  • 1
    Why do you say that "armel is dead" ?
    – Grodriguez
    May 16, 2016 at 9:25

2 Answers 2

200

On Debian and derivatives,

dpkg --print-architecture

will output the primary architecture of the machine it’s run on. This will be armhf on a machine running 32-bit ARM Debian or Ubuntu (or a derivative), arm64 on a machine running 64-bit ARM.

On RPM-based systems,

rpm --eval '%{_arch}'

will output the current architecture name (which may be influenced by other parameters, e.g. --target).

Note that the running architecture may be different from the hardware architecture or even the kernel architecture. It’s possible to run i386 Debian on a 64-bit Intel or AMD CPU, and I believe it’s possible to run armhf on a 64-bit ARM CPU. It’s also possible to have mostly i386 binaries (so the primary architecture is i386) on an amd64 kernel, or even binaries from an entirely different architecture if it’s supported by QEMU (a common use for this is debootstrap chroots used for cross-compiling).

0
7

In case dpkg is not installed in your system (for example in lean docker container), this command will helps you

$ arch
1
  • In the context of this specific question, the output of arch needs some translation — for example on ARMv8 it outputs aarch64, which corresponds to Debian’s arm64 architecture. May 5 at 7:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .