3

I'm setting up a new Win 10 laptop with Ubuntu 16.04 in dual boot that has a home folder and with WSL (Windows Subsystem for Linux) using Xubuntu that has a home folder.

My goal is when booted with Ubuntu I want to be able to change files and have those reflected in WSL at the same time. When I've booted into Windows I want WSL changes to be reflected in Ubuntu at the same time.

Within WSL Ubuntu will be mounted. Within Ubuntu WSL will be mounted.

I have a "faint hope" that a file manager can virtually merge the two home folders, strip out the file names that are the same and leave me with the file names / directories names that are in one home folder (and sub-directories) but not the other (XOR).

The reason being:

  • I don't want to duplicate the same files between two different homes and have to synchronize them.
  • Some files / documents with the same name must be unique to each environment and never synchronized. A likely candidate would be ~/.conkyrc should never be copied between environments as one uses Linux Kernel and the other uses NT kernel for machine stats.

I'm hoping to get Xubuntu running as a second Desktop within WSL. It should be able to run most file managers. I'm hoping I won't have to dig into the source to XOR two home folders.

I think much of /usr/local/bin will be only on the Ubuntu partition and symbolic links created from WS.

On a similar note I read once the same user name shouldn't be used as a sub-directory under /home on different partitions. ie having two /home/WinEunuuchs2Unix is frowned upon? And the Windows one should be named /home/WinEunuuchs2Unix2WSL for example? Real names would be shorter of course.


XOR

Initially there was some confusion on my question so I'll define XOR as best I can. It is an Assembler command (some insist on calling it Assembly Language) that means:

In one, or in another but NOT in both

Once you understand this instruction code you'll see how I want to be presented with a list of files in my directory PLUS the list of files in the same directory name in on a DIFFERENT partition that do NOT exist on the current partition so I can edit any of the files simultaneously and NOT have to synchronize them because they do NOT exist in the current partition in the first place.

It's probably a new invention in data processing so it makes my question misleading to most people which I apologize for. Ironically on the other hand, XOR is probably one of the oldest computer instruction codes on earth, dating back to the 1 vacuum tube = 1 bit of memory days I imagine.

  • Diff can do something like this. I recall having done that. – Andrea Lazzarotto Oct 18 '17 at 23:53
  • @AndreaLazzarotto I use diff now to tell me what lines of code people have changed on the internet that are different from my SSD. I run that in batch mode though and would prefer a more instantaneous GUI approach when both partitions are on SSD. If all else fails though your idea would be good to consider. – WinEunuuchs2Unix Oct 18 '17 at 23:58
  • 1
    Wait, you want your WSL system and your Ubuntu system to be effectively synched? That is a very dangerous idea for a lot of reasons. A lot of things can go wrong and cause massive data loss or OS failure. – Kaz Wolfe Oct 19 '17 at 0:05
  • 2
    Minor nitpick: XOR is not just an assembly command. It's a basic logical operation (as defined by ⊕) – Kaz Wolfe Oct 19 '17 at 5:03
  • 1
    @AndreaLazzarotto searching your idea of diff I found two file managers that use it. There's a CLI one called Midnight Commander and a GUI one called Krusader. Both also allow custom user commands operations on the two directories. So a solution seems to be close, if not already there. – WinEunuuchs2Unix Oct 19 '17 at 10:38
2

What you're doing (attempting to sync a WSL and true Ubuntu install perfectly) is very dangerous and should not be taken lightly, if it's even possible. Config/system differences between the two OSes can cause massive problems depending on how things happen. See here for what happens when people do similar things with VirtualBox.

Only worse things can happen with WSL, and this will only be exaggerated by trying to sync all files except those on a blacklist. You're essentially asking for trouble here.

That said, what you want to do (merge folders without overwriting existing files) is extremely simple and is already supported by pretty much every major file manager (and the command prompt).

Note that this will not work automatically. You will have to manually trigger them, though I suppose you can use some creative abuse to make it semi-automatic. Do note that all of the former caveats will apply.


