Create W32 7-Zip sfx in Linux
Jun 30
7-Zip allows you to create a self extracted binary archives with the -sfx switch. But in the Linux version of 7-Zip the SFX created is a Linux binary.
So if you run the following command in a Linux box and try to run test.exe in Windows you’ll get a “Program too big to fit into memory” error.
7z a -sfx test.exe test.txt
That’s because the binary is a GNU/Linux binary.
$ file test.exe test.exe: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped
The -sfx switch in Linux will try to use 7zCon.sfx module by default and will create a Linux binary console file.
If you want to create a W32 self extracted binary in Linux you have to pick the 7z.sfx module from the windows 7-Zip version and put it in the 7z directory.
In Ubuntu you can copy 7z.sfx in the following directory:
/usr/lib/p7zip/
After done this you can use the -sfx7.sfx switch to create a W32 binary SFX file.
e.g.
7z a -sfx7.sfx test.exe test.txt
and you get that
$ file test.exe test.exe: PE32 executable for MS Windows (GUI) Intel 80386 32-bit














Thx, that was not very clear on official docs or forums.
Thanks for the info, that’s great!
The “-sfx7.sfx” flag didn’t work for me, however. So I tried “-sfx7z.sfx” and that worked like a charm!
To test out a hunch I had, I also copied 7zCon.sfx from my Win32 installation and renamed it to 7zConW32.sfx and also stuck it into the /usr/lib/p7zip/ directory. I then did: “7za a -sfx7zConW32.sfx output.exe input_folder” — and ‘file’ command returned: PE32 executable for MS Windows (console) Intel 80386 32-bit
Awesome! =)