How to Configure SQL Server to Access USB Shared Folder in VirtualBox

In SQL Server Management Studio, you will only see the local drives available to SQL Server database engine. In this article we will take a look at the approach on how to configure SQL Server to access shared folder to perform database backup or restore commands, even further the SQL Server datafiles and logfiles can be stored on to shared folders in Oracle VirtualBox.

Install Guest Additions  

The first thing is to install guest additions if not yet as per following instructions.

Navagite to Devices->Optical Drive->Choose a disk file-> highlight “VboxGuestAdditions” file.
Then click Open.

VirtualBox Guest Addition

Double-click on this CD drive to launch the Oracle VM VirtualBox guest additional setup.

VirtualBox Guest Addition
Start guest additional installation
VirtualBox Guest Addition

Click Next and select the destination folder. It requires approx 1 MB space in the drive.

Destination folder
VirtualBox Guest Addition

In the next step, it shows the components to install.

Select components
VirtualBox Guest Addition

Reboot the VM to complete the guest additional feature for a VM.

Reboot VM
VirtualBox Guest Addition

  Set up VM Shared Folders

VM macine -> Settings->Shared Folders->Add New Shared Folder(+)->Choose Folder Path.

Click OK.

VirtualBox Shared Folder

Go to File Explorer, we can see the following expected network diagram.

Network VBOXSVR of Shared Folder

Enable xp_cmdshell Command in SQL Server

xp_cmdshell is disabled by default. so we need use sp_configure command to enable it as shown below:

EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO

EXEC sp_configure 'xp_cmdshell',1
GO
RECONFIGURE
GO

Define the Share Drive for SQL

Now we need define the shared folder with xp_cmdshell command of SQL server as below:

EXEC XP_CMDSHELL 'net use Z: \VBOXSVR\mssql'

To verify the new drive, we can use the below command that will show you all files in that newly mapped drive:

EXEC XP_CMDSHELL 'Dir Z:' 

To un-map the shared folder drive from SQL server by:

exec xp_cmdShell 'net use Z: /delete'

Test the Shared Folder Drive in SQL Server

Backup Database onto Shared Folder Drive from SSMS

SSMS backup database

SSMS backup database
SSMS backup database

Backup Database onto Shared Folder Drive by Running SQL Script

BACKUP DATABASE [AdventureWorks15] TO DISK = N'Z:\AdventureWorks15.bak'
WITH NOFORMAT, NOINIT, NAME = N'AdventureWorks15-Full Database Backup',
SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
10 percent processed.
20 percent processed.
30 percent processed.
40 percent processed.
50 percent processed.
60 percent processed.
70 percent processed.
80 percent processed.
90 percent processed.
Processed 25016 pages for database 'AdventureWorks15', file 'AdventureWorks15' on file 2.
100 percent processed.
Processed 296 pages for database 'AdventureWorks15', file 'AdventureWorks15_log' on file 2.
BACKUP DATABASE successfully processed 25312 pages in 8.847 seconds (22.352 MB/sec).
Completion time: 2020-09-21T18:07:50.3413113+10:00

Create a Database onto Shared Folder Drive

CREATE DATABASE [TestDatabase] ON (NAME = N'TestDatabase', FILENAME = N'Z:\TestDatabase.mdf', SIZE = 512MB, FILEGROWTH = 64MB) LOG ON (NAME = N'TestDatabase_log', FILENAME = N'Z:\TestDatabase_log.ldf', SIZE = 256MB, FILEGROWTH = 32MB) 
GO
Commands completed successfully.
Completion time: 2020-09-21T18:15:32.9791694+10:00

Restore Database onto Shared Folder Drive

Query the logical file names of the database from the previous backup.

RESTORE FILELISTONLY
FROM DISK = 'Z:\AdventureWorks15.bak'

Restore the backup to a new database by using the logicalname column of the previous step.