Plain old cp can do this with the -n option:

┌─[16:57:35]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % tree
.
├── folder-a
│   ├── a
│   ├── b
│   └── d
└── folder-b
    ├── a
    ├── c
    ├── e
    └── k
        └── j

3 directories, 7 files
┌─[16:57:41]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % cat folder-a/a
Hello World A
┌─[16:57:43]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % cat folder-b/a
Hello World B
┌─[16:57:54]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % cp -nR folder-a/* folder-b/
┌─[16:58:00]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % cp -nR folder-b/* folder-a/
┌─[16:58:03]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % tree
.
├── folder-a
│   ├── a
│   ├── b
│   ├── c
│   ├── d
│   ├── e
│   └── k
│       └── j
└── folder-b
    ├── a
    ├── b
    ├── c
    ├── d
    ├── e
    └── k
        └── j

4 directories, 12 files
┌─[16:58:07]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % cat folder-a/a
Hello World A
┌─[16:58:09]─[kazwolfe@firewolf]
└──> /tmp/xor-terminal % cat folder-b/a
Hello World B

Alternatively, if you want to use the GUI, that is also doable with plain old Nautilus. Just drag and drop the contents of one to the other, and you'll see this prompt on the first conflicting file. Just hit Apply this action to all files and then Skip:

image showing things

┌─[17:01:33]─[kazwolfe@firewolf]
└──> /tmp/xor-gui % cat folder-a/a
Hello World A
┌─[17:01:34]─[kazwolfe@firewolf]
└──> /tmp/xor-gui % cat folder-b/a
Hello World B

If you want to experiment a bit (actually, a lot), you might be able to abuse something like aufs or OverlayFS. Effectively, you'd set up your "base" filesystem to the common filesystem (likely going to be your Ubuntu root). Then, you'd have a second layer containing WSL-only changes. Have the WSL-only layer be read-only, and everything else pass through to the base filesystem. Of course, this is all theoretical and you will have to do a lot of research to see if something like that is even possible.

If you only want "major" folders synced between OSes (for example, Documents, Music, Desktop, etc.), just create a symlink from one to the other. My old Ubuntu config back when I dual-booted had my ~/Documents folder symlinked to the Windows equivalent. This can be done, of course, with something like ln -s. Note that you may need to muck around a bit with permissions on mounts or use bind mounts.

  • TL;DR; No I explicitly do NOT want them sync'd. I want my documents to be exclusive or'd (XOR) so I do not have to duplicate them between partitions and manually sync them one by one. +1 though for a great answer along a similar vein :) – WinEunuuchs2Unix Oct 19 '17 at 0:20
  • @WinEunuuchs2Unix - You can not really do what you envision. Bash on windows are still windows binaries and windows does not have the capability or rw to linux file systems reliably. Ubuntu does not support ntfs as a home directory. Your best option is a shared NTFS partition which you can then rw from both os. – Panther Oct 19 '17 at 4:53
  • @bodhi.zazen Bash on Windows runs Linux Binaries natively without recompiling. It is true that Windows programs cannot edit (or copy) Linux files because they corrupt the file attributes/permissions. I'm looking for a Linux file manager not a Windows file manager. – WinEunuuchs2Unix Oct 19 '17 at 10:15
  • As always you are right. I'm using your coveted nano now in WSL even though I can use gedit in xfce4 in VcXsrv in WSL. (It's complicated). After weeks of research I've come to the conclusion I'll have to setup the old laptop as an Open-SSH server with a static set of bash scripts and documents.I'll have to use Open-SSH client in WSL and dual booted Linux on the same client PC to access those files so as to not have to manually copy files. I've posted comments on MS sites on limitations of WSL not being able to read/write Linux partitions to no avail. Hint @RichTurner @YouknowWhere. – WinEunuuchs2Unix Nov 2 '17 at 1:30
  • Oh well now I have a good excuse to buy one of those 8 port 10/100/1000 switch thingies for forty bucks :) – WinEunuuchs2Unix Nov 2 '17 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.