Skip to main content

Introduction

Setting up an Ubuntu virtual machine (VM) with Logical Volume Management (LVM) storage and Network File System (NFS) shares can enhance your system’s flexibility and scalability. This guide provides a step-by-step approach to configuring an Ubuntu VM with LVM for efficient storage management and NFS for sharing files across the network.
PrerequisitesBefore you begin, ensure you have the following prerequisites:
  • A preferred virtualization platform (e.g., VirtualBox, VMware, KVM).
  • An Ubuntu ISO image for installation.
  • Basic knowledge of Linux command line and system administration.

Server Setup

1

Installing Ubuntu VM

  1. Create a new virtual machine in your chosen virtualization platform.
  2. Allocate sufficient resources (CPU, RAM, Disk Space) based on your requirements.
  3. Mount the Ubuntu ISO image and start the VM.
  4. Follow the on-screen instructions to install Ubuntu, ensuring you set up a user account and password.
  5. In the installation process keep the unallocated or free space as it is.
  6. Complete the installation and reboot the VM.
2

Enable remote root access

Open a terminal in your Ubuntu VM and use the below command to set the root password:
3

Command to enable remote root login

Step 3: Install root CA certificates in the trust store

  1. Copy the root CA certificate file (e.g., my-ca.crt) to the /usr/local/share/ca-certificates/ directory.
  1. Update the CA certificates:

Step 4: Setting Up LVM Storage

  1. Show the availabls space using below command
you will see the free space in the VG like below:
  1. to see the absolute free space use below command
you will see the free space in the PV like below:
  1. Create a new logical volume (LV) using the free space:
It will create a LV named nfs-share with 300GB size. give the terminal output like below:
  1. Format the new LV with a filesystem (e.g., xfs):
you will see the terminal output like below:
  1. Create a mount point and mount the LV:
  1. To make the mount persistent across reboots, add an entry to /etc/fstab:
It will append the fstab file with the new entry. and command output like below:

Step 5: Setting Up NFS Shares

  1. Install NFS server packages:
  1. Check the status of NFS server:
  1. Configure NFS exports by editing the /etc/exports file:
This command will append the exports file with the new NFS share configuration. The output will be:
  1. Apply the export changes:
  1. Adjust firewall settings to allow NFS traffic (if applicable):
  1. Verify NFS exports:
You should see output similar to:
  1. Set proper permissions on the NFS share directory:

Connect from Client Machine

  1. On the client machine, install NFS client packages:
  1. check avaiable shares from the NFS server:
You should see the exported shares from the server. 3. Create a mount point on the client machine:
  1. Mount the NFS share from the server:
  1. To make the NFS mount persistent across reboots, add an entry to /etc/fstab on the client machine:
This command will append the fstab file with the new NFS mount entry. The output will be:
  1. Unmount the NFS share when done:

Mount using autofs (optional)

  1. We dont need to add directory in the fstab file. Instead we will use autofs to mount the NFS share on demand.
  2. Install autofs package:
  1. Check the status of autofs service:
  1. Edit the autofs master configuration file /etc/auto.master to add a new map file:
This command will append the auto.master file with the new map file entry. The output will be:
For docker swarm it will be better if we add below permissions:
Why these extra flags matter for Docker:
  • nolock: Prevents the NFS client and server from trying to coordinate file locks, which often fail when multiple containers or nodes access the same share.
  • soft: If the NFS server goes down, the client will eventually report an error instead of hanging the entire Linux process (and your Docker service) forever.
  • tcp: Forces the use of TCP, which is more stable for Docker traffic than UDP.
  • intr: Allows NFS requests to be interrupted if the server stops responding.
  1. Create the map file /etc/auto.nfs with the NFS share details:
This command will create the auto.nfs file with the NFS share configuration. The output will be:
  1. Restart the autofs service to apply the changes:
  1. check the mounts:
You should see output similar to:
  1. Access the NFS share:
  1. watch the autofs logs for any issues:

Allow ip to access NFS share through firewall

If you have UFW enabled on your Ubuntu VM, you need to allow the IP address or subnet of the client machines to access the NFS share. Use the following command to allow access:
Replace <CLIENT_IP_OR_SUBNET> with the actual IP address or subnet of the client machines.

Extend the LVM Storage (if needed)

If you need to extend the LVM storage in the future, follow these steps:
  1. Ad disk to the VM through your virtualization platform.
  2. Run lsblk to identify the new disk (e.g., /dev/sdb).
You should see output similar to:
  1. Create a physical volume (PV) on the new disk:
You should see output similar to:
  1. Extend the existing volume group (VG) to include the new PV:
You should see output similar to:
  1. Extend the logical volume (LV) to use the additional space:
You should see output similar to:
  1. Verify the new size of the LV:
You should see output similar to:

Troubleshooting

If you encounter issues during the setup process, consider the following troubleshooting steps:
  1. Check NFS server status:
  1. Verify NFS exports:
  1. Review system logs for errors:
  1. Ensure firewall rules are correctly configured to allow NFS traffic.
  2. Verify LVM configuration:

Conclusion

By following this guide, you have successfully set up an Ubuntu virtual machine with LVM storage and NFS shares. This configuration provides a flexible and scalable storage solution that can be easily managed and expanded as needed. Enjoy your new Ubuntu VM setup!