The hardware, the kernel and the user space programs may have different word sizes¹.
You can see whether the CPU is 64-bit, 32-bit, or capable of both by checking the flags
line in /proc/cpuinfo
. You have to know the possible flags on your architecture family. For example, on i386/amd64 platforms, the lm
flag identifies amd64-capable CPUs (CPUs that don't have that flag are i386-only).
grep -q '^flags *:.*\blm\b' /proc/cpuinfo # Assuming a PC
You can see whether the kernel is 32-bit or 64-bit by querying the architecture with uname -m
. For example, i[3456]86
are 32-bit while x86_64
is 64-bit. Note that on several architectures, a 64-bit kernel can run 32-bit userland programs, so even if the uname -m
shows a 64-bit kernel, there is no guarantee that 64-bit libraries will be available.
[ "$(uname -m)" = "x86_64" ] # Assuming a PC
You can see what is available in userland by querying the LSB support with the lsb_release
command. More precisely, lsb_release -s
prints a :
-separated list of supported LSB features. Each feature has the form module-version-architecture
. For example, availability of an ix86 C library is indicated by core-2.0-ia32
, while core-2.0-amd64
is the analog for amd64. Not every distribution declares all the available LSB modules though, so more may be available than is detectable in this way.
You can see what architecture programs on the system are built for with a command like file /bin/ls
. Note that it's possible to have a mixed system; even if ls
is a 64-bit program, your system may have libraries installed to run 32-bit programs, and (less commonly) vice versa.
You can find out the preferred word size for development (assuming a C compiler is available) by compiling a 5-line C program that prints sizeof(void*)
or sizeof(size_t)
. You can obtain the same information in a slightly less reliable way² by running the command getconf LONG_BIT
.
#include <stdio.h>
int main() {
printf("%d\n", (int)sizeof(void*));
return 0;
}
As for virtual machines, whether you can run a 64-bit VM on a 32-bit system or vice versa depends on your virtual machine technology. See in particular
How can I install a 64bit Linux virtual machine on a 32bit Linux?
¹ “Word size” is the usual name for what you call bitness.
² It can be unreliable if someone installed an alternate C compiler with a different target architecture but kept the system default getconf
.
I’ve written a function that returns 1
if the argument is the root device,
0
if it is not, and a negative value for error:
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
static int
root_check(const char *disk_dev)
{
static const char root_dir[] = "/";
struct stat root_statb;
struct stat dev_statb;
if (stat(root_dir, &root_statb) != 0)
{
perror(root_dir);
return -1;
}
if (!S_ISDIR(root_statb.st_mode))
{
fprintf(stderr, "Error: %s is not a directory!\n", root_dir);
return -2;
}
if (root_statb.st_ino <= 0)
{
fprintf(stderr, "Warning: %s inode number is %d; "
"unlikely to be valid.\n",
root_dir, root_statb.st_ino);
}
else if (root_statb.st_ino > 2)
{
fprintf(stderr, "Warning: %s inode number is %d; "
"probably not a root inode.\n",
root_dir, root_statb.st_ino);
}
if (stat(disk_dev, &dev_statb) != 0)
{
perror(disk_dev);
return -1;
}
if (S_ISBLK(dev_statb.st_mode))
/* That's good. */ ;
else if (S_ISCHR(dev_statb.st_mode))
{
fprintf(stderr, "Warning: %s is a character-special device; "
"might not be a disk.\n", disk_dev);
}
else
{
fprintf(stderr, "Warning: %s is not a device.\n", disk_dev);
return(0);
}
if (dev_statb.st_rdev == root_statb.st_dev)
{
printf("It looks like %s is the root file system (%s).\n",
disk_dev, root_dir);
return(1);
}
// else
printf("(It looks like %s is NOT the root file system.)\n", disk_dev);
return(0);
}
The first two tests are basically sanity checks: if stat("/", …)
fails or “/
” is not a directory, your filesystem is broken. The st_ino
tests are something of a shot in the dark. AFAIK, inode numbers should never be negative or zero. Historically (by which I mean 30 years ago), the root directory always had inode number 1. This may still be true for a few flavors of *nix (anybody heard of “Minix”?), and it may be true for the special filesystems, like /proc
, and for Windows (FAT) filesystems, but most contemporary Unix and Unix-like systems seem to use inode number 1 for tracking bad blocks, pushing the root up to inode number 2.
S_ISBLK
is true for “block devices”, like /dev/sda1
, where the output from ls -l
begins with “b
”. Likewise, S_ISCHR
is true for “character devices”, where the output from ls -l
begins with “c
”. (You may occasionally see disk names like /dev/rsda1
; the “r
” stands for “raw”. Raw disk devices are sometimes used for fsck
and backup, but not mounting.) Every inode has a st_dev
, which says what filesystem that inode is on. Inodes for devices also have st_rdev
fields, which say what device they are. (The two comma-separated numbers you see in place of the file size when you ls -l
a device are the two bytes of st_rdev
.)
So, the trick is to see whether the st_rdev
of the disk device matches the st_dev
of the root directory; i.e., is the specified device the one that “/
” is on?
Best Answer
In the ARM world from ARMv4 to ARMv7 floating-point support is called VFP, and hardware support for it appears in the
Features
line of/proc/cpuinfo
or in theVFP support
log message printed by the kernel while booting. (In ARMv8 it's just "FP".)In
/proc/cpuinfo
on an Allwinner A20 this gives:(see the various
vfp
features) and in the boot log:If VFP isn't fully supported, the kernel will instead log
or
As to whether your Python interpreter is capable of using this, it appears to depend mainly on the architecture of your ARM Linux distribution. If I understand things correctly, basic Debian
armel
won't use the FPU, Debianarmhf
(and Raspbianarmhf
) will; the older Debianarm
variant used FPU instructions, but these were emulated if the hardware didn't support them. Onarmel
you can install kernels or C libraries with FPU support (although no such C library appears to be available in the Debian archives).