NFS Server hosted on Virtual Linux 

Its been a long time since i posted a Tip. This came to mind after I decided to use Pihole. Pihole is a fast DNS cache with advert site filtering. As it name implies...it is designed to be hosted on a Pi running a Pi operating system. To run on Windows it must use Docker or Virtual Linux. I chose Virtual Linux. Pihole only works with a few Linux versions...and all but one are a pain to get working with Pihole. Debian / Mate is the one that made Pihole install very easily. Thats becuase it creates a real user account for Root, which can be switched too, to perform Root functions. So thats the version used here. 

The end result is an NFS server which uses a virtual drive of any size (not the 2TB as shown in the Virtualbox GUI!). To  upload media VHD is used. It can be mounted by Windows and used just like a normal drive. Windows only supports fixed size, so you have to  run the command that creates it overnight. It take a long time to create a 4TB VHD!

 

VirtualBox must be the only virtualization Windows is running. Windows own supprt must be disable in Windows Features. Open control Panel, and disable Hyper-V.

That might not be enough if Hyper-V has been in use. You must clean out its reference in the BCD using the following command via CMD:-

 bcdedit /set hypervisorlaunchtype off

 

 

Then we can install Oracle Virtual Box on Windows. That is in three parts. The core VirtualBox, an extensions ISO to add support for USB 3 etc, and a Kernel upgrade for Linux to make it VirtualBox aware.

The first two are found via the link below. The third is added once Debian is installed.

https://www.virtualbox.org/wiki/Downloads

Follow the instructions to install Virtualbox. Run VirtualBox from the desktop icon, and select Tools / Preferences.

Go to Extensions, and press the little green "+". Find and select the extensions file you downloaded.

Now select New from the Tools. Give the new build the name Debian, and VirtualBox will fill in the rest of that page for you.

Select Next, and go through the setup options ones by one. 

Double the memory allocation to 2048 

 

Double the virtual disk size. 

(ignore the name HTML..the image was taken from a demo build just to generate these images)

Again...ignore the HTML name below. You will get Debian.

Chose Bridge Mode. You will get your current Lan device.

Close setup and this is what you have. Yours will be named Debian. 

Now with virtualbox manager still running, download the Debian linux build using your browser. The one i used is the minimal net install build. It gets most of its files via the internet.

https://www.debian.org/releases/buster/debian-installer/

Now go back to the VirtualBox Manager, and select [Optical Drive]. When requested, find the downloaded Debian ISO. 

 

Now select Start, the Debian installer will be run. At this point its just uses up, down,tab and enter. I prefer the text installer, so i went down one, and enter. 

You now go through the installer as it instructs you..until it loads the desktop selector. At that point we add Mate to the list, and remove the Network Printer.

Continue the install process untill it asks to install the bootloader grub. It says it will the default drive, but then shows manual. You have to move the selection down one.

 

It will now complete the install, remove the iso from the virtual drive, and reboot. 

It should now boot all the way to the Debian login screen. We can now login into root using the password you created during install. its too early in the process to use User. 

 

The first thing are going to do is create a bigger desktop. Select System/Preference/Hardware/Displays/

Change the Resolution from the scolling list to something bigger.

 

The next thing we are going to do as root, is build into the kernel the VirtualBox Additions. Open Mate Terminal from System Tools, and follow the instructions on this link:-

https://virtualboxes.org/doc/installing-guest-additions-on-debian/

When finished, shutdown Debian from its menu options System/Shutdown/Shutdown...not VirtualBox! 

 

At this point its a good idea to create a backup. in VirtualBox Manager, go to  to  Tools, Export..amd export Debian to an ova file. If you mess things up in the rest of the build, just remove Debian and Import the backup.

Now we need to create the virtual drive for our media. In my case that was on drive D. It is a hard to find command. 

Run CMD on Windows.

Input this command:-

"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" createhd --filename d:\NFSshare.vhd --size 3700000 --format VHD --variant Fixed

In my case its for 4TB. It will take a long time. The slower the write speed of the drive, the longer it will take. It has to  be Fixed size for Windows to recognise it. Once created it will be recognised by Windows, even if bigger that the often quoted 2TB limit.  Open Disk Management, and highlight the partition hosting the VHD.  Then select Add VHD from Tools. Browse to the VHD using that tool, and select. 

 Disk Manager will now mount it as a Raw drive.  Use the left block to inistalise the drive using GPT. Then create a Simple Volume. Give it the name NFSshare.  The VHD is then in use by Windows. For VirtualBox to use it, its must be Ejected using right click in File Manager, as if its an optical disk. Now prepare Debian to use it. 

