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
- Create a new virtual machine in your chosen virtualization platform.
- Allocate sufficient resources (CPU, RAM, Disk Space) based on your requirements.
- Mount the Ubuntu ISO image and start the VM.
- Follow the on-screen instructions to install Ubuntu, ensuring you set up a user account and password.
- In the installation process keep the unallocated or free space as it is.
- 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
- Copy the root CA certificate file (e.g.,
my-ca.crt) to the/usr/local/share/ca-certificates/directory.
- Update the CA certificates:
Step 4: Setting Up LVM Storage
- Show the availabls space using below command
- to see the absolute free space use below command
- Create a new logical volume (LV) using the free space:
- Format the new LV with a filesystem (e.g., xfs):
- Create a mount point and mount the LV:
- To make the mount persistent across reboots, add an entry to
/etc/fstab:
Step 5: Setting Up NFS Shares
- Install NFS server packages:
- Check the status of NFS server:
- Configure NFS exports by editing the
/etc/exportsfile:
- Apply the export changes:
- Adjust firewall settings to allow NFS traffic (if applicable):
- Verify NFS exports:
- Set proper permissions on the NFS share directory:
Connect from Client Machine
- On the client machine, install NFS client packages:
- check avaiable shares from the NFS server:
- Mount the NFS share from the server:
- To make the NFS mount persistent across reboots, add an entry to
/etc/fstabon the client machine:
- Unmount the NFS share when done:
Mount using autofs (optional)
- We dont need to add directory in the fstab file. Instead we will use autofs to mount the NFS share on demand.
- Install autofs package:
- Check the status of autofs service:
- Edit the autofs master configuration file
/etc/auto.masterto add a new map file:
- 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.
- Create the map file
/etc/auto.nfswith the NFS share details:
- Restart the autofs service to apply the changes:
- check the mounts:
- Access the NFS share:
- 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:<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:- Ad disk to the VM through your virtualization platform.
- Run lsblk to identify the new disk (e.g., /dev/sdb).
- Create a physical volume (PV) on the new disk:
- Extend the existing volume group (VG) to include the new PV:
- Extend the logical volume (LV) to use the additional space:
- Verify the new size of the LV:
Troubleshooting
If you encounter issues during the setup process, consider the following troubleshooting steps:- Check NFS server status:
- Verify NFS exports:
- Review system logs for errors:
- Ensure firewall rules are correctly configured to allow NFS traffic.
- Verify LVM configuration: