GRUB2

Grand Unified Boot Loader
/etc/default/grub – the most important.
# cd /etc/default/
# vi grub
Here are the parameters.
Important: GRUB_CMDLINE
rhgb quite is a parameter which not allow grub to show what is doing while is booting.
Rest of configuration is in:
# /etc/grub.d
After changing the configuration, must load them:
# grub2-mkconfig
# reboot
go to menu and go to kernel line and press ctrl+x to exit and continue the boot procedure.

kickstart File for automatic isntallation

On root directory is the kickstart file anaconda-ks.cfg and also initial-setup-ks.cfg
For creating a kickstart file must install:
# yum install system-config-kickstart -y
Is the only utility that has been updated.
The powerful about this file is that can execute scripts before and after installation.
Modify anaconda-ks.cfg
# vi /root/anaconda-ks.cfg
Copy the file to /var/ftp/pub/ directory that is visible.
# chmod 644 anaconda-ks.cfg
#systemctl status vsftpd
Start the installation and stop on first page and press key and add the following to line:
ks=ftp://server.rhatcertification.com/pub/anaconda-ks.cfg

Kernel modules and tunning Kernel Behavior

# lsmod – show the modules loaded.
# modinfo e1000 – show details about the module.
# modprobe -r cdrom
If the remove is not working, can change the parameter:
# modprobe cdrom lockdoor=0
The files which should be modified are into: /etc/modprobe.d/
Check the man page:
# man 5 modprobe.d
The syntax should be:
options modulename options
There should be a new file created with extension .conf
# vim cdrom.conf
add the line:
options cdrom lockdoor=0

Tunning Kernel Behavior
Easy to make the changes persistent, use sysctl
# sysctl -a – show an overview.
# sysctl -a | grep forward
The name of parameters correspond to files from /proc/sys
From this I have to replace “.” with “/”
In RHEL7 /etc/sysctl.conf is not used anymore.
In order to make settings persistent, create a file into /etc/sysctl.d/ directory and put it with extension “.conf”.
Another place to put the file could be /usr/lib/sysctl.d/
The number from files matter because if you make a settings in 2 files, the second will matter.
For routing, create a file into /etc/sysctl.d/ directory with name:
# vi /etc/sysctl.d/50-ipforward.conf
The values:
net.ipv4.ip_forward = 1
On next reboot the value will be loaded.

Summary:
# lsmod
# modinfo iwlwifi
# cd /etc/modprobe.d
# vi iwlwifi.conf
options iwlwifi led_mode=1
test:
# modprobe iwlwifi
Check the logs to see if is enabled:
# dmesg

Create LVM logical volume

1. create a partition
# fdisk /dev/sdb
n > p > 3 > +100M
Change the partition type:
t > 3 > l (overview) > 8e (Linux LVM) > p (verify) > w
# partprobe – push the changes to kernel.
2. create the physical volume.
# pvcreate –help
# pvcreate /dev/sdb3
Check:
# pvs
Put it into Volume Group:
# vgcreate –help
# vgcreate vgmyvg /dev/sdb3
vgmyvg – this is volume group name which should be started with “vg”. Make it easy to find the volume group.
Volume group have 94MB. 4 MB are used for metadata.
3. create the logical volume from volume group:
# lvcreate –help | less
# lvcreate -n lvmylv -L 96M vgmyvg
-n is for name….is for see better
-L is required and is for size in M or G.
vgmyvg – is the name of volume group used for creation.
Check:
# lvs
Now I can put file system on it.
# mkfs.ext2 /dev/vgmyvg/lvmylv
Now mount it
# mount /dev/vgmyvg/lvmylv /mnt
Now check if the LVM volume has been mounted:
# mount | grep ^/dev
The mount is /dev/mapper/
Both /dev/vgmyvg/lvmylv and /dev/mapper/vgmyvg/lvmylv are pointing to same device: ../dm-3
This is the same device mapper used for creating luks and volumes.