Start Debian and log in as root. Now from Places, select Home , then Up Arrow. Open the Media folder. There create a folder with your user name. Open that User folder. In that folder create a folder called NFSshare. 

 

 

 

 

Now from Places, select Home , then Up Arrow. Open the etc folder. Open the fstab file with Pluma. Add the following line at the bottom:-

/dev/sdb2 /media/john/NFSshare ntfs-3g rw,permissions 0 0. Ignore the 0 2 in the image below.  VHD's should not be maintained using standard disk tools. 0 2 instigates a disk check on mounting.  The VHD should be maintained when in use by Windows. And even then, by using Powershell. 

These commands should be used:-

 Optimize-Volume -DriveLetter G -Analyze -Verbose
Optimize-Volume -DriveLetter G -Defrag -Verbose

 

...where john is your user name. Close the editor and save. Now Reboot.../System/Shutdown/Restart/

On reboot, log into Root again.

We now need to install NFS. Open the Mate Terminal and input the following command:-

apt install nfs-kernel-server

Again Reboot...System/Shutdown/Restart

Login as Root...again.

Now from Places, select Home , then Up Arrow. Open the etc folder. Open the exports file with Pluma. Add the following line at the bottom:-

/media/john/NFSshare *(sync,insecure,no_subtree_check,no_root_squash,rw)

Mede8ers will not connect using secure ports...1024 or lower. Linux clients must work in Native Root. 

After closing the file..Shutdown...System/Shutdown/Shutdown. 

Now we change the Debian settings in VirtualBox to add the VHD. Open Storage, select add hard drive and browse for the VHD. 

 

 

Start Debian, but this time log in as your user. 

The desktop should appear, with two icons.

Your Home, and NFSshare. 

Now we need to fix the IP. Right click on the Lan icon, top right, and select Connection Information. Note the IP that DHCP has allocated. Do the same again, but select Edit Connections... 

Select Wired Connection, and then the blue Edit Icon at the bootom of that window. Select IP4, and change to Manual, fixing the IP you noted earlier.

This time..... Shutdown. System/Shutdown/Shutdown. It must not be running for the next step.

Now we prepare for the System to close using Mate Shutdown via VirtualBox itself. Otherwise when Windows closes down, VirtualBox just pulls the plug creating a corrupted journal file. 

This is another hard to find command. Open CMD in Windows:-

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" setextradata "Debian" GUI/DefaultCloseAction Shutdown

Restart Debian. 

Now try closing the VirtualBox Window with its X, top right. Mate shutdown window now appears on the linux desktop. Cancel it for now. It will take an age to shutdown using the default timer. That delay will occur on Windows shutdown. 

Open Mate Terminal, and input this command:-

gsettings set org.mate.session logout-timeout 5.

That changes it to 5 seconds. 

We now need to autologin as User when Debian is started.

Now logout as User, and logback in as Root.

Now from Places, select Home , then Up Arrow. Open the etc folder. Open the lightdm folder. Open lighdm.conf with Pluma.

Go to line 126, remove the # , and add your user name. 

Close, and reboot.

Debian should this time boot directly to user. 

Now we need to test Sharing, and create a way to move media to the share hidden inside the vhd. We must first free up the vhd by closing down the VirtualBox linux. Then mount the VHD using Disk Management as we did when it was raw. 

 Copy a test movie to the mounted VHD. Then eject the VHD as before. 

To autostart on boot.., Open virtualBox manager, and right click on Debian in the left pane. Select the Create Desktop Shortcut option. Copy the Shortcut and past in Windows Startup.

C:\Users\john_\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

 

Then reboot the PC. It will  restart the virtual linux and mount the VHD for sharing. 

 

Start your Mede8er. Goto Library, NFS..and hopefully it finds the share. Open and try to play the test movie. 

 

At this point is a good idea to  do  another Export. But it will try to backup the virtual share drive, and take an age. So before doing so remove the second virtual  drive from VirtualBox Storage. Whenever you then do an Import, you must add it back  again.  

And there you are! 

N.B 

It you need to remove a linux build using the attached share vhd, never use the Delete File option. That will go as well...all 3TB+ of it!

Only use the Remove only option. Then use File Explorer to delete the host folder in your user area. Leave the share untouched. It can be reconnected to another Linux build.