LVM – Setup and configure Filesystems in RHEL 6/Centos 6 – Part 4

Welcome to Part 4 of this series of 4 articles detailing how to setup and configure multiple filesystems running on LVM partitions. Each article will cover a specific topic, per the below:

Part 1 – Setup and configure Physical Volumes
Part 2 – Setup and configure Volume Groups
Part 3 – Setup and configure Logical Volumes
Part 4 – Setup and configure Filesystems

In Part 4 we are going to we will:

  • Format the logical volumes with the ext4 filesystem.
  • Mount the logical volumes create in Part 3 as filesystems.
  • Add these filesystems into /etc/fstab to ensure they are mounted during the boot process.

To format the music logical volume with the ext4 filesystem run:

mkfs.ext4 /dev/data/music

The resulting output is:

[root@lnx-svr-01 ~]# mkfs.ext4 /dev/data/music
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@lnx-svr-01 ~]#

Perform the same steps for the video and pictures logical volumes.

Now that the filesystems have been created, we need to mount them. First, We will create the folders upon which the filesystems will be mounted, their relationships to the corresponding folders (mount point) is:

music -------> /var/music
video -------> /var/video
pictures ----> /var/pictures

Run mkdir to create the folder above:

mkdir /var/music /var/video /var/pictures

Mount the newly created filesystems by running the mount command per the below:

mount /dev/data/music /var/music
mount /dev/data/video /var/video
mount /dev/data/pictures /var/pictures

Then run df -h to see the currently mounted filesystems:

