This lab demonstrates how to build a flexible, scalable Network Attached Storage (NAS) solution using Linux's Logical Volume Management (LVM) and the Samba (SMB/CIFS) protocol.
Learning Objectives
- Configure storage virtualization using Logical Volume Management (LVM).
- Understand Physical Volumes (PV), Volume Groups (VG), and Logical Volumes (LV).
- Set up and secure file shares over a network using Samba.
Prerequisites
- Linux VM (Ubuntu/Debian) with root access.
- Basic understanding of storage devices and partitions.
Step 1: Storage Pooling with LVM
LVM allows us to pool multiple physical disks into a single logical "blob" of storage that can be easily resized.
- Create Virtual Disks: We'll use loop devices to simulate 3 physical disks of 500MB each.
for i in {1..3}; do truncate -s 500M disk_$i.img; done
sudo losetup -f disk_1.img
sudo losetup -f disk_2.img
sudo losetup -f disk_3.img
# Check your devices
losetup -a
Assume the devices are /dev/loop0, /dev/loop1, and /dev/loop2.
- Initialize Physical Volumes (PV):
sudo pvcreate /dev/loop0 /dev/loop1 /dev/loop2
- Create a Volume Group (VG): This "pools" the three disks together.
sudo vgcreate nas_pool /dev/loop0 /dev/loop1 /dev/loop2
sudo vgs # Verify the pool size (~1.5GB)
- Carve out a Logical Volume (LV): This is what we will actually format.
sudo lvcreate -L 1G -n nas_data nas_pool
sudo lvs # Verify the LV
Step 2: Formatting & Persistent Mounting
- Format with XFS:
sudo mkfs.xfs /dev/nas_pool/nas_data
- Mount the storage:
sudo mkdir -p /srv/nas_share
sudo mount /dev/nas_pool/nas_data /srv/nas_share
- Make it persistent: Find the UUID and add it to
/etc/fstab.
sudo blkid /dev/nas_pool/nas_data
# Add to /etc/fstab: UUID=xxxx /srv/nas_share xfs defaults 0 2
Step 3: Samba Configuration
Now we will share this volume over the network using the SMB protocol.
- Install Samba:
sudo apt update && sudo apt install -y samba
- Configure the Share: Add the following to the end of
/etc/samba/smb.conf:
[CloudNAS]
path = /srv/nas_share
browseable = yes
read only = no
guest ok = no
valid users = @smbgroup
- Set Permissions:
sudo groupadd smbgroup
sudo chgrp smbgroup /srv/nas_share
sudo chmod 775 /srv/nas_share
Step 4: Access Control
- Create a Samba User:
sudo useradd -M -s /sbin/nologin nasuser
sudo usermod -aG smbgroup nasuser
sudo smbpasswd -a nasuser
- Restart Services:
sudo systemctl restart smbd
Step 5: Client Connection
From a secondary machine (or your host):
- Linux:
mount -t cifs -o username=nasuser //IP_ADDRESS/CloudNAS /mnt/remote_nas - Windows: Map Network Drive to
\\IP_ADDRESS\CloudNAS - Mac: Connect to Server
smb://IP_ADDRESS/CloudNAS
Test: Create a folder from the client and verify it exists on the NAS server in /srv/nas_share.
Lab Reflection
- If your NAS runs out of space, what LVM commands would you use to add a 4th disk and grow the filesystem?
- What is the difference between an SMB share and an S3 bucket in terms of how an application would use them?
- Why is LVM essential for "elastic" cloud-style storage?