Growing an LVM Logical volume
Can be resizable easy.
# df -h (disk free human readable format)
If the disk is full, must make the file system bigger.
check the volume group in order to see if there is some space available.
# lvs
Check VG for space available
# vgs
No disk free space available.
I have to make VG bigger by adding physical volume.
# fdick /dev/sdb
I have 3 partitions. There is room for one more:
Maybe I will have to add partitions in future. For that I will have to make an extended partition and inside this extended partition I will create logical partitions. In logical partitions I will use pv.
n > e (extended) > (extended partitions consume the all remaining space).
p to test
# n > +100M > t (type) > 8e (Linux LVM) > w
# partprobe
I will not create the PV. I’m starting direct to resize the volume group.
# vgextend –help
# vgextend vgmyvg /dev/sdb5
Check now:
# vgs
# lvextend –help
# lvextend -l +100%FREE -r /dev/vgmyvg/lvmylv
-l is used to use 100% of free space
-r is to resize the file system.
Check the file system
# df -h

Shrinking an LVM Logical Volume
Need a fs which support shrinking. NFS is not supporting shrinking. ext4 is supporting
# df -h
The /moredata is not used and is ok to shrink.
# mount | grep lvmmylv
Is using an ext4 file system.
Must unmount the file system.
umount /moredata
1. reduce file system.
Check the file system:
# e2fsck -f /dev/vgmyvg/lvmylv
and now can reduce it without issues
# man -k resize
# resize2fs /dev/vgmyvg/lvmylv 100M
2. reduce the Logical Volume
# lvreduce –help
# lvreduce -L 102400K /dev/vgmyvg/lvmylv
Press yes in order to accept.
Now I have to mount the filesystem:
# mount -a (I will mount all)

Another approach will be with lvreduce with “-r” option.
Unmount hte directory.
# umount /moredata
# lvreduce -L 50M -r /dev/vgmyvg/lvmylv
This command is doing all.
# mount -a
The volume group will be done later.
!!!!! -r is not working on all file systems.

Steps for creating partitions

Create 1GB ext4 logical partition.
GiB is multiple 1024. RHEL use G to create partition.
# fdisk -l
/dev/sda have all sectors used:
/dev/sdb don’t contain anything:
# fdisk /dev/sdb
n > e (extended) > 1G >enter > p
Now I want to create logical partitions inside the extended partition.
n > +1G
n > +1G
w
reboot if there is error.
I have 2 partitons created and must to mount them to /data
Create the file system to logical and NOT to extended partition.
# mkfs.ext4 /dev/sdb5
Now persist the info into /etc/fstab
/dev/sdb5 /data ext4 defaults 1 2
Now the encrypted partition.
# cryptsetup liksFormat /dev/sdb6
Now open it with a name
# cryptsetup luksOpen /dev/sdb6 secret
Now the partition is open in /dev/mapper
Now create the file system on this device
# mkfs.xfs /dev/mapper/secret
Now I have to mount it automatically.
I have to create directory /secret and /data
#mkdir /data
# mkdir /secret
I have to do 2 thinkes:
1. put the partition in /etc/fstab
/dev/mapper/secret /secret xfs defaults 1 2
2. I have to create a file /etc/crypttab
secret /dev/sdb6
(I have to put into file the name and the location before encrypted)

Dealing with “Enter root passwd for maintenance mode”

If there is an error at boot because of editing improperly /dev/sdb1, could request root password.
Troubleshooting mode > Emergency mode.
Check the logs:
# journalctl -xb (booting messages).
q – quit journalctl.
Check if you can write in file system:
# touch fileName
Identify error into /etc/fstab and correct it.
Reboot:
# systemctl reboot

Creating a LUKS Encrypted Partition

