RHCSA Study Guide – Objective 6 : Kernel Features

############################
Everything below are my raw notes that I took while attending an unofficial RHCSA training session.  I am posting them here in hopes they will assist others who may be preparing to take this exam.  

My notes are my own interpretation of the lectures, and are certainly not a replacement to classroom training either through your company, or by taking the official RHCSA classes offered through Red Hat.  If you are new to the Red Hat world, I strongly suggest looking into their training courses over at Red Hat.
############################

LVM

Quick note: There is a gui tool for all this if that is what you like:

[root@web01 ~]# yum install system-config-lvm
[root@web01 ~]# system-config-lvm

LVM abstracts the physical hardware into logical drive spaces which can be dynamically grown/shrunk and span disparate physical devices. Its good for hard drive management as it abstracts away the details of the underlying storage devices.

There is a low amount of overhead to the VFS layer, so you are going to take a slight performance hit.

LVM Terminology:

- Physical Volume (pv) - A physical volume is the partition/raid device for the lvm space.
- Physical Extent (pe) - EXAM NOTE:  You may need to change this on text.  Its a chuck of disk space.  Defaults to 4M
- Volume Group (vg) - Collection of physical volumes
- Logical Volume (lv) - A logical volume is a grouping of physical extents from your physical volume.  This is where you format your fs.

Gist of how this works:
pvcreate : Create a physical volume

[root@web01 ~]# pvcreate /dev/sda4

vgcreate : Create a volume group on PV

vgcreate VolGroup00 /dev/sda4  # This is where the extents are created.

lvcreate : Create a logical volume on VG

[root@web01 ~]# lvcreate -n myvol -L 10G VolGroup00 # This is where the extents are allocated.

Other commands:

vgextend
lvextend
lvresize
resize2fs
lvresize # Use this one when doing your resize:  
ex:  lvresize -r {-l (+extents) | -L (+size)} (lv)

When mounting your new fs, use: /dev/vg/lv.

Lab

EXAM NOTE: Most of this stuff will be on the test

1.  Add logical volume management on top of a new partition.  Use a physical extent size of 16MB.  Use fdisk or whatever to create new volume.  
[root@web01 ~]# pvcreate /dev/sda7
[root@web01 ~]# vgcreate -s 16 vg0 /dev/sda7
[root@web01 ~]# vgdisplay vg0

2.  Use half the available space for a logical volume formatted with ext4 and mounted persistently across reboots.
[root@web01 ~]# lvcreate -n myvol -L 5G vg0
[root@web01 ~]# ls -al /dev/vg0/myvol
[root@web01 ~]# ls -al /dev/mapper/vg0-myvol
[root@web01 ~]# ls -al /dev/dm-3
[root@web01 ~]# mkfs -t ext4 /dev/vg0/myvol
[root@web01 ~]# vi /etc/fstab
...
/dev/vg0/myvol /u03 ext4 defaults 1 2
...
[root@web01 ~]# mkdir /u03
[root@web01 ~]# mount /u03

3.  Take a snapshot of this logical volume and check the file system for errors
[root@web01 ~]# ls -al /u03
[root@web01 ~]# cp /var/log/* /u03/
[root@web01 ~]# lvcreate -s /dev/vg0/myvol -n snap-of-myvol -L 500M
[root@web01 ~]# ls -al /dev/vg0
[root@web01 ~]# lvdisplay vg0 # You will see your 2 logical volumes (and snapshot in 'source of')
[root@web01 ~]# mount /dev/vg0/snap-of-myvol /mnt  # This is how you mount that snapshot.

4.  Assuming none are found, reset the counter for days and mounts until a check is forced on the original file system.
[root@web01 ~]# umount /mnt
[root@web01 ~]# fsck /dev/vg0/snap-of-myvol  # If you see clean, then you should be okay
[root@web01 ~]# tune2fs /dev/vg0/snap-of-myvol # Shows more verifications
[root@web01 ~]# tune2fs -C 25 /dev/vg0/snap-of-myvol # Fake out the system to make it believe it has been mounted 25 times so it will actually fsck
[root@web01 ~]# fsck /dev/vg0/snap-of-myvol
[root@web01 ~]# umount /u03
[root@web01 ~]# lvresize -r -L +100M /dev/vg0/myvol
[root@web01 ~]# lvchange -an /dev/vg0/myvol
[root@web01 ~]# lvchange -ay /dev/vg0/myvol
[root@web01 ~]# lvresize -r -L +100M /dev/vg0/myvol
[root@web01 ~]# lvremove /dev/vg0/snap-of-myvol # If this fails, just try a few more times.  Its a known issue

5.  Copy some data onto the LV, then expand it and the filesystem by 50MB.  fsck, then re-mount the filesystem and verify it's contents.  Also try reducing by 50MB 
[root@web01 ~]# umount /u03
[root@web01 ~]# lvresize -r -L +100M /dev/vg0/myvol
[root@web01 ~]# lvchange -an /dev/vg0/myvol
[root@web01 ~]# lvchange -ay /dev/vg0/myvol
[root@web01 ~]# lvresize -r -L +100M /dev/vg0/myvol
[root@web01 ~]# lvremove /dev/vg0/snap-of-myvol # If this fails, just try a few more times.  Its a known issue.  You can resize till snap is gone.
[root@web01 ~]# lvresize -r -L +100M /dev/vg0/myvol # Grow it
[root@web01 ~]# lvresize -r -L -300M /dev/vg0/myvol # Shrink it
# Or you can set it to 2G by
[root@web01 ~]# lvresize -r -L 2G /dev/vg0/myvol
# NOTE:  The -r flag does everything with the resize2fs... so you won't have to resize your system manually.

Swap space

Swap space allows the kernel to better manage limited system memory by copying segments of memory onto disk.

To create 2G of additional swap space using a file:

[root@web01 ~]# dd if=/dev/zero of=/swap01 bs=1024 count=2097152
[root@web01 ~]# mkswap /swap01
[root@web01 ~]# swapon /swap01

If you no longer need the /swap01, just:

[root@web01 ~]# swapoff /swap01

Now list your active swap areas by:

[root@web01 ~]# cat /proc/swaps

Performance note:
Creating a swap device via lvm or like its own partition (even better) is better for performance. Setting it up on a file within an existing fs is going to be really horrendous for performance.

Lab

1.  Add 500MB of swap space to your system using a device
[root@web01 ~]# lvcreate -n swap02 -L 500M vg0
[root@web01 ~]# mkdir /swap02
[root@web01 ~]# mount /dev/vg0/swap02 /swap02
[root@web01 ~]# mkswap /swap02
[root@web01 ~]# swapon /swap02
[root@web01 ~]# vi /etc/fstab
...
/dev/vg0/swap02 swap swap defaults 0 0
...

2.  Add 500MB of swap space to your system using a swap file
# Calculate how much 500M is:
[root@web01 ~]# echo $((1024*500))
512000
[root@web01 ~]# dd if=/dev/zero of=/swap01 bs=1024 count=512000
[root@web01 ~]# mkswap /swap01
[root@web01 ~]# swapon /swap01
[root@web01 ~]# vi /etc/fstab
...
/swap01 swap swap defaults 0 0
...