Moving $HOME from one WSL to another with local rsync
I’m installing a new WSL system, essentially a Linux VM. I want to move my 13GB of home directory files over. WSL doesn’t provide any easy way to do this. You can export and import a whole virtual disk. You can tar up your home directory and copy it just like you would any other Linux box. And you can use WSL’s various strange mounts (including 9P) but those will be slow and screw up persmissions.
The way I settled on was running an rsync daemon from the command line.
The client send command in the source WSL instance is the easy part. The only strange thing here is “localhost” as the destination. WSL’s networking magic means that two separate Linux instances apparently share “localhost”. They probably share it with the Windows host, too. (The ::xfer in the destination looks magic too; see below for the server config file that defines it.)
rsync -az --info=progress2 --port=12345 ~ nelson@localhost::xfer
The server side to receive things is trickier. Launching the server is easy enough. I just ran this as root, was running into problems with changing group ownership as a normal user
rsync --daemon --config=rsyncd.conf --no-detach --address=localhost --port=12345
All the real work here is in rsyncd.conf. Here it is:
pid file = /tmp/rsyncd.pid
lock file = /tmp/rsync.lock
log file = /tmp/rsync.log
[xfer]
path = /home/nelson/xfer
comment = xfer
read only = false
list = true
uid = nelson
gid = nelson
auth users = nelson
secrets file = /home/nelson/secrets.txt
I didn’t check this too closely, an AI generated it for me. It seems to work. It’s possible all my files got chowned and chgrped to nelson but in this case (my home directory) that’s ok.
The one gotcha is secrets.txt. The contents are simple, I just made it nelson:p for the insecure plaintext password “p” (you have to have some password). But that file has to be only readable by the user running rsync. Otherwise auth won’t work but the error message won’t tell you why.