琪依坤 | 羽毛在飛

Good Luck To You!

VirtualBox shared folder symlink error

由于VDI硬盘在删除文件后,不能自动缩小尺寸,写新的文件也不会占用已删除的空间,造成VDI体积越来越大。后来,就想将文件放到share folder。若干次发现,在解压缩时会出现Cannot create a symlink to ...... Read only file system. 的提示,造成解压缩失败。

转载两篇关于如何在shared folder 创建symlink的文章,下面是两个非常重要的地方,一定要加以注意。

1. 以管理员身份运行CMD

2. 以管理员身份启动虚拟机

 

第一篇:

解決VirtualBox的共用資料夾無法建立軟連結

我的電腦我習慣上桌面還是用Windows,但是開Server下指令還是Linux系統方便多了,所以開發時需要執行東西我會用VirtualBox開Ubuntu來進行。

VirtualBox有個方便的功能稱為共用資料夾(shared folder),因此我習慣將在Windows的workspace利用共用資料夾分享到Ubuntu (VM)裡面,然後由Ubuntu來開server。

但是最近開始玩Node.js發現,VirtualBox共用資料夾安裝是無法增加軟連結(Symbolic link)。因為安裝npm package的時候經常需要增加軟連結的權限,因此安裝的最後就會出現錯誤訊息!

?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
npm ERR! Error: EROFS, symlink '../express/bin/express'
npm ERR! If you need help, you may report this log at:
npm ERR!
npm ERR! or email it to:
npm ERR!    
 
npm ERR! System Linux 2.6.38-13-generic
npm ERR! command "/PATH-To-NODE/bin/node" "/PATH-To-NODE/bin/npm" "install" "express"
npm ERR! cwd /media/sf_SHARED_FOLDER/test
npm ERR! node -v v0.8.15
npm ERR! npm -v 1.1.66
npm ERR! path ../express/bin/express
npm ERR! code EROFS
npm ERR! errno 56
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /media/sf_SHARED_FOLDER/test/npm-debug.log
npm ERR! not ok code 0

而在console執行建立軟連結的指令也會錯誤

?
1
2
$ ln -sf /SOME_PATH/SOME_FILE /media/sf_SHARED_FOLDER/A_SYMBOLIC_LINK
ln: creating symbolic link `/media/sf_SHARED_FOLDER/A_SYMBOLIC_LINK': Read-only file system

google之後看到這篇文章發現原來python virtualenv也有類似的問題。總之在HOST OS為Windows 7、Client OS (VM)為 Ubuntu Linux的時候,共用資料夾就會發生軟連結無法寫入的情況!

修正方法如下,請在HOST (Windows) 開啟cmd (需要管理員權限開啟):

?
1
> c:\Oracle\VirtualBox\VBoxManage setextradata YOURVMNAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/YOURSHAREFOLDERNAME 1

上面的參數請視情況修改:

  • c:\Oracle\VirtualBox\ : 這是VirtualBox的預設資料夾,如果安裝在不同資料夾,請自行修改。
  • YOURVMNAME : 請修改為你要開啟的VM名稱。
  • YOURSHAREFOLDERNAME :修改為VM設定中共用資料夾的名稱

確認是不是設定成功了,可以用這個指令查看:

?
1
> c:\Oracle\VirtualBox\VBoxManage getextradata YOURVMNAME enumerate

設定完畢後就可以順利使用了!

如果設定後出現這樣的錯誤:

?
1
ln: failed to create symbolic link `LINKNAME': Protocol error

表示你的VirtualBox不是用管理員權限打開。

第二篇:

http://ahtik.com/blog/2012/08/16/fixing-your-virtualbox-shared-folder-symlink-error/

Fixing your virtualbox shared folder symlink error

Operations such as installing node.js or python virtualenv to a virtualbox writable shared folder can fail if you try to do this as a linux (ubuntu) virtualbox guest running Windows 7 host.

The cause is symlink permission.

Typical error:

ln -fs out/Release/node node
ln: failed to create symbolic link `node': Read-only file system

It can also be a “Protocol error”.

This happens even if your shared folder is writable.

Fix: Enable symlinks feature in VirtualBox

Run at cmd prompt:

  1.     
  2. VBoxManage setextradata YOURVMNAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/YOURSHAREFOLDERNAME 1  
  3.     

Verify by running:

  1.     
  2. VBoxManage getextradata YOURVMNAME enumerate  
  3.     

If your user belongs to Administrators group then start VirtualBox with “Run as Administrator”!

If user is not in Administrators group

By default Windows 7 security policy does not allow creating symlinks as it’s a potential security threat. Run “secpol.msc” and navigate to “Local Policies-User Rights Assignments” and add your user to “Create symbolic links”. I didn’t try that but could be that after that virtualbox could be run as a regular user.

Speculation: The controversy is that users with admin group seem to be unable to create symlinks even after granting the permission unless they use “run as admin”. Maybe symlink privilege gets filtered out for regular runs when user belongs to Administrators. Any ideas?

Let me know if it helps or if there’s an easier way!

 

更多精彩请关注公众号:

发表评论:

Powered By Z-BlogPHP 1.7.2

沪ICP备12032294号-1