In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
People who play with virtual machines generally set up a shared directory for virtual machines, which is easy to operate and use. For example, if I install the Ubuntu 16.04 virtual machine with Virtualbox on a 64-bit win10 system, I usually map some directories under the win10 system to Ubuntu. In the past, I used to write the information of the shared directory directly to the / etc/fstab file to achieve automatic mount (about this how to operate, do not do detailed explanation here, you know about Baidu, very simple). However, several problems have been found after using it for a long time:
First, there are several directory locations where I need to mount to the virtual machine (for example, tmp, where there are temporary files, wrk, where there is a work project code area, and mit, a directory where learning materials are organized, etc.), and some of these directories are under different partitions, and some directories are even in very deep locations, so it is impossible to mount them through a single shared directory.
Second, of all the shared directories automatically mounted in this way, once one or more of them fail (such as changing the name or moving the location, etc.), it will cause ubuntu to fail to start and enter the desktop. For perfectionists like me, I often sort out files, directories, levels, etc., and it is common to move to a shared directory. When I encountered this situation several times, I didn't react to it for a while. I thought the virtual machine was dead and almost deleted the reinstallation directly.
Third, I have several computers to use virtual machines. For convenience, I reuse the image files of the same virtual machine and directly copy the entire VDI file back and forth when necessary. Also, the directories I want to map on different computers are not exactly the same (for example, I don't need to map the directory wrk of the work project code area for a virtual machine at home). This time is very troublesome, each copy, you have to remember to change the virtual machine / etc/fstab file, otherwise the virtual machine will not be able to start, it is really troublesome.
In order to solve these problems, I have explored a more convenient and automatic method of mounting shared directories, which is specially recorded here for follow-up reference and share with my colleagues. This method is actually very simple, just two steps, the first step is to mount the entire partition of the physical machine, and the second step is to create a soft link to the directory specified in the partition.
Step 1: to mount the entire partition of the physical machine.
First of all, add the partition of the physical machine you want to mount as a shared directory in the settings of Virtualbox. As shown in the following figure, I added [D root directory, E disk root directory and Onedrive root directory] as shared directories, and named them [drv_d/drv_e/drv_o] respectively. You can modify them as you like:
It should be noted here that when setting up a shared directory, there is an option to automatically mount the directory [remember not to select] (as shown below), otherwise the Ubuntu system will automatically mount the directory to the / media directory when it is started, and it will be mounted with the permissions of the super user, which will cause other ordinary users to be unable to access, and then have to toss about user rights and other things, which is very troublesome. You might as well write two commands by yourself and get them done.
Then, create a new mount directory for the shared files under the / mnt directory of the virtual machine, and then the external drive root directory will be mounted directly to this directory. I will name it win10 here (the full address is / mnt/win10, of course, the location of this directory depends on you, do not make mandatory), you can set it freely [note that when you create a new directory, you may be prompted that the user does not have enough permissions, you need to sudo it]. And create 3 new directories under this directory to mount the actual 3 shared directories, which are also named drv_d/drv_e/drv_o here, and you can also set them yourself.
Leon@Ubuntu:~$ cd / mnt/leon@Ubuntu:/mnt$ sudo mkdir win10 shareleon@Ubuntu:/mnt$ sudo chown leon * leon@Ubuntu:/mnt$ sudo chgrp leon * leon@Ubuntu:/mnt$ cd win10/leon@Ubuntu:/mnt/win10 $mkdir drv_d drv_e drv_o
Next, modify the / etc/fstab file in the virtual machine by adding the following statement:
Drv_d / mnt/win10/drv_d vboxsf rw,auto 0 0drv_e / mnt/win10/drv_e vboxsf rw,auto 0 0drv_o / mnt/win10/drv_o vboxsf rw,auto 0 0
In the above script, the first project is the name of the external physical machine shared directory, which is the name of the directory set up in figure 1. The / mnt/win10/drv_d in the second project is the mount address where you want to mount it to the ubuntu virtual machine. There is no explanation for other projects in the back, but Baidu can be specific.
So far, the root directory of the external physical machine has been automatically mounted. After restarting, ubuntu will automatically mount all the directories you selected to the address you specified, as shown below:
Step 2. Create a soft link file
The above steps complete the automatic mounting of the root directory, that is, once ubuntu is started, you can access the root directories such as D disk and E disk under the win10 system under the / mnt/win10 directory.
However, the actual shared directories are still hidden somewhere under the root directory, and if you want to access them, you have to look down layer by layer, and you have to enter a lot of paths each time, which is troublesome. Therefore, we have to create some shortcuts to achieve convenient access.
The practice is actually very simple, in the / mnt/share directory (again, the location of this directory is up to you, not required), according to your own needs, for each actual directory to create a soft link file (ln command). The specific syntax is as follows:
Ln-s / mnt/win10/drv_d/A_Download / mnt/share/tmpln-s / mnt/win10/drv_d/B_WorkItem/A_YXProjects/C_HUD_Code/imx6ul / mnt/share/wrkln-s / mnt/win10/drv_d/M_MyInstitute / mnt/share/mitln-s / mnt/win10/drv_d/S_StudyProject/G_GitArea / mnt/share/git
The final effect created is as follows:
Total amount of leon@Ubuntu:/mnt/share$ ls-l 0lrwxrwxrwx 1 leon leon 42 May 28 10:48 git-> / mnt/win10/drv_d/S_StudyProject/lrwxrwxrwx 1 leon leon 31 May 28 10:47 mit-> / mnt/win10/drv_d/M_MyInstitute/lrwxrwxrwx 1 leon leon 28 10:41 tmp-> / mnt/win10/drv_e/A_Download/lrwxrwxrwx 1 leon leon 59 May 28 10:47 wrk-> / mnt/win10/drv_e/B_WorkItem/A_Projects/C_Code/imx6ul/
The shared directory and its linked files created according to the above method have the following benefits:
1. What is mapped outside the virtual machine is the root directory of the win10 system. Even for patients like me who are obsessive-compulsive, I have the desire to organize directories and files at any time, but it is not so easy to organize the root directory. So, you don't have to worry about the fact that the directory of my win10 system will cause an exception in the shared directory mapping of the virtual machine.
2. The access channel created at last is a link file temporarily created based on the root directory under the / mnt/win10 directory. It can be changed at any time if there is any need, without having to move to the outside physical machine or worry about the conflicts between multiple physical machines. It is extremely convenient!
Summary
The above is the best way to automatically mount a shared directory for Ubuntu16.04 under Virtualbox. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to the website!
If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.