setarch
Run program under specified architecture environment
TLDR
Run a command as if the machine architecture is i686 (useful for running 32-bit apps on a 64-bit kernel)
Run a shell with the x86_64 architecture
Disable randomization of the virtual address space
List supported architectures
Display help
SYNOPSIS
setarch [options] architecture [command [arguments...]]
setarch [options] [command [arguments...]]
PARAMETERS
architecture
The target architecture personality string (e.g., i386, x86_64, arm). This is the primary argument to change the reported architecture for the command.
command
The program or script to be executed with the modified architecture personality.
arguments
Any arguments to be passed to the command.
-R, --addr-no-randomize
Disables address space layout randomization (ASLR) for the executed command, making memory addresses more predictable.
-r, --force-addr-randomize
Forces address space layout randomization (ASLR) for the executed command, overriding system defaults if necessary.
-S, --stack-randomize
Forces randomization of the stack address for the executed command.
-L, --library-randomize
Forces randomization of shared library addresses for the executed command.
-B, --no-brk-randomize
Disables randomization of the brk() system call's return address for the executed command, affecting heap layout.
-v, --verbose
Enables verbose output, showing more information about the operations setarch performs.
-h, --help
Displays a help message and exits.
-V, --version
Displays version information for setarch and exits.
DESCRIPTION
setarch is a utility that allows you to execute a command with a modified system personality, specifically concerning the reported architecture. Its primary use case is to facilitate the execution of applications compiled for a different architecture (e.g., a 32-bit binary on a 64-bit system, or vice-versa) without requiring explicit recompilation or a full virtualization environment. It achieves this by utilizing the personality(2) system call, which changes how certain system calls and signals behave for the executed process, making it appear as if it's running on the specified architecture. While often used for i386 or x86_64 compatibility, setarch can theoretically be used with any architecture supported by the kernel's personality system call. It's a powerful tool for compatibility and testing scenarios.
CAVEATS
setarch relies on the kernel's personality(2) system call; not all kernels or architectures support all personality types. It does not translate instruction sets; a 32-bit binary run with setarch x86_64 will still execute 32-bit instructions (requiring kernel compatibility like IA32_EMULATION). It does not provide a full chroot or virtualization environment; dependencies must still be available for the target architecture.
HOW IT WORKS
setarch leverages the personality(2) system call, which allows a process to change certain kernel behaviors and the reported system type (e.g., from x86_64 to i386). This does not involve instruction set translation, but rather adjusts how the kernel handles system calls, signals, and other low-level interactions for the specified process, making it appear to the running application as if it's on the target architecture. For example, when running a 32-bit binary on a 64-bit kernel using setarch i386, the kernel's IA32 emulation layer is activated for that process.
HISTORY
setarch is part of the util-linux project, a collection of essential Linux utilities. Its development is tied to the evolution of multi-architecture kernel support, particularly the ability for 64-bit Linux kernels to run 32-bit binaries seamlessly through the personality() system call and IA32 emulation. It provides a more flexible way to invoke this personality change compared to specific wrappers like linux32.