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!). I am using a 3TB Seagate Constellation ES2 drive. It should be noted the drive starts out at 16GB, and grows as needed. It would take all day to create a 3TB virtual drive!

This guide requires Windows Pro NFS Client Services for Linux to copy media to an ext4 based share rather than NTFS.  

Before you think that  excludes you, its not that  expensive to upgrade. I had to  upgrade my mini PC to stream via NFS. you  can do  so using sites like this:-

https://www.urcdkeys.com 

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.

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, reboot Debian from its menu options System/Shutdown/Restart...not VirtualBox! 

Log back in as Root.

Open Mate terminal and install Gparted

apt-get install gparted

When finished, shutdown Debian...System/Shutdown/Shutdown.

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.vdi --size 2860000  --format VDI --variant Standard

In my case its for 3TB.

The command registers the new VDI with the VirtualBox manager. We can go back to VirtualBox manager, and select Settings/Storage. 

On the Controller:SATA line, select the green "+", and then the Chose existing disk option. 

The existing disk list should now include NFSshare.vdi you just created. Select it. You now have two virtual sata drives. 

Start the Linux again from VirtualBox. When asked, login into root again.

Chose Gparted from System Tools, and select the new drive...sdb. It is a raw disk, without even MBR or GPT. 

From Device, chose Create Partition Table, and follow the instructions. When that is finished, create a full disk partition, from the Partition option. We use ext4 for greater lunix compatibility.

 

Now from Places, select Home , then Up Arrow. Open the Media folder. Open the folder with your user name. Create a new folder  called NFSshare. This is the mount point for the shared media.

Open the NFSshare folder. Right click on the blank window and change persmissons to  your user name and group. 

 

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/sdb1        /media/john/NFSshare ext4 defaults 0 2

 

...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..Reboot...System/Shutdown/Restart.

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. We now need to  turn on Windows NFS Services. 

To control access its best to create two batch  files. Place them  where your VirtualBox is stored in your user area. 

 

In NFSshare.bat put the following command:-

mount -o anon \\192.168.50.138\media\john\NFSshare Z:

Change it to match  your Linux share IP.

In disconnect.bat put the following command:-

umount Z:

Create desktop shortcuts for both.  Run NFSshare.bat to mount the share as Z:

Copy a test movie to Z: 

Then dismount Z: by running disconnect.bat.  

That can be automated on shutdown. Run gpedit via the "Type here to search". Run Group Policy Editor and add disconnect.bat as a Shutdown Script. That prevents Windows trying to auto  connect on boot, and failing.  

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 VDI 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 vdi, 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.