[root@lnx-svr-01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       18G  903M   16G   6% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             477M   25M  427M   6% /boot
/dev/mapper/data-music
                      9.8G   23M  9.2G   1% /var/music
/dev/mapper/data-video
                      4.8G   10M  4.6G   1% /var/video
/dev/mapper/data-pictures
                      4.8G   10M  4.6G   1% /var/pictures
[root@lnx-svr-01 ~]#

We can see from the above that our filesystems are listed and mounted. However, we mounted the filesystems manually, we need them to mount automatically when the system boots up, so in order to enable this we need to add them to /etc/fstab.

So to proceed, run vi to edit /etc/fstab:

vi /etc/fstab

This is what is looks like at present:

# /etc/fstab
# Created by anaconda on Sat May 30 19:17:27 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=db505cff-1d69-4f12-b22a-9d4335dc2275 /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

Add the following lines into the file:

/dev/data/music         /var/music              ext4    rw,noatime      0 0
/dev/data/video         /var/video              ext4    rw,noatime      0 0
/dev/data/pictures      /var/pictures           ext4    rw,noatime      0 0

So it looks like this:

# /etc/fstab
# Created by anaconda on Sat May 30 19:17:27 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=db505cff-1d69-4f12-b22a-9d4335dc2275 /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/data/music         /var/music              ext4    rw,noatime      0 0
/dev/data/video         /var/video              ext4    rw,noatime      0 0
/dev/data/pictures      /var/pictures           ext4    rw,noatime      0 0

Save and exit the file, then reboot the system by running the shutdown command per the below:

[root@lnx-svr-01 ~]# shutdown -r now

Broadcast message from root@lnx-svr-01.vsysad.local
        (/dev/pts/0) at 14:35 ...

The system is going down for reboot NOW!
[root@lnx-svr-01 ~]#

Once the server comes back up, login and run df -h to confirm that all of our filesystems are mounted:

[root@lnx-svr-01 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       18G  903M   16G   6% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             477M   25M  427M   6% /boot
/dev/mapper/data-music
                      9.8G   23M  9.2G   1% /var/music
/dev/mapper/data-video
                      4.8G   10M  4.6G   1% /var/video
/dev/mapper/data-pictures
                      4.8G   10M  4.6G   1% /var/pictures
[root@lnx-svr-01 ~]#

There we have it, three filesystems running on LVM partitions which are ready for production use. I hope this was easy to follow and understand. Please also take time to read the references at the bottom, they are excellent resources and were bookmarked by myself for reference whenever I needed to check anything LVM related.

References:
How to Create LVM Partition in RHEL 6 / CentoOS
Linux Basics – LVM (Logical Volume Manager) Tutorial
How to Install LVM on Linux and Disk Operations
A Beginner’s Guide To LVM
How To Create LVM Using vgcreate, lvcreate, and lvextend lvm2 Commands

LVM – Setup and configure Logical Volumes in RHEL 6/Centos 6 – Part 3

Welcome to Part 3 of this series of 4 articles detailing how to setup and configure multiple filesystems running on LVM partitions. Each article will cover a specific topic, per the below:

Part 1 – Setup and configure Physical Volumes
Part 2 – Setup and configure Volume Groups
Part 3 – Setup and configure Logical Volumes
Part 4 – Setup and configure Filesystems

In Part 3 we are going to create the logical volumes within our data volume group. The logical groups to be created are:

music (10GB)
video (5GB)
pictures (5GB)

So to proceed, run the lvcreate command per the below:

lvcreate --name music --size 10G data

The output will be:

[root@lnx-svr-01 ~]# lvcreate --name music --size 10G data
  Logical volume "music" created

Perform the same commands in order to create the video and pictures logical volumes:

lvcreate --name video --size 5G data
lvcreate --name pictures --size 5G data

Please note that there was insufficient space on the data volume group to fit the picture logical volume:

[root@lnx-svr-01 ~]# lvcreate --name pictures --size 5G data
  Volume group "data" has insufficient free space (1274 extents): 1280 required.
[root@lnx-svr-01 ~]#

But as you can see from the above it confirms that there are only 1274 extents available. So we can run lvcreate with the -l option:

[root@lnx-svr-01 ~]# lvcreate --name pictures -l 1274 data
  Logical volume "pictures" created
[root@lnx-svr-01 ~]#

Here I have stated that I want the pictures volume group to be laid down on exactly 1274 extents. Alternatively, I could have run the following command to achieve the same result:

lvcreate -l 100%FREE -n pictures data

The above command will simple use all remaining space for the logical volume creation.

Now run lvdisplay to view all logical volumes:

[root@lnx-svr-01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/data/music
  LV Name                music
  VG Name                data
  LV UUID                Vpq1Tk-j7wj-6WTi-37bZ-3KQx-AJRA-fUuELr
  LV Write Access        read/write
  LV Creation host, time lnx-svr-01.vsysad.local, 2015-06-11 13:03:20 +0100
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/data/pictures
  LV Name                pictures
  VG Name                data
  LV UUID                TzB4Gd-ZjYo-4YBD-mRVb-zFek-7j91-pIjzQo
  LV Write Access        read/write
  LV Creation host, time lnx-svr-01.vsysad.local, 2015-06-11 13:17:30 +0100
  LV Status              available
  # open                 1
  LV Size                4.98 GiB
  Current LE             1274
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/data/video
  LV Name                video
  VG Name                data
  LV UUID                YPv1jQ-sneY-ee20-aSq3-J3qQ-zivI-WeJkSN
  LV Write Access        read/write
  LV Creation host, time lnx-svr-01.vsysad.local, 2015-06-11 13:35:43 +0100
  LV Status              available
  # open                 1
  LV Size                5.00 GiB
  Current LE             1280
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:4

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                tYZOe0-bhSb-G0fL-7RWK-Vzwq-BG8H-AZyZL9
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-05-30 19:17:03 +0100
  LV Status              available
  # open                 1
  LV Size                17.51 GiB
  Current LE             4482
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_swap
  LV Name                lv_swap
  VG Name                VolGroup
  LV UUID                QWeze3-c0cy-dwui-6BkI-LDkc-VSun-7W7yuK
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-05-30 19:17:25 +0100
  LV Status              available
  # open                 1
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@lnx-svr-01 ~]#

The logical volumes we created; music, video and pictures are visible. We can run lvscan to view a more concise listing of logical volumes:

[root@lnx-svr-01 ~]# lvscan
  ACTIVE            '/dev/data/music' [10.00 GiB] inherit
  ACTIVE            '/dev/data/pictures' [4.98 GiB] inherit
  ACTIVE            '/dev/data/video' [5.00 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_root' [17.51 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_swap' [2.00 GiB] inherit
[root@lnx-svr-01 ~]#

To rename a logical volume run the lvrename command:

lvrename data video movies

The output would be:

[root@lnx-svr-01 ~]# lvrename data video movies
Renamed "video" to "movies" in volume group "data"
[root@lnx-svr-01 ~]#

To delete a logical volume run the lvremove command:

lvremove /dev/data/video

The result would be:

[root@lnx-svr-01 ~]# lvremove /dev/data/video
Do you really want to remove active logical volume video? [y/n]: y
Logical volume "video" successfully removed
[root@lnx-svr-01 ~]#

The lvrename and lvremove examples were for your reference only, there is no need to run them.

This is then end of Part 3. Please go to Part 4, to setup and configure Filesystems.

References:
How to Create LVM Partition in RHEL 6 / CentoOS
Linux Basics – LVM (Logical Volume Manager) Tutorial
How to Install LVM on Linux and Disk Operations
A Beginner’s Guide To LVM
How To Create LVM Using vgcreate, lvcreate, and lvextend lvm2 Commands