0

LFCS filesystem & storage part 2

Welcome to post 21 of my 100 day challenge. Checkout my introduction for some background.

This is post six of my LFCS series. This post is the second part of file system and storage. In it I will be discussing Logical Volume Management. For the first part see post 5.

You can go back to the overview post for a brief introduction or take a look at post one for instructions on setting up the exam practice system which I will be using throughout this series. For the posts regarding the Linux Command Line see posts 2, 3 and 4.

LFCS filesystem & storage part 2

Logical Volume Management (LVM)

LVM is a technology used for clustering disks together into a larger volume or group of volumes. It’s biggest advantage over conventional partitioning methods is that the volumes can easily be resized after the fact. Which isn’t the case with other storage mechanisms and saves you the effort of calculating how much storage you need during the installation of the host operating system.

LVM is a software layer on top of the physical hardware creating a layer of abstraction and consistency.

It is often grouped with RAID as they share functionality but they are not the same. LVM is for clustering disks, turning Physical Volumes into Volume Groups, the volume groups are then mapped to Logical Volumes that the operating system interprets as partitions.

LVM functionality is already available in our CentOS 6.4 VM. You can access it by typing in LVM on the command line.

In part one of this series we created a set of hard disks during the initial set-up. These should be available to us within the vm you can use the lsblk command to list them. If you followed part one correctly you should have the following disks:

