is my linux ARM 32 or 64 bit?

240,813

Solution 1

There are several gradations, since you can run a 32-bit or mixed operating system on a 64-bit-capable CPU. See 64-bit kernel, but all 32-bit ELF executable running processes, how is this? for a detailed discussion (written for x86, but most of it applies to arm as well).

You can find the processor model in /proc/cpuinfo. For example:

$ cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 10 (v7l)

ARMv7 (and below) is 32-bit. ARMv8 introduces the 64-bit instruction set.

If you want to see whether your system supports 64-bit binaries, check the kernel architecture:

$ uname -m
armv7l

On a 64-bit processor, you'd see a string starting with armv8 (or above) if the uname process itself is a 32-bit process, or aarch64 if it's a 64-bit process. (See also https://stackoverflow.com/questions/45125516/possible-values-for-uname-m)

Solution 2

As richard points out, armv7 variants are all 32-bit, so there is no redundant label armv7-32, etc.

On a linux system, you can easily, although not truly definitively, check by examining a common executable:

> which bash
/bin/bash
> file /bin/bash
/bin/bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV) ...

I say "not definitively" because it is possible to run 32-bit executables on a 64-bit system.

There does not appear to be anything foolproof in /proc or /sys; the output from /proc/cpuinfo may provide some significant clues. If for some reason you need an automated check, creating a table mapped to the "model name" field seems like one potentially sound method (other fields, including "model", "cpu family", etc. look optional -- they don't appear at all for me on a Broadcom 2708 ARMv6 processor).

Solution 3

Install the 'lshw' package.

# lshw
...
    description: Computer
    product: Raspberry Pi 3 Model B Rev 1.2
    width: 32 bits
...

Solution 4

Seems like most ways to see bit count is to somehow know that arm7=32 bit and while that may be true but what about

pi@rpi9:~ $ getconf LONG_BIT
32

And if you want to look for the cpu model I normally use arch

root@rpi4:~# tr '\0' '\n' </proc/device-tree/model;arch
Raspberry Pi Model B Rev 2
armv6l

pi@rpi9:~ $ tr '\0' '\n' </proc/device-tree/model;arch
Raspberry Pi 3 Model B Rev 1.2
armv7l

Solution 5

Try the following.

// -*- compile-command: "gcc -Wall -o sizeof sizeof.c && ./sizeof" -*-

#include <stdio.h>
#include <limits.h>

#define size(t) { t x; printf("%s:\t%3lu bit\n", #t, CHAR_BIT * sizeof x); }

int main (int argc, char *argv[])
{
  size(char);
  size(short);
  size(int);
  size(long);
  size(void*);
  return 0;
}

The address size is void*.

Share:
240,813

Related videos on Youtube

Chris Maes
Author by

Chris Maes

I am an image processing engineer who evolved to Devops. I used to work with C, C++, some OpenCV and even some SSE / Neon. Now I'm having fun automating things, striving for continuous integration, rewriting git history, and trying to make Jenkins, Jira, Bitbucket, Sonarqube, Nexus, docker, ... work together. My favourite personal posts: https://stackoverflow.com/a/54363151/2082964 https://stackoverflow.com/a/34764586/2082964

Updated on September 18, 2022

Comments

  • Chris Maes
    Chris Maes over 1 year

    under an intel I know I can look at the outcome of uname -m to know if my OS is 32 or 64 bit, but under ARM this gives:

    armv7l
    

    I deduced from

    file /usr/bin/ls
    

    that I'm on a 32-bit OS, but how can I know this in an easier way?

    • Admin
      Admin almost 10 years
      arm 7 is 32 bit. ARMv8-A architecture, announced in October 2011,[6] adds support for a 64-bit address space and 64-bit arithmetic. — wikipedia
    • Admin
      Admin almost 10 years
      @richard I was guessing so, but then what is the name of the 64-bit variant?
    • Admin
      Admin almost 10 years
      I don't have access to an ARM machine but what is the output of uname -a and gcc -v? Those might be helpful.
    • Admin
      Admin almost 10 years
      Announced October 2011, ARMv8-A (often called ARMv8 although not all variants are 64-bit such as ARMv8-R) represents a fundamental change to the ARM architecture. It adds a 64-bit architecture, named "AArch64", and a new "A64" instruction set. AArch64 provides user-space compatibility with ARMv7-A ISA, the 32-bit architecture, therein referred to as "AArch32" and the old 32-bit instruction set, now named "A32" ARM announced their Cortex-A53 and Cortex-A57 cores on 30 October 2012.en.wikipedia.org/wiki/ARM_architecture#64.2F32-bit_architect‌​ure
    • Admin
      Admin almost 10 years
      Arm was the last of the 32bit cpu to go 64bit (excluding those that died). Most went 64bit and then died, because of poor marketing — assuming that being better is enough. The Intel x86 was the second to last, though it was AMD that added 64 bit.
    • Admin
      Admin over 8 years
    • Admin
      Admin almost 7 years
    • Admin
      Admin almost 7 years
      Also, 'getconf LONG_BIT' will spit out the # bits of the OS (not necessarily the processor)
    • Admin
      Admin over 4 years
      uname -m will show aarch64, therefore anything different than that on a arm processor is 32.
  • pmv
    pmv over 9 years
    I don't contest your answer, but unfortunately android IS A LINUX, so, there suppose to be some command, SOMEWHERE that show it locally and not to read a documentation on some page
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 9 years
    @THESorcerer Android uses a Linux kernel but it is not a Linux system. It does not have Linux user land tools (only a very small subset). On Android, I think 64-bit support is consistent in the base OS, so cat /proc/$$/maps will let you know whether the system is 64-bit or 32-bit from an adb command line.
  • phuclv
    phuclv about 7 years
    where did you find that the OP's using Allwinner H8? The architecture is armv7l which is clearly not a 64-bit one
  • phuclv
    phuclv about 7 years
    sizeof returns size_t which must be printed out using %zu. Using the wrong format specifier invokes undefined behavior
  • phuclv
    phuclv about 7 years
    and size of void* isn't necessarily the architecture bit width. Have you ever heard of x32 ABI sites.google.com/site/x32abi
  • kaiwan
    kaiwan almost 7 years
    Similarly, getconf -a|grep LONG_BIT
  • bakalolo
    bakalolo almost 7 years
    So armv7l is 32 bit right?
  • goldilocks
    goldilocks almost 7 years
    @bakalolo Read the question and the accepted answer slowly ;)
  • Sathish
    Sathish almost 7 years
    I believe Raspberry Pi 3, which is ARMv8 (CRC, no optional Crypto) will report armv7l even though its ARMv8. So I'm pretty sure the wrong CPU will be reported.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 7 years
    @jww If it reports armv7l, it means you're running a 32-bit kernel. You can run a 32-bit kernel on a 64-bit CPU. If you want information about the CPU, read /proc/cpuinfo.
  • rsethc
    rsethc over 6 years
    This doesn't tell you about anything other than the nature of your compiler.
  • xercool
    xercool over 4 years
    uname -m just returns "aarch64". /proc/cpuinfo doesn't always contain a name for a processor either.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 4 years
    @Halsafar If uname -m returns aarch64, it means you're running a 64-bit kernel.
  • Synetech
    Synetech over 4 years
    It's better to demonstrate a way to find the desired information from within the system instead of using third-party information from external sources. This is better suited to be a comment than an answer (hence all the down-votes).
  • Abdulkarim Kanaan
    Abdulkarim Kanaan over 4 years
    getconf LONG_BIT is very straightforward
  • legends2k
    legends2k over 2 years
    This should be the selected answer; getconf is a POSIX command and it works on Linux, macOS and BSD.
  • milia
    milia about 2 years
    Great answer; using bash to see if the CPU architecture it's 32-bit or 64-bit :). A bit counter-intuitive, but I love it. Thanks !