How can I determine the OS architecture (32-bit or 64-bit) from a file on a disk?
It is trivial to determine whether the host operating system has a 32-bit or 64-bit kernel by running:
uname --machine
An output of i386
means 32-bit and x86_64
means 64-bit.
It is less trivial, but still feasible to determine whether an application is compiled for the i386 or amd64 architecture but neither of these will indicate the architecture of the kernel. Even checking /sbin/init
is not technically sufficient since the init program can be customized at boot time.
The only foolproof way to determine the architecture of the kernel is to actually boot it. Luckily this can easily be done using qemu
.
Begin by opening a terminal and navigating to /boot
on the hard drive. You will find one or more compressed kernel images in the form:
vmlinuz-[version]-[type]
For example, I have vmlinuz-3.19.0-21-generic
present in /boot
on my machine. Now, assuming you have the qemu-system-x86 package installed, run the following command, substituting the filename where appropriate:
qemu-system-i386 -kernel <path_to_kernel>
If you see a wall of text scroll by and eventually panic (because the root FS is missing), you have installed a 32-bit kernel. If instead you receive an error similar to the one displayed below, you have a 64-bit kernel (which will not boot on an x86 CPU).
I agree that in general the mere presence of a certain kind of executable or library isn't useful because it's possible to have objects of more than one architecture installed, but there are some executables that you can only have one of. file /mnt/usr/bin/dpkg
(replacing /mnt
with wherever you mounted your filesystem) will tell you whether the core package manager is 32-bit or 64-bit, which is an accurate indicator of the rest of the system unless you're in the middle of an in-place migration from one to the other - you'd certainly know if you were!
Look at the directories organization from the root of your old hard disk, this method is analogous to look for the "Program Files" and "Program Files (x86)" directories if it where a Windows OS.
In Linux, if 64 bit, you will see "lib32" and "lib64" directories, while if 32 bit you will only encounter the lib directory (I don't remember now if there would be a lib32 directory too).
If you do not trust in the suggested method, or need more guaranties, the "file" command looks promising. Looking at @ColinWatson answer, personally, I think that /sbin/init is a better candidate, but any of those files (dpkg or init) will match the Kernel arch.
For example, the execution of file /sbin/init
will provide an output like this:
/sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24
Just replace the path to /sbin/init with the proper mount point of your old root partition, if it is now /media/oldroot
, the full path becomes /media/oldroot/sbin/init