[root@centospractice ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 8G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 7.5G 0 part
 ├─vg_centospractice-lv_root (dm-0) 253:0 0 5.6G 0 lvm /
 └─vg_centospractice-lv_swap (dm-1) 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 8G 0 disk
sdc 8:32 0 8G 0 disk
sdd 8:48 0 8G 0 disk

We are going to use fdisk to create /dev/sdb1, /dev/sdc1 and /dev/sdd1 onto the three extra disks we created earlier. The device /dev/sda including its two partitions are our root volume (/dev/sda1) and swap partition (/dev/sda2) respectively. I am only showing the creation and change of volume type for /dev/sdb to create /dev/sdb1 you will have to repeat this process for /dev/sdc and /dev/sdd.

[root@centospractice ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
 switch off the mode (command 'c') and change display units to
 sectors (command 'u').
Command (m for help): n

Command action
 e extended
 p primary partition (1-4)
p

Partition number (1-4): 1

First cylinder (1-1044, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044):
Using default value 1044

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000ecb3
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 83 Linux

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): df
Changed system type of partition 1 to df (BootIt)

Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000ecb3
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ df BootIt

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

After you have created the partitions and changed the volume types you should be left with a partition list like so:

[root@centospractice ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 8G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 7.5G 0 part
 ├─vg_centospractice-lv_root (dm-0) 253:0 0 5.6G 0 lvm /
 └─vg_centospractice-lv_swap (dm-1) 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 8G 0 disk
└─sdb1 8:17 0 8G 0 part
sdc 8:32 0 8G 0 disk
└─sdc1 8:33 0 8G 0 part
sdd 8:48 0 8G 0 disk
└─sdd1 8:49 0 8G 0 part

Now use the pvcreate command to initialise the disks for use by lvm:

[root@centospractice ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created
[root@centospractice ~]# pvcreate /dev/sdc1
 Physical volume "/dev/sdc1" successfully created
[root@centospractice ~]# pvcreate /dev/sdd1
 Physical volume "/dev/sdd1" successfully created

Take the initialised physical volumes above and incorporate them into a volume group:

[root@centospractice ~]# vgcreate vg0 /dev/sdb1 /dev/sdc1 /dev/sdd1
 Volume group "vg0" successfully created

Now lets create some logical volumes for use. Each of the physical volumes was 8GB which means the maximum logical volume size we can have is 24GB.

[root@centospractice ~]# lvcreate -L 5G -n lv0 vg0
 Logical volume "lv0" created
[root@centospractice ~]# lvcreate -L 5G -n lv1 vg0
 Logical volume "lv1" created

Display the physical and logical volumes as well as the volume group

[root@centospractice ~]# pvdisplay
 --- Physical volume ---
 PV Name /dev/sdb1
 VG Name vg0
 PV Size 8.00 GiB / not usable 1.35 MiB
 Allocatable yes
 PE Size 4.00 MiB
 Total PE 2047
 Free PE 767
 Allocated PE 1280
 PV UUID 2U277p-DvU5-lYVW-Lgut-mGys-bwY7-QLqVS2
--- Physical volume ---
 PV Name /dev/sdc1
 VG Name vg0
 PV Size 8.00 GiB / not usable 1.35 MiB
 Allocatable yes
 PE Size 4.00 MiB
 Total PE 2047
 Free PE 767
 Allocated PE 1280
 PV UUID jOiOZM-BfhU-Gm0C-boOQ-FrYu-VxTb-dEHj5x
--- Physical volume ---
 PV Name /dev/sdd1
 VG Name vg0
 PV Size 8.00 GiB / not usable 1.35 MiB
 Allocatable yes
 PE Size 4.00 MiB
 Total PE 2047
 Free PE 2047
 Allocated PE 0
 PV UUID TdJh5d-zWNA-q4NB-icJl-ebDM-kvJZ-WGjli1
[root@centospractice ~]# vgdisplay
 --- Volume group ---
 VG Name vg0
 System ID
 Format lvm2
 Metadata Areas 3
 Metadata Sequence No 3
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 2
 Open LV 0
 Max PV 0
 Cur PV 3
 Act PV 3
 VG Size 23.99 GiB
 PE Size 4.00 MiB
 Total PE 6141
 Alloc PE / Size 2560 / 10.00 GiB
 Free PE / Size 3581 / 13.99 GiB
 VG UUID l4DtQm-Fq8f-c1vo-ajk9-hxOU-UPKT-KJtpIK
[root@centospractice ~]# lvdisplay
 --- Logical volume ---
 LV Path /dev/vg0/lv0
 LV Name lv0
 VG Name vg0
 LV UUID 5nrv1M-6URA-dt8I-p6QE-7Vns-IXT4-TY1BDE
 LV Write Access read/write
 LV Creation host, time centospractice.local, 2015-04-26 22:40:44 +0100
 LV Status available
 # open 0
 LV Size 5.00 GiB
 Current LE 1280
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:2
--- Logical volume ---
 LV Path /dev/vg0/lv1
 LV Name lv1
 VG Name vg0
 LV UUID yKbtfL-jNxe-rpAr-7nX0-ehD2-QGnk-Lw3dfi
 LV Write Access read/write
 LV Creation host, time centospractice.local, 2015-04-26 22:40:49 +0100
 LV Status available
 # open 0
 LV Size 5.00 GiB
 Current LE 1280
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:3

You can address these logical volumes like so:

  • /dev/vg0/lv0
  • /dev/vg0/lv1

or

  • /dev/mapper/vg0-lv0
  • /dev/mapper/vg0-lv1

Create a filesystem on the logical volumes we have just created, create mount points for them and mount them for use.

[root@centospractice ~]# mkfs.ext4 /dev/vg0/lv0
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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@centospractice ~]# mkfs.ext4 /dev/vg0/lv1
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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@centospractice ~]# mkdir /mnt/lv0
[root@centospractice ~]# mkdir /mnt/lv1
[root@centospractice ~]# mount -t ext4 /dev/vg0/lv0 /mnt/lv0
[root@centospractice ~]# mount -t ext4 /dev/vg0/lv1 /mnt/lv1
[root@centospractice ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centospractice-lv_root
 5.5G 791M 4.5G 15% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot
/dev/mapper/vg0-lv0 5.0G 138M 4.6G 3% /mnt/lv0
/dev/mapper/vg0-lv1 5.0G 138M 4.6G 3% /mnt/lv1

Tune in tomorrow for the third part of my revision article on LFCS Filesystem & storage where we will discuss how to create and use swap partitions and how to format partitions with file systems.

Subscribe to my feed either by E-mail or by RSS to receive updates as they happen.

Can you improve on any of the tips I’ve discussed here? If you can let me know in the comments.

Jason Edwards