Saturday 28 January 2017

How to determine architecture on Linux

How to determine whether a given Linux is 32 bit or 64 bit?We can say system is 32-bit or 64-bit but there are actually three things that have to be observed separately:

  • CPU (processor) - can have 32-bit or 64-bit instruction set (it can support 32-bit or 64-bit kernel)
  • kernel (OS) - can be 32-bit or 64-bit
  • applications - can be 32-bit and 64-bit

Here is a list of some commands with output containing information on the system architecture.

arch



$ man arch

...
arch - print machine hardware name (same as uname -m)
...



Output example:


$ arch
x86_64



uname



$ man uname

...
NAME
uname - print system information

SYNOPSIS
uname [OPTION]...

DESCRIPTION
Print certain system information. With no OPTION, same as -s.
-a, --all

print all information, in the following order, except omit -p and -i if unknown:

-s, --kernel-name
print the kernel name

-n, --nodename
print the network node hostname

-r, --kernel-release
print the kernel release

-v, --kernel-version
print the kernel version

-m, --machine
print the machine hardware name

-p, --processor
print the processor type (non-portable)

-i, --hardware-platform
print the hardware platform (non-portable)

-o, --operating-system
print the operating system

--help display this help and exit

--version
output version information and exit
...



Output example:


$ uname -a
Linux bojan-IdeaCentre-K430 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

$ uname -m
x86_64



Instead of x86_64, 32-bit systems would return i686 or i386.

uname -p tells architecture supported by the processor and uname -m which kernel is loaded (kernel name).

/proc/cpuinfo


CPU info file also contains useful info:


$ cat /proc/cpuinfo

...
processor : 7
vendor_id : GenuineIntel
cpu family : 6
model : 58
model name : Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
stepping : 9
microcode : 0x15
cpu MHz : 1749.273
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 7
initial apicid : 7
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts
bugs :
bogomips : 6784.27
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:



We can observe flags section separately:


$ grep flags /proc/cpuinfo

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts



The flags of interest are:

  • lm - means Long mode cpu - 64 bit CPU
  • tm - means Protected mode - 32-bit CPU
  • rm - means Real Mode - 16 bit CPU

lshw


lshw tool extracts detailed information on the hardware configuration of the machine. CPU info can be obtained from its output:


$ sudo lshw -class cpu
[sudo] password for xxx:
*-cpu
description: CPU
product: Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
vendor: Intel Corp.
physical id: 10
bus info: cpu@0
version: Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
slot: SOCKET 0
size: 1708MHz
capacity: 3900MHz
width: 64 bits
clock: 100MHz
capabilities: x86-64 fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts cpufreq
configuration: cores=4 enabledcores=4 threads=8

/lib/systemd/systemd


We can also query the type of the systemd file (user space bootstrapper):


$ file /sbin/init
/sbin/init: symbolic link to /lib/systemd/systemd

$ file /lib/systemd/systemd
/lib/systemd/systemd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=5d0c9b0db7931b487a8edd5faf4d5258d56e0abc, stripped

HOSTTYPE


HOSTTYPE environmental variable can also be used:


$ echo $HOSTTYPE
x86_64



References:

What do the flags in /proc/cpuinfo mean?
How to determine whether a given Linux is 32 bit or 64 bit?
How to determine Linux kernel architecture?


No comments: