I'm new here and found this old question and didn't like the answer given, so I thought I'd add my two cents.
First, there's a bit of mis-information on 'properly' setting up LVM around how to prepare the physical disk.
The video shows using a raw device such as /dev/sdb and adding that to a volume group. On real hardware, NEVER do this. The short answer here is that you want your filesystem blocks to align with your backend storage blocks, else you will suffer from worse performance than if you do this properly. You'll really notice this if you're using a SAN or EBS on AWS. If you're on an SSD, you're less likely to notice at all unless you're running the maximum IOPS the device can support.
So, in your question, you have /srv/samba. If that is on the same physical device as your / mount, then we're going to have to do some moving of data after adding a drive. That's easy. I'll go ahead and assume that is the case.
Add a new physical drive. We'll assume here that your existing drive is /dev/sda (and on it you have multiple partitions). Your new drive we will assume is now /dev/sdb. Please be sure you KNOW what the new device name is, or you're going to have a bad day when we erase it in a moment.
You can double-check the devices you have by using either cat /proc/partitions
to see what partitions your OS recognizes, or run lsblk
for an excellent view of your devices and where they are mounted. Use this information to be sure you are configuring the correct device.
To prepare the new disk, we need to partition it. Here's the part the video missed. If the new disk is more than 2TB, you can use fdisk without an issue, and you'll need to use the new GPT partition. Newer versions of fdisk know about GPT, which will allow you to partition a disk larger than 2TB. If you don't have a newer system with the fdisk that knows about GPT, then you'll want to use something like parted.
sudo fdisk /dev/sdb
Now that you're in fdisk editing the new disk you've added, let's add a GPT partition to this disk.
Menu option 'g' will set up a GPT instead of a MBR partition table which is required for all drives larger than 2TB. This also puts fdisk in GPT mode.
Then we want to add a new partition, so press menu option 'n'.
Take the default partition of '1' by pressing 'ENTER'.
Here's where fdisk will detect the block alignment of the device. For most storage options, it will default to sector 2048 as the beginning sector of the new partition.
Take the default by pressing 'ENTER'.
If you want to use all of the free space on the disk, this is the default, so press 'ENTER'.
The new partition is created and ready to be written to disk, but we want to mark it with the LVM type, not the default Linux filesystem type. Press menu option 't' to change the type, and specify type '15' which is the Linux LVM type in GPT mode. (It is type '8e' in MBR mode). When you press 'ENTER' you're ready to write the changes to disk by pressing menu option 'w' and 'ENTER'.
You can confirm the changes were written to disk by using sudo fdisk -l /dev/sdb
(that's the lower-case L) and examine the output. Here's mine:
Disk /dev/sdb: 2199.0 GB, 2199022206976 bytes, 4294965248 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Start End Size Type Name
1 2048 4294965214 2T Linux LVM
(I only have a 2TB partition because that's the maximum my VM host will allow)
Your kernel may or may not pick up the new disk partition. Check to see if /dev/sdb1 shows up in the output of cat /proc/partitions
or lsblk
. If it does, you're golden. If it doesn't, try running sudo partprobe
to see if it shows up. If it still doesn't show up, reboot, and then it should be there.
Here's where we tag the new partition as a LVM physical volume.
sudo pvcreate /dev/sdb1
- this writes the meta-data to the disk so LVM will identify it as a member disk.
The next step assumes you do NOT already have LVM configured to use a Volume Group. If you do, you don't need to create a new one, so skip this step:
sudo vgcreate sambadata /dev/sdb1
Now we have a Volume Group named 'sambadata'.
Next step is to create a Logical Volume in the Volume Group. This is where we will lay our filesystem.
sudo lvcreate -n sambalv --extents 100%VG sambadata
Next, create your filesystem of choice. If you want to use xfs, for example:
sudo mkfs -t xfs -L samba -i maxpct=100 /dev/mapper/sambadata-sambalv
You now have a mountable filesystem on device /dev/mapper/sambadata-sambalv that you can later grow larger as you add more drives.
Let's mount this somewhere so I can move all my existing data onto it:
sudo mkdir -p /mnt/sambatmp
sudo mount /dev/mapper/sambadata-sambalv /mnt/sambatmp/
To get all the data sync'd up to the new location, I use rsync. The reason for this is that I can leave Samba running while these files get copied, so if I have a lot of data, I don't have to take the server down while I'm moving data. (This will slow down the server significantly.)
You can always press 'CTRL-C' to interrupt the rsync process and restart it later.
sudo rsync --delete -av /srv/samba/. /mnt/sambatmp/
I put the '--delete' in there so when I run it again later, it will remove any files from the new location that were deleted from /srv/samba. The -a preserves ownership, permissions, timestamps, etc.
Once this command completes, the samba server will need to be stopped to make sure files aren't changing (and this will detach any active Windows mounts). Then, let's run a final rsync and move the existing files out of the way so I can mount the new disk in place:
sudo rsync --delete -av /srv/samba/. /mnt/sambatmp/
sudo umount /mnt/sambatmp
sudo mv /srv/samba /srv/samba-old
sudo mkdir /srv/samba
sudo mount /dev/mapper/sambadata-sambalv /srv/samba
Restart your samba server to use the new LV on the newly added disk.
Finally, update your /etc/fstab to mount /dev/mapper/sambadata-sambalv at the /srv/samba location using the options you want. This is necessary so that your new disk's LV will be mounted after a reboot.
The added line might look something like this:
/dev/mapper/sambadata-sambalv /srv/samba xfs rw,relatime,seclabel,attr2,inode64,noquota 0 0
Since we moved the /mnt/samba to /mnt/samba-old, all of your original files are here. Once you're sure the new mointpoint is all happy, you can delete this directory and recover all of that used space.
sudo rm -R /srv/samba-old