- Can I run a Windows .exe file on Linux? [duplicate]
- 7 Answers 7
- How can I access Windows files from Ubuntu
- 4 Answers 4
- Access the Windows file system through WSL!
- 1. Use the cd command in the Linux terminal.
- 2. Moving files between the two systems through WSL.
- 3. Editing windows files through WSL.
- 4. Creating files in windows through WSL.
- 5. Deleting files from the windows file system through WSL.
- Top comments (5)
- Read next
- NextJS 13 – How to Web3?
- Using Webflow DevLink Beta
- How to build a LLM powered carbon footprint analysis app
- Enhancing Your Laravel API with Treblle Platform
Can I run a Windows .exe file on Linux? [duplicate]
Can a Windows .exe file be run on Linux? If the same architecture is used will it be possible? Like if both programs run on X86 architecture, will it be possible to run a Windows .exe on Linux?
7 Answers 7
The exe file will either execute under Linux or Windows, but not both.
Executes Under Windows
If the file is a windows file, it will not run under Linux on it’s own. So if that’s the case, you could try running it under a Windows compatibility layer (Wine). If it’s not compatible with wine, then you won’t be able to execute it under Linux.
Before you can start, you will need to install Wine. The steps you need to install Wine will vary with the Linux platform you are on. You can probably Google «Ubuntu install wine», if for example, you’re installing Ubuntu.
Once you have wine installed, then you’d be able to execute these commands.
Execute Under Linux
If you know this file to run under linux, then you’ll want to execute these commands:
You’ll want to change permissions to allow all users to execute this file (a+x). you could also allow just the user to execute (u+x)
Launch the program, the ./ tells the command line to look in the current path for the file to execute (if the ‘current’ directory isn’t in the $PATH environment variable.
The operating system (Windows or Linux) provides services to applications. For example, Windows and Linux will have functions that the application can call to access files, to access the network, to display things on the screen, etc.
The different operating systems provide different ways of doing those things, so an application that does it the Windows way won’t work on Linux, and vice versa, even though the CPU architecture is the same.
This answer is correct. It’s not the only reason (the different loaders and executable formats are also key), but it’s one of them.
It’s one of the main reasons you can’t have the same executable run natively on different operating systems.
@0xA3 If you are accessing platform specific API, then yes. But for the most part, that’s actually not true. Reimplementing C or C++ standard library is actually very simple, you just need to re-implement the bugs and redirect calls. What takes a lot of work is different file format (and platform specific API’s since they have to be reimplemented from scratch).
@Let, I never said you should. I was pointing out that you said «for the most part», programs don’t use platform-specific APIs; in fact, most do. Even programs using cross-platform libraries like GTK are still using platform-specific APIs indirectly.
No, different Operating Systems use different formats (ie. Windows uses PE while linux uses ELF). Also, when compiled, your program makes calls to native OS methods. As mentioned, you can look into using WINE. It provides most functionality to run Windows binries on Linux.
There are three major reasons why .exe files won’t directly run on Linux and why a Linux executable won’t directly run on Windows.
- The first is System calls. System calls are, almost by definition, platform specific. However, not all system calls are made the same. There are portable system calls (e.g. defined by the C/C++ standard library) and non-portable system calls (e.g. defined by POSIX or Microsoft). Applications that are statically linked at compile time with the system libraries would find that the part of the code that is statically included would probably have no chance of executing correctly in the target platform due to the vastly different design of the platform. Applications that are dynamically linked at runtime do have a chance of running with a few condition: if it’s portable system calls, there is a translation table between the original binaries’ system calls to the target platform’s system calls; if it’s non-portable system call, there must be a compatibility layer that receive system calls of the original platform and find an equivalent translation in the target platform (which may not always be possible 1 , different platforms have different set of features, and some feature does not make sense in the other platform 2 ). Solution: For running Windows program in Linux, Wine provides an implementation of Windows System Calls and Windows System Libraries, it also recognizes PE format; Wine can run Windows program in Linux without recompiling. For the Linux program in Windows, Cygwin provides an implementation of POSIX System calls in Windows, and it allows program written for Linux to be recompiled using Cygwin GCC to run on Windows system with no source-code changes. Because of the open source nature of most Linux program, it is easier to recompile rather than going the Wine’s way of providing binary-compatible layer. It is not impossible to provide wine-like compatibility layer, however Cygwin’s way is more robust and there is just not much drive to allow non-open-source Linux program to be easily ported to Windows.
- The other is Executable Format. Windows uses PE (Portable Executable) format and Linux uses ELF (Executable and Linkable Format). The executable format contains metadata, and defines how the executable is to be loaded and executed by the platform. Solution: It is entirely possible to write a PE -> ELF or ELF -> PE converter; and it probably should not be too hard to do so (warning: I’m not familiar with the actual format of either one). Another way is to write an executable loader that can understand PE files (e.g. Wine provides one) or executable loader that can understand ELF file (I believe the design of Windows limits the possibility of a double-clickable file running natively as an executable)
- System calls calling convention. Linux and Windows does not only have a different set of available system calls, it also have a very different system call calling convention. In Linux, to make a system call you pass the syscall number in eax/rax register and arguments in the rest of registers, and then you make 0x80 interrupt request. In DOS, you also pass arguments in the register, however there is a different interrupt request number for each system service so you don’t pass system call number in eax/rax. Windows NT is more similar to Linux, however instead of 0x80 you raise 0x2E interrupt request, however the system call number still differs (so you need a syscall number translation table and possibly a compatibility layer). Solution: Even when you don’t have a self-modifying code or trying to execute data as code or do other tricky codes, it is still very hard (as hard as solving the Halting Problem) to analyze an executable, search for all system calls interrupt requests, and translate them to the target platform’s system calls. An easier way is to provide a runtime service that handle the program’s interrupts requests and redirect them to the target platform’s system calls 3 .
There are various other reasons, but I believe these three are the big stumbling blocks.
1 filesystem security comes to mind, there is no way to translate between Linux’s security bits and Windows’ NTFS ACL.
2 Windows cannot fork a process; CreateProcess can somewhat be used to emulate fork however it loses the copy-on-write semantic. There is no way to do a create copy-on-write process in Windows.
3 I believe Wine does this
How can I access Windows files from Ubuntu
Is it possible to get the files I had on Windows onto my Ubuntu desktop? How can I connect to my Windows partition from Ubuntu?
4 Answers 4
yes of course you can acccess windows NTFS/FAT32 partitions from Ubuntu
Using the File Manager For those using a desktop version of Ubuntu, or one of its offical derivatives, the easiest and quickest way of mounting NTFS or FAT32 partitions is from the file manager: Nautilus in Ubuntu, Thunar in Xubuntu, Dolphin in Kubuntu and PCManFM in Lubuntu. Simply look in the left pane of the file manager for the partition you wish to mount and click on it — it will be mounted and its contents will show up in the main pane. Partitions show with their labels if labelled, or their size if not.
Unless you require your Windows partition — or a NTFS/FAT32 partition for data shared with Windows — mounted every time you boot up for one of the reasons given below, mounting from the file manager in this way should suffice.
If you are using a Wubi version of Ubuntu and you wish to browse the host partition, you do not need to mount it — it is mounted already in the «host» folder. Click on «File System» in the left pane of the Nautilus file browser and then open the host folder which you will see in the main pane.
Just Open Home folder from your Dash menu and you can see all partitions mounted under Devices:
Click on the needed drive and copy files/folders thw way you want to your Ubuntu drive
Access the Windows file system through WSL!
Have you ever wondered, how to access the windows file system through WSL? If the answer is yes you are in the right place! Microsoft WSL has given us an incredible way to access the windows file system, you have just to navigate through an exact path to do it. Without further due, let’s dive into the topic.
1. Use the cd command in the Linux terminal.
cd /mnt/c/Users **OR** cd /mnt/d/your_folder/your_folder
2. Moving files between the two systems through WSL.
If you want to move files between the two operating systems you can simply use the cp or mv commands.
cp — command for copying files
mv — command for moving files
Use of cp command
cp /mnt/c/file.txt /home/username/Documents
mv /mnt/c/file.txt /home/username/Documents
3. Editing windows files through WSL.
To edit windows files through the Linux terminal using WSL, you have to use any text editor that can be opened in the terminal. One of the most famous text editors is nano. In our example, I am going to use the nano editor.
Type into the terminal nano and the path to the file.
sudo nano /mnt/c/Users/file.txt
4. Creating files in windows through WSL.
To create a file in a specific windows directory you have first to navigate to it and then use the touch command to create a file.
touch — a command that creates a file.
. The file extension can be anything you want.
cd /mnt/c/Users/Public/Documents/ touch filename.txt
5. Deleting files from the windows file system through WSL.
To delete windows files using WSL, you have to navigate to the directory where the file lives and use the rm command.
rm — a command that deletes files / directories
cd /mnt/c/Users/Public sudo rm example_file.jpg
Congratulations you learned 5 vital skills about working with the Linux terminal. 🎺🎺🎺
If you have any questions, comment down, I will answer as soon as possible.
Top comments (5)
A self-taught programmer and software enthusiast. In my free time, I enjoy walking and running on local trails, playing my guitar, and plant based cooking.
Nice quick guide! I got sick of typing cd /mnt/c/Users/Joe so I made an alias in .bash_aliases file I called called cdwin (takes you to Windows «home» folder»
- create .bash_aliases in your WSL Ubuntu home directory: touch .bash_aliases
- nano .bash_aliases
- Enter alias cdwin=’cd /mnt/c/Users/’ into .bash_aliases file
- ctrl + x and then Y to save aliases file.
- Create a symbolic link in bash shell: ln -s /mnt/c/Users/ win
Now you can get to «windows home» from anywhere by typing cdwin from within WSL Ubuntu.
2 likes Like Comment button
👋 Hi, I’m Ivaylo Ivanov 👀 I’m interested in AI, server-side, cybersecurity, and ethical hacking. 🌱 I’m currently learning Javascript, Node.js, Go, and Python.
That’s really cool little tip!
2 likes Like Comment button
Question: why would you ever run Windows in the first place?
2 likes Like Comment button
Thoughts on keeping working code files on the windows side to keep them in OneDrive? Is it overkill? Not everything deserves a place on github.
2 likes Like Comment button
👋 Hi, I’m Ivaylo Ivanov 👀 I’m interested in AI, server-side, cybersecurity, and ethical hacking. 🌱 I’m currently learning Javascript, Node.js, Go, and Python.
Personally, I think that GitHub is the best place to store your projects because it is well-integrated with code editors and meant to be used by programmers. If you do not want your work to be publically accessible on GitHub, you can always create a private repository, where only you are going to have access. I do not have experience with google drive for keeping coding projects on there, but certainly, I would prefer Github.
1 like Like Comment button
For further actions, you may consider blocking this person and/or reporting abuse
Read next
NextJS 13 – How to Web3?
Using Webflow DevLink Beta
Bernie January Jr. — Jun 26
How to build a LLM powered carbon footprint analysis app
Enhancing Your Laravel API with Treblle Platform
👋 Hi, I’m Ivaylo Ivanov 👀 I’m interested in AI, server-side, cybersecurity, and ethical hacking. 🌱 I’m currently learning Javascript, Node.js, Go, and Python.