RESTORE DATABASE AdventureWorks15New
FROM DISK = 'Z:\AdventureWorks15.bak'
WITH MOVE 'AdventureWorks15' TO 'Z:\AdventureWorks15New.mdf',
MOVE 'AdventureWorks15_log' TO 'Z:\AdventureWorks15New_log.ldf'
Processed 25016 pages for database 'AdventureWorks15New', file 'AdventureWorks15' on file 1.
Processed 294 pages for database 'AdventureWorks15New', file 'AdventureWorks15_log' on file 1.
RESTORE DATABASE successfully processed 25310 pages in 5.330 seconds (37.097 MB/sec).
Completion time: 2020-09-21T18:29:04.4634020+10:00

So all works as expected. The shared folder now can be used to store backups, and also datafiles/logfiles of a SQL server.

Advertisement

ERROR: Unable to open policy //etc/selinux/targeted/policy/policy.31

When installing Oracle VirtualBox 6.1.4 Guest Addition on Linux, the following errors occur:

# mount /dev/cdrom /media/cdrom
# cd /media/cdrom

# ./VBoxLinuxAdditions.run
Verifying archive integrity… All good.
Uncompressing VirtualBox 6.1.14 Guest Additions for Linux……..
VirtualBox Guest Additions installer
Removing installed version 6.1.4 of VirtualBox Guest Additions…
Copying additional installer modules …
Installing additional modules …
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
4.14.35-1902.10.7.el7uek.x86_64.
ERROR: Can't map '//etc/selinux/targeted/policy/policy.31': Invalid argument
ERROR: Unable to open policy //etc/selinux/targeted/policy/policy.31.
libsemanage.semanage_read_policydb: Error while reading kernel policy from /etc/selinux/targeted/active/policy.kern. (No such file or directory).
OSError: No such file or directory
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted

Check ‘//etc/selinux/targeted/policy/policy.31’ file exists but zero size.

#ls -ltr //etc/selinux/targeted/policy/policy.31
-rw-r--r-- 1 root root 0 May 1 6:03 //etc/selinux/targeted/policy/policy.31

SOLUTION

Install the latest package for “selinux-policy-targeted”.

# yum install selinux-policy-targeted

Then run VirtualBox Guest Additions installer successfully.

# ./VBoxLinuxAdditions.run uninstall


# ./VBoxLinuxAdditions.run
Verifying archive integrity… All good.
Uncompressing VirtualBox 6.1.14 Guest Additions for Linux……..
VirtualBox Guest Additions installer
Copying additional installer modules …
Installing additional modules …
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
4.14.35-1902.10.7.el7uek.x86_64.
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted

How to Install SQL Server 2019 on Windows Server 2019 VM of VirtualBox

After Windows server 2019 Oracle VirtualBox VM has been created as per How to Install Windows Server 2019 on Oracle VirtualBox,  now it is time to install SQL server 2019.

Subscribe to get access

Read more of this content when you subscribe today.

How to Install Windows Server 2019 on Oracle VirtualBox

This post illustrates step by step on how to build a Windows Server 2019 evaluation VM server on Oracle VirtualBox, also screenshots are provided for every step in details.

Subscribe to get access

Read more of this content when you subscribe today.

To log in, press the host key plus the Delete key to simulate the CTRL + ALT + DELETE key combination. The host key is the right-CTRL key by default.

VirtualBox shared folder is not working, Kernel headers not found for target kernel, Unable to Install Guest Additions on Oracle Linux 7.7

VirtualBox shared folder is not working, and the VirtualBOx shows below warning message:

“The VirtualBox Guest Additions do not appear to be available on this virtual machine, and shared folders cannot be used without them. to use shared folders inside the virtual machine, please install the Guest Additions in they are not installed, or re-install them if they are not working properly, by selecting Insert Guest Additions CD image from the Devices menu. if they are installed but the machine is not yet fully started then shared folders will be available once it.”

VirtualBox Guest Additions Error
VirtualBox Guest Additions Error

After selecting Insert Guest Additions CD image from the Devices menu, we can see the Additions CD images are mounted.

Insert Guest Additions CD image
Insert Guest Additions CD image

But the shared folder is still not working.

[root@racnode1 media]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.8G     0  4.8G   0% /dev
tmpfs                2.0G  645M  1.4G  32% /dev/shm
tmpfs                4.8G  8.6M  4.8G   1% /run
tmpfs                4.8G     0  4.8G   0% /sys/fs/cgroup
/dev/mapper/ol-root   61G   33G   29G  53% /
/dev/sda1            497M  120M  377M  25% /boot
tmpfs                973M     0  973M   0% /run/user/0
[root@racnode1 media]#

