First of all, sparse files are only handled transparently if you seek, not if you write zeroes.
To make it more clear, the example from Wikipedia
dd if=/dev/zero of=sparse-file bs=1k count=0 seek=5120
does not write any zeroes, it will open the output file, seek (jump over) 5MB and then write zero zeroes (i. e. nothing at all). This command (not from Wikipedia)
dd if=/dev/zero of=sparse-file bs=1k count=5120
will write 5MB of zeroes and will not create a sparse file!
As a consequence, a file that is already non-sparse will not magically become sparse later.
Second, to make a file with lots of zeroes sparse, you have to cp it
cp --sparse=always original sparsefile
or you can use tar's or rsync's --sparse option as well.
If you started sshfs with -o reconnect
, killing it's hanging SSH process will make it reconnect.
First find the matching SSH, for example:
ps -ef
...
user 9644 1 0 11:15 ? 00:00:00 ssh -x -a -oClearAllForwardings=yes -2 <host> -s sftp
...
The you can tell it apart by the distinctive set of options and the host you were connecting sshfs to. Then kill it, regular SIGTERM should be enough:
kill 9644
This should make SSHFS start a new SSH session and the mounted filesystem will become responsive again and all processes hanging on it will continue as if nothing happened.
Best Answer
Nope, sshfs does not copy any files over the network when you mount a remote directory. It does not even copy files when you cd into a sshfs-mounted directory. When you cd into a directory, sshfs fetches the names of the files.
The actual contents of files only get transferred by when you access a file. So let's say there's a file called file.txt in the directory mydir, mounted on your system via sshfs. The transmission of the contents of file.txt starts:
This means you can safely mount an entire root filesystem with sshfs, even if it's larger than all the free space you have available on your hard drive.