Add remote shares or disks

You usually need to add external data to your VM's or #Proxmox It's best practices to keep VM's small and use external storage for data. iSCSI or NFS. Even SMB can be used. #SMB #CIFS #iSCSI #NFS

Add remote shares or disks
Photo by Patrick Lindenberg / Unsplash

You usually need to add external data to your VM's or to your Proxmox

Background

It's a proven best practices to keep VM's small and use external storage for data. iSCSI or NFS and even CIFS are usable to a point.

If you want to use a virtual TrueNAS you should use directly attached disks not the virtual disks. On the other hand, you should avoid using a virtual TrueNAS in production.

iSCSI is a block device interface, it's a protocol that can communicate SCSI's commands over the network. Not easy to set up but stable. It's been with us for years because it works. You can use it on servers to connect to SAN and NAS systems. It's possible to boot from a iSCSI drive (see note below).

NFS is the way to implement shared storage in Unix/Linux environments and CIFS is used with SAMBA but it is slow. iSCSI is often found in enterprise MS setups for mounting disks to PC's centrally.

Using mout points can cause confusing situations when they change.
Use UUID is safe - it newer change

Use cfdisk (be carefull) or lsblk to check your disks and partitions

Adding a disk in Proxmox

In Proxmox you can list the disks: ls -n /dev/disk/by-id

Copy the UUID you want to attach from the list and connect the disk to your VM 801

/sbin/qm set 801 -virtio2 /dev/disk/by-id/scsi-3600508b1001038393620202020200019

Uncheck Backup - backing up a big disk with the VM is not optimal


CIFS - Passing a networked share into a VM/CT

apt install cifs-utils

nano /root/.smbcred
# Enter following data
username=smbuser
password=Pa$$word
domain=mydomain

# set /smbcred access to root only
chmod 400 /root/.smbcred

# Check .smbcred access
ls -al /root/.smbcred

Make mount point directory


mkdir /mnt/testshare

#Mount the share manually
mount.cifs -v //192.168.1.200/testshare /mnt/testshare  --verbose -o credentials=/root/.smbcred

#Open fstab
nano /etc/fstab
#Add the line:
//192.168.1.200/testshare /mnt/testshare cifs credentials=/root/.smbcred 0 0

#Reboot the machine
reboot

#Test to see if share is mounted
ls /mnt/testshare

NFS - Passing a networked share into a VM/CT

You can add shares in the GUI or in the CLI. Link to Proxmox docs NFS

Proxmox Configuration Example:

# List NFS-shares on your NAS
pvesm nfsscan 10.10.10.10

# Add needed shares
nano /etc/pve/storage.cfg
nfs: iso-templates
        path /mnt/pve/iso-templates
        server 10.10.10.10
        export /space/iso-templates
        options vers=3,soft
        content iso,vztmpl

Add a NFS share to your VM

Set the shared directory to chown nobody:nogroup and chmod 777 and add them to /etc/exports like this /mnt/data 10.10.40.40(rw,sync,no_subtree_check)

sudo apt-get update
sudo apt-get install nfs-common portmap

sudo mkdir -p /mnt/projects
sudo mkdir -p /mnt/data

sudo mount 10.10.40.40:/home/data /mnt/data
sudo mount 10.10.40.40:/home/project /mnt/projects

# Check if sucsessfull
sudo df -h
# Test your apps and then make shares mounted at boot

sudo nano /etc/fstab
# Add somthig like this:

NAS1:/home/data     /mnt/data  nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
NAS1:/home/project  /mnt/projects nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

Unmount NFS Share

If you want to unmount the mounted folders, you can do so by running the umount command on client system.

sudo umount /mnt/projects
sudo umount /mnt/data

SSHFS

We can easily add files for testing by ssh, using the SFTP portion of SSH. This method is usable on Linux, Mac and Windows. Just install it

# To add a remote share
#sudo sshfs -o idmap=user [email protected]:/mnt/Data/Music ./music
sudo sshfs -o allow_other [email protected]:/mnt/Data/Music ./music

# To remove a mounted Directory
sudo fusermount -u ./music
To avoid DNS lookup delays, it is usually preferable to use an IP address instead of a DNS name - unless you have a very reliable DNS server, or list the server in the local /etc/hosts file.
NFS mount options (see man nfs). Read about version then use 3 or 4

Generic example:

https://www.howtoforge.com/tutorial/how-to-configure-nfs-storage-in-proxmox-ve/

We need som packages to be installed

  • nfs-utils are the utilities to manage the NFS server. They have to be installed on the server and client.
  • rpcbind is a daemon that allows an NFS clients to discover the port that is used by the NFS server.
  • libnfsidmap is a library to help mapping id's for NFSv4.
apt install nfs-utils libnfsidmap rpcbind

If all packages installed successfully, enable rpcbind and nfs-server services to be started when the server is booting.

systemctl enable rpcbind
systemctl enable nfs-server

iSCSI on Proxmox:

The main advantage is that you don't need any hard drives for getting a fully functional server. A diskless server will boot over the network, acquiring its disk image from the SAN/NAS. Today, a lot of systems support iSCSI but they don't really support iSCSI install and boot (only VMWare supports that). However, you can making this work on some Linux systems using a few tricks explained here: See this link.