Now we manually mount the Additions CD images:

[root@racnode1 ~]# mount /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only
[root@racnode1 ~]#

Install Guest Additions CD Image manually with errors.

[root@racnode1 ~]# cd /media/cdrom
[root@racnode1 cdrom]# ls -ltr
total 45524
-r--r--r-- 1 root root 763 Mar 13 2019 AUTORUN.INF
-r-xr-xr-x 1 root root 6384 Mar 13 2019 autorun.sh
-r-xr-xr-x 1 root root 4821 Mar 13 2019 runasroot.sh
-r-xr-xr-x 1 root root 270616 Jan 13 22:08 VBoxWindowsAdditions.exe
-r-xr-xr-x 1 root root 9795088 Jan 13 22:09 VBoxWindowsAdditions-x86.exe
-r-xr-xr-x 1 root root 16776232 Jan 13 22:12 VBoxWindowsAdditions-amd64.exe
-r-xr-xr-x 1 root root 3949 Jan 13 22:21 VBoxDarwinAdditionsUninstall.tool
-r--r--r-- 1 root root 3744169 Jan 13 22:21 VBoxDarwinAdditions.pkg
-r-xr-xr-x 1 root root 6716837 Jan 13 22:21 VBoxLinuxAdditions.run
-r--r--r-- 1 root root 9287680 Jan 13 22:22 VBoxSolarisAdditions.pkg
-r--r--r-- 1 root root 547 Jan 13 22:26 TRANS.TBL
dr-xr-xr-x 2 root root 2652 Jan 13 22:26 OS2
dr-xr-xr-x 2 root root 1824 Jan 13 22:26 NT3x
dr-xr-xr-x 2 root root 792 Jan 13 22:26 cert

[root@racnode1 cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.1.2 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 5.0.10 of VirtualBox Guest Additions...
Removing existing VirtualBox non-DKMS kernel modules[ OK ]
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Kernel headers not found for target kernel
4.14.35-1902.8.4.el7uek.x86_64. Please install them and execute
/sbin/rcvboxadd setup
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
[root@racnode1 cdrom]#

There is no 4.14.35-1902.8.4.el7uek.x86_64 kernel header.

[root@racnode1 ~]# ls -ltr /usr/src/kernels/
drwxr-xr-x  3 root root   20 Jan  6 15:33 3.10.0-327.el7.x86_64
drwxr-xr-x  3 root root   20 Jan  6 15:33 3.10.0-229.el7.x86_64
[root@racnode1 ~]#

Ignore the misleading messages in /var/log/vboxadd-setup.log.

[root@racnode1 ~]# cat /var/log/vboxadd-setup.log
Could not find the X.Org or XFree86 Window System, skipping.

Check and install the following missing packages:

[root@racnode1 tmp]# yum install kernel-header* glibc-header*  
glibc-devel*  gcc-4* cpp*  kernel-uek-devel*

Then install Guest Additions again successfully.

[root@racnode1 cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.1.2 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 6.1.2 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
4.14.35-1902.10.7.el7uek.x86_64.
[root@racnode1 cdrom]#
[root@racnode1 ~]# ls -ltr /usr/src/kernels/
drwxr-xr-x  3 root root   20 Jan  6 15:33 3.10.0-327.el7.x86_64
drwxr-xr-x  3 root root   20 Jan  6 15:33 3.10.0-229.el7.x86_64
drwxr-xr-x 24 root root 4096 Feb 23 02:54 4.14.35-1902.10.7.el7uek.x86_64
[root@racnode1 ~]#

And the shared folders are working now.

[root@racnode1 ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
...
..
.
/dev/sr0              57M   57M     0 100% /media/cdrom
12.2.0.1             932G  488G  444G  53% /media/sf_Software

[root@racnode1 ~]#

Appendix

Upgrade VirtualBox Additions from VirtualBox 6.1.2 to 6.1.4 successfully.

[root@racnode1 cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.1.4 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 6.1.2 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
4.14.35-1902.10.7.el7uek.x86_64.
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted
[root@racnode1 cdrom]#