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.

1 Answers1

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.

Kaz Wolfe
  • 34,680