Ubuntu in the virtual machine shares folders with the host

The solution when Ubuntu and the host share folders in the virtual machine, and the /mnt directory is empty and there is no shared folder

1. Enable shared folders

First shut down the virtual machine, in the virtual machine settings, select the options panel, select the shared folder, select always enable

image-20230117163209175

Click Add, select Next in the pop-up panel, and select a shared folder (select or create a new folder in the host as a shared folder)

image-20230117163634796

Select Enable this sharing and click Finish.

image-20230117163643736

2. Install VMware Tools

The virtual machine is powered on and VMware Tools is installed

The VMware Tools directory appears in the directory

image-20230117162400898

Copy the compressed package indicated by the arrow in the figure to the desktop, and decompress it

image-20230117162624137

Go to the vmware-tools-distrlb directory and choose to open it in the terminal

image-20230117164728108

Type in terminal

sudo ./vmware-install.pl

It will ask yes or no in the middle, choose yes for all, and keep pressing Enter until the loading is completed, as shown in the figure after completion

image-20230117165044484

After completion, enter the mnt directory under the Ubuntu computer directory

image-20230117165250041

If there is a /mnt/hgfs/ shared folder, it is successful, if not, the solution is as follows.

3. If there is no shared folder in the /mnt/hgfs/ directory

Open a terminal command window in the computer directory

Install command package

sudo apt-get install open-vm-tools

If there is no hgfs directory under mnt, you need to create a hgfs directory yourself (root permission is required)

Open a terminal command window in the mnt directory

Create a folder with root privileges. If you use simple installation of ubuntu in VMware, the root user has no password, which means that the root user cannot be used, and the root privilege cannot be opened. This is the security mode of ubuntu . But ubuntu provides a command to execute super management privileges as ordinary users—sudo

sudo passwd root

First enter the password of your own ordinary user, and then set the root password. Note that it must be greater than 8 characters, and do not include root

After setting up the root user, enter the command

su root

Enter the root password, as shown in the figure, you have the permission to create folders

image-20230117171548819

To create a folder under the mnt directory, as shown in the figure above, you must enter the mnt directory. If you are not in the mnt directory, you must enter through the cd command. Execute the following command to create the hgfs directory.

sudo mkdir hgfs

Execute cd .../ to enter the computer directory

mount

sudo vmhgfs-fuse .host:/ /mnt/hgfs -o nonempty -o allow_other

If an error is reported due to -o nonempty, delete it

Execute commands such as

sudo vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other

Then the shared folder appears under mnt/hgfs successfully

image-20230117172734077

The shared folder under the mnt/hgfs directory disappears after restarting

It needs to be mounted here, that is, open a terminal command window in the root directory of the computer

sudo vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other

That is, it needs to be remounted after each restart.

4. The solution to the failure of the shared folder after restarting

Edit the fstab file under etc and execute the following command in the root directory

vim /etc/fstab

If the following situations occur

image-20230117173528551

Then install vim first

sudo apt install vim

Then execute the above command

vim /etc/fstab

Move the cursor to the last digit, press a to enter insert mode, press Enter, and enter the following command

 .host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other 0 0

然后在执行上述命令

vim /etc/fstab


将光标移至最后一位,按a进入插入模式,按回车键,输入以下命令

.host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other 0 0


然后输入 :wq 保存并退出,不要忘记冒号。

Guess you like

Origin blog.csdn.net/qq_52783505/article/details/128720211