1

I've got a lighttpd web server set up on a Debian 6 guest in Virtualbox 4. I've got the www directory in a virtualbox shared folder, so that I can develop a website in the Windows host.

My problem is that two otherwise identical files created by different text editors are served differently by lighttpd. Vim works as it should, but creating files with echo (or any other editor) produces files that look fine on disk but become corrupted once lighttpd serves them. This problem is only present when the document root is on a shared virtualbox folder. It might be easier to show this problem than explain it, so I did a test case below.

EDIT: This is some kind of caching issue, running echo 3 > /proc/sys/vm/drop_caches before wget makes the downloaded file work fine. Still doesn't explain why vim isn't affected though...

root@Apricots:/var/www/xxx.org/http# vim vim.txt
    (I type 'Line 1' into vim, on one line)
root@Apricots:/var/www/xxx.org/http# echo 'Line 1' >> echo.txt
root@Apricots:/var/www/xxx.org/http# md5sum vim.txt echo.txt
376cbf50d47a30459adca22b15964912  vim.txt
376cbf50d47a30459adca22b15964912  echo.txt
root@Apricots:/var/www/xxxt.org/http# cd ~
root@Apricots:~# wget xxx.org/vim.txt xxx.org/echo.txt
    (The two files download OK)
root@Apricots:~# md5sum vim.txt echo.txt
376cbf50d47a30459adca22b15964912  vim.txt
376cbf50d47a30459adca22b15964912  echo.txt
root@Apricots:~# cat vim.txt
Line 1
root@Apricots:~# cat echo.txt
Line 1
root@Apricots:~# cd /var/www/xxx.org/http/
root@Apricots:/var/www/xxx.org/http# vim vim.txt
    (I type 'Line 2' in a second line in vim)
root@Apricots:/var/www/xxx.org/http# echo 'Line 2' >> echo.txt
root@Apricots:/var/www/xxx.org/http# md5sum vim.txt echo.txt
ef3095884e8daf72dc4d2ea71306caa7  vim.txt
ef3095884e8daf72dc4d2ea71306caa7  echo.txt
root@Apricots:/var/www/xxx.org/http# cat vim.txt
Line 1
Line 2
root@Apricots:/var/www/xxx.org/http# cat echo.txt
Line 1
Line 2
root@Apricots:/var/www/xxx.org/http# cd ~
root@Apricots:~# rm vim.txt echo.txt
root@Apricots:~# wget xxx.org/vim.txt xxx.org/echo.txt
    (They both download fine again)
root@Apricots:~# md5sum vim.txt echo.txt
ef3095884e8daf72dc4d2ea71306caa7  vim.txt
0b8835dcb6bb73c7a4eb25301101699a  echo.txt
root@Apricots:~# cat vim.txt
Line 1
Line 2
root@Apricots:~# cat echo.txt
Line 1
root@Apricots:~# hexdump vim.txt
0000000 694c 656e 3120 4c0a 6e69 2065 0a32
000000e
root@Apricots:~# hexdump echo.txt
0000000 694c 656e 3120 000a 0000 0000 0000
000000e
root@Apricots:~# echo "what the hell just happened there??"
what the hell just happened there??
1
  • 1
    Don't know how to tell you to fix it, but I can tell you what the difference is: When you save in vi, it creates a completely new file that is moved to the location of the old file, while > truncates the existing file and writes to it. If you use ls -il, you will see that vim.txt has a new inode # while echo.txt is the same inode number. See if that is the case for however you're creating "real" files that are being read wrong, perhaps something along the line is caching by inode #.
    – DerfK
    Feb 25, 2011 at 1:25

2 Answers 2

2

Alright, fixed it. Apparently it's because sendfile() from virtualbox shared folders is broken. You can make lighttpd use the write syscall to send files instead, by adding the directive server.network-backend = "writev". Since this is just for development, not a big deal.

Source:

http://forums.virtualbox.org/viewtopic.php?f=6&t=38973

http://forums.virtualbox.org/viewtopic.php?f=8&t=24905&p=129089&hilit=vboxsf+web+server

1
  • +1 for figuring out the solution.
    – sybreon
    Feb 27, 2011 at 13:20
0

I have also had some problems with serving files from a VBox shared folder. In my case, I edit the files on the host machine but the changes are not reflected in the VM.

To work around it, I have to umount and mount the shared folder inside the VM to get it to see the new files. Maybe something similar is happening here and you might need to either sync it or force a flush by umount and mount the shared folder too.

If that works, maybe there is an option to do it automatically.

2
  • This is odd... I've tried running sync and then service lighttpd restart to no avail, but running service lighttpd stop, umount /var/www, mount -a and then service lighttpd start makes the file serve properly. But, my understanding is that those two should do the exact same thing!!! Feb 25, 2011 at 1:07
  • Well, sounds like the same problem as mine then. If you figure out a way to do it automatically, let me know. :)
    – sybreon
    Feb 25, 2011 at 1:12

Not the answer you're looking for? Browse other questions tagged .