# fdisk /dev/sdb
p
Difference between total and end block is the free space.
n > primary > 2 > Default sector > +100MB
p > w
Update kernel partition tabel:
# partprobe /dev/sdb
# cat /proc/partitions
Now I can create the crypt volume.
Use cryptsetup
# cryptsetup luksFormat /dev/sdb2
yes >
Now the partition encrypted is created.
In order to use it, make mount point:
# mkdir /secret
Open before mount. Need to provide a name to partition. In this case is “secret”
# cryptsetup luksOpen /dev/sdb2 secret
/dev/mapper – should contain the encrypted partition: /dev/mapper/secret.
Make a file system on this device. This time mkfs.ext4
# mkfs.ext4 /dev/mapper/secret
Now I can mount it:
# mount /dev/mapper/secret /secret
NEVER disconnect an encrypted partition but if have to do it:
# umount /secret
# cryptsetup lucksClose /dev/mapper/secret
Now the secret device is secured unmounted and closed.
Add the partition to fstab:
# vi /etc/fstab
/dev/mapper/secret /secret ext4 defaults 1 2
At this moment will not work because there is no /dev/mapper/secret.
I have to create a file /etc/crypttab
vi /etc/cryptatab
nameOfDevice nameOfPartition passwordUsage
secret /dev/sdb2 none

The only way to test is by reboot.

Making the File System and mounting manually

I have the partition created:
# cat /proc/partitions
Type mkfs and press tab twice.
There are many mkfs utilities. The default is mkfs.xfs.
# mkfs.xfs –help (check the options)
blocksize is for large file syse and need big blocks to alocate.
inode is useful for SELinux in order to store metadata.
label – is a name for fileSystem.
# mkfs.xfs -L myfs /dev/sdb1

Mounting manually
in order to use it, use mount command:
#mount –help
simple option for moment:
#mount /dev/sdb1 /mnt
mounting is connecting something to a directory.
Check by listing all mounted devices:
# mount
Check only my device:
# mount | grep ^/dev
If want to disconnect device:
# umount /dev/sdb1
or use:
# umount /mnt
If I don’t want after next boot to be changed the anme of device from /dev/sdb1 to /dev/sdc1, use UUID
Display UUID:
# blkid (block ID)
UUID is generated and is unique and Label is generated manually by administrator and is fixed.
# mount LABEL=myfs /mnt

Use fstab:
The clasical way to automount:
# /etc/fstab
Every file system have UUID.
# blkid
Mount options. Can be used for ACL the acl mount option on /etc/fstab
Column 5 is the backup support. 1 is the backup support which is used in older environments.
Column 6 is for fsck (fs check) is checking the fs. On boot is checked. Option 0 is for no, 1 is for checking /root filesystem first and 2 is for checking and is not root file system.

Create partition > make file system > mount it.
# vi /etc/fstab
All file systems are added there.
Device name mount point fileSystems default backup checkOnBooting
/dev/sdb1 /data xfs defaults 1 2
Test it:
# mount -a
create the directory /data
# mount -a
verify:
# mount | grep ^/dev/
There are some problems. If the server change the name, the file system will not be mounted. Need the label or the UUID.
# blkid (show labels and UUID for all file systems)
LABEL=myfs /data xfs defaults 1 2
Change the label of file system:
# xfs_admin help
# xfs_admin -L bootdevice /dev/sda1

types of available file systems for RHEL 7

XFS – Default in RHEL 7. Based on B-tree database. Good tuning options for different workload.
Ext4 – old and is base on ext2 from 1993. Not scalable
Btrfs – (copy-on-write). Future.
vfat – for Windows capabilities.
GFS2 – clustoring on active-active HA Cluster Environments
Gluster – For distributed file systems. Is base on bricks of XFS and is used for clouding.

create partitions

Add a new virtual disk.
Verify the available space.
# cat /proc/partitions
Into proc directory is all the information about what is happening into kernel.
sdb is the new device used to create partitions.
On sda there are 2 partitions: sda1 and sda2.
Create partitions with fdisk:
# fdisk /dev/sdb
type “m” for help. There is menu. The important are:
“p” print the current layout…partition table
“n” – add a new partition.
“w” – write the information to disk.
use “p” to create partition.
The size of space is 1073 MB which have 2097152 sectors. Every sector is 1/2 KBytes (512 bytes). The sectors will be used for creating partitions on disk
type “n” for new.
!!!!!! Always use “p” for primary partition unless want to create more than 4 partitions on disk.
Choose default by press for type, number and first sector. 1MB is used to store metadata.
Size for last sector. The size +size100M. If not “M”, it will choose automatically as sector and is too small.
Write changes to disk with “w”.
Verify:
# cat /proc/partitions
Now have to create file-system. If there is an error with “device is busy”, reboot the system.