Skip to content

Instantly share code, notes, and snippets.

@EnisBerk
Last active April 9, 2024 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EnisBerk/a824c2eea312b6fc56245384237bd8f5 to your computer and use it in GitHub Desktop.
Save EnisBerk/a824c2eea312b6fc56245384237bd8f5 to your computer and use it in GitHub Desktop.

Step 1: Install LVM

First, you need to make sure that LVM is installed on your Ubuntu server. You can do this by running the following command:

sudo apt-get update
sudo apt-get install lvm2

Step 2: Create a Physical Volume

The next step is to create a physical volume on your RAID disk. You can do this with the pvcreate command:

sudo pvcreate /dev/sdd

Step 3: Create a Volume Group

After creating a physical volume, you need to create a volume group. You can do this with the vgcreate command. In this example, I'll name the volume group "myvg":

sudo vgcreate myvg /dev/sdd

Step 4: Create a Logical Volume

Next, you need to create a logical volume within your volume group. You can do this with the lvcreate command. In this example, I'll create a logical volume named "mylv" that uses all available space:

sudo lvcreate -l 100%FREE -n mylv myvg

Step 5: Create an ext4 File System

Now that you have a logical volume, you can create an ext4 file system on it. You can do this with the mkfs.ext4 command:

sudo mkfs.ext4 /dev/myvg/mylv

Step 6: Mount the File System

Finally, you need to mount the file system. First, create a directory where you'll mount the file system:

sudo mkdir /tank

Then, mount the file system to this directory:

sudo mount /dev/myvg/mylv /tank

Step 7: Make the Mount Permanent

To ensure the mount persists across reboots, you'll need to add an entry to the /etc/fstab file. First, open the file with a text editor such as nano:

sudo vim /etc/fstab

Then, add the following line at the end of the file:

/dev/myvg/mylv /tank ext4 defaults 0 0

Save and close the file. Now, the file system will be mounted automatically when the system boots.

That's it! You've now set up LVM and installed an ext4 file system on your RAID disk.\

Here's how I setup data and scratch folders:

  1. Create the directories:
sudo mkdir -p /tank/scratch/enis
sudo mkdir -p /tank/scratch/jcdevaney
sudo mkdir /tank/data
  1. Change the ownership of the directories to the respective users:
sudo chown enis:enis /tank/scratch/enis
sudo chown jcdevaney:jcdevaney /tank/scratch/jcdevaney
  1. Create a new group called data:
sudo groupadd data
  1. Add the users enis and jcdevaney to the data group:
sudo usermod -a -G data enis
sudo usermod -a -G data jcdevaney
  1. Change the group ownership of the /tank/data directory to the data group:
sudo chgrp data /tank/data
  1. Set the permissions for the /tank/data directory to drwxrwsr-x. This will give the owner and group members full access, and others read and execute access. The s in the group permissions field sets the setgid bit, which means new files and directories created under /tank/data will inherit the group ownership:
sudo chmod 2775 /tank/data
  1. Symlink /tank/scratch to /scratch
cd /
sudo mkdir /scratch/ 
sudo ln -s /tank/scratch /scratch

How to extend /tank after adding a new disk to hardware RAID:

To extend your LVM volume to use the entire disk space, you need to follow these steps: (assumes disk is called /dev/sdd and logical volume is myvg-mylv)

  1. Resize the physical volume: First, you need to resize the physical volume on the disk. You can do this using the pvresize command. This command will resize the physical volume on /dev/sdd to use all available space.
sudo pvresize /dev/sdd
  1. Extend the logical volume: After resizing the physical volume, you can now extend the logical volume. You can do this using the lvextend command. This command will extend the logical volume myvg-mylv to use all available space in the volume group.
sudo lvextend -l +100%FREE /dev/myvg/mylv
  1. Resize the filesystem: Finally, you need to resize the filesystem on the logical volume to use the new space. The command to do this depends on the type of filesystem you are using.

For ext4 filesystem, you can use the resize2fs command:

sudo resize2fs /dev/myvg/mylv

After these steps, your logical volume should now be using the entire disk space. You can verify this by running the lsblk command again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment