[LINUX] How to set a shared folder with the host OS in CentOS7 on VirtualBOX

Introduction

Nice to meet you. It is called "Snorlax". I usually work as a data scientist at a financial institution who doesn't try to understand the business. I would like to keep a record of my struggle as the first article of Qiita.

Background of writing

When studying Docker on Udemy, I needed to set up a shared folder for VirtualBox (host OS ⇔ guest OS), and I fell in love with it. Although there are articles by the pioneers, none of them can be solved as they are, and after learning the ensemble of various information, the settings have been made, so I will write them here including a memorandum. I hope it helps those who are referred to.

Execution environment

(Host OS) Windows10 pro (Guest OS:virtual)CentOS7.7 (1908) CLI (Virtualization)VirtualBox 6.1.8-137981 Trial time: 2020/05/28

procedure

It omits from CentOS installation to startup.

In VirtualBox, there are setting items that seem to be very kind, such as [Settings]> [Shared Folder], and I wondered if I could do it by specifying the folder of the host OS here. Before setting up shared folders in VirtualBox You have to set up something called "Guest Additions".

The flow is explained below.

GetAdditions setting eve (package update)

After moving to root privileges with su Update the packages and install the required packages.

yum -y update
yum -y install kernel-devel kernel-headers gcc gcc-c++
yum -y install bzip2

If you start with kernel-devel and kernel-headers, it will be inconsistent with existing kernels that have not been updated, so update the kernel (included in yum -y update) first. It makes sense to do it.

We recommend that you install bzip2 here as you will need it later.

Once the above steps are complete, use reboot to *** reboot ***!

Installing Guest Additions

(After restarting, use the su command to transfer to root privileges.)

GuestAdditions are installed in the iso image format, but they are included as standard in VirtualBox without any special acquisition.

Insert ISO image

Select [Device]> [Insert Guest Additions CD Image ...] in VirtualBox and connect. ss1.png

Installation

Mount the connected disk image in the media folder in CentOS.

mount -r /dev/cdrom /media

Go to the media folder and After the mount is complete, run the installation from the mount image. The bzip2 package is required for VBoxLinuxAdditions.run to be done here.

cd /media
sh ./VBoxLinuxAdditions.run

After the installation is complete, unmount the image and reboot ***.

cd
umount /media
reboot

Unmounting can also be done from the GUI. ss2.png

Shared folder settings

After returning from the restart, from [Device]> [Shared Folder]> [Shared Folder Settings] Set the folder you want to share in the host OS (Windows this time). ss3.png

Select [Shared Folder Settings] to move to the window below. ss4.png Select "Shared Folder" and press the Add New button on the right. ss5.png Select any folder. (This time, the folder name is docker_file) Also,

-[x] Auto mount (A) -[x] Persist (M)

Check the box and press [OK] to close.

Now, in the guest OS (CentOS), it will be shared as / media / sf_ {shared folder name} in this case, / media / sf_docker_file.

Mount shared folders

If you want to mount other than / media / sf_ {shared folder name} above,

su
cd media/
mount -t vboxsf sf_{Shared folder name} {Mount destination directory name}
reboot

With, you can make another folder a shared folder in the guest OS.

Access restriction settings

With the above steps, the shared folder will be available to the root user, but if you want to give other general users access to the shared folder, add the user with the following command.

su
gpasswd --add {User name} vboxsf

Related article

I have referred to each article very much, and some parts have been quoted. If you find it annoying, I would appreciate it if you could point it out.

--Install Guest Additions on Linux on VirtualBox and set shared folders

-How to create a shared folder between the host OS and guest OS (Ubuntu) in VirtualBox

Reference site

-How to create a shared folder with Guest Additions on CentOS, the guest OS with VirtualBox

Recommended Posts

How to set a shared folder with the host OS in CentOS7 on VirtualBOX
How to send a file in one shot by connecting to a host on the other side of the platform with SCP in multiple stages
[Python] Get the files in a folder with Python
How to get the files in the [Python] folder
[2015/11/19] How to register a service locally using the python SDK on naoqi os
How to publish a blog on Amazon S3 with the static Blog engine'Pelican'for Pythonista
How to drop Google Docs in one folder in a .txt file with python
How to get a list of files in the same directory with python
How to convert / restore a string with [] in python
How to create a submenu with the [Blender] plugin
How to install caffe on OS X with macports
A memorandum on how to use keras.preprocessing.image in Keras
How to identify the element with the smallest number of characters in a Python list?
A memo on how to overcome the difficult problem of capturing FX with AI
Define a task to set the fabric env in YAML
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
How to output a document in pdf format with Sphinx
How to use the __call__ method in a Python class
How to set the html class attribute in Django's forms.py
How to manipulate the DOM in an iframe with Selenium
A note on how to load a virtual environment in PyCharm
Process the files in the folder in order with a shell script
How to generate a query using the IN operator in Django
How to get the last (last) value in a list in Python
A story about how to deal with the CORS problem
Connect to centos6 on virtualbox with ssh connection from Mac
Notes on how to use marshmallow in the schema library
How to install Theano on Mac OS X with homebrew
[Cyberduck] How to exchange files on Linux (CentOS7) started by VirtualBox with mac using GUI
Recursively get the Excel list in a specific folder with python and write it to Excel.
How to set the output resolution for each keyframe in Blender
How is the progress? Let's get on with the boom ?? in Python
[Django Learned with the Devil's Blade] How to get a query set for forward / reverse reference
[sh] How to store the command execution result in a variable
How to determine the existence of a selenium element in Python
A note on how to check the connection to the license server port
How to get all the possible values in a regular expression
[Introduction to Python] How to split a character string with the split function
How easy is it to synthesize a drug on the market?
How to check the memory size of a variable in Python
Steps to install VirtualBox on CentOS
How to make a command to read the configuration file with pyramid
Output the contents of ~ .xlsx in the folder to HTML with Python
How to customize U-Boot with OSD335X on a custom board (memo)
How to create a heatmap with an arbitrary domain in Python
For those of you who don't know how to set a password with Jupyter on Docker
How to use python put in pyenv on macOS with PyCall
[Introduction to Python] How to use the in operator in a for statement?
How to check the memory size of a dictionary in Python
How to install PyPy on CentOS
How to combine all CSVs in a folder into one CSV
How to install TensorFlow on CentOS 7
How to get the vertex coordinates of a feature in ArcPy
How to deploy a Django app on heroku in just 5 minutes
How to install Maven on CentOS
How to send a request to the DMM (FANZA) API with python
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
[Python] What is a formal argument? How to set the initial value
[Small story] How to save matplotlib graphs in a batch with Jupyter
Think about how to write a filter with the Shotgun API-Contact Versions
A memo organized by renaming the file names in the folder with python