Using rd.break to Reset the Root Password

reboot > e > line starting with linux17 > remove “rhgb quiet”, insert the parameters: “rd.break”
# mount -o remount,rw /sysroot
# chroot /sysroot
# echo secret | passwd –stdin root
# touch /.autorelabel
Login again normal

systemd and mounting

I want to mount lvdisk to directory /lvdisk
Inside /etc/systemd/system I will create the file:
# vi lvdisk.mount
Description = my test mount
What = /dev/vgdisk/lvdisk
Where =/lvdisk
Type = xfs

WantedBy =

(I can copy as exemple of mounting from/usr/lib/systemd/system)
To mount the disk I have to run:
# systemctl start lvdisk.mount
Make sure that will come back after reboot:
# systemctl enable lvdisk.mount

Part191 – Managing Automount in a systemd Environment
Must create a mount file for a disk which I want to be mounted automatically when is used.
First I have to be sure that the mount is stoped, disabled:
# systemctl disable lvdisk.mount
# systemctl stop lvdisk.mount
# mount | grep lvdisk
Create a automount file which have the name: directoryName.automount
The lvdisk is directoryName, so the file will be:
# lvdisk.automount
Description = lvdisk automount

Where = /lvdisk

WantedBy =

Is important that the name of automount file is matching the name of corresponding of the mount file.
Now I can enable and start automount
# systemctl enable lvdisk.automount
# systemctl start lvdisk.automount
Can use this option or the one discussed before, but this is the future.


cd /usr/lib/systemd/system
This are default services.
The changes should be done into:
Here are service scripts and will overwrite the one from /usr/lib/systemd/system
The basic unit of the systemd are the services from /usr/lib/systemd/system
Here is an example of service httpd.service.
Can make everything as service and start it.
The buttom line show how service should be started.
It should be started by target.
To manage service:
# systemctl status httpd
stop – stop the service
disable – take it out from startup procedure of OS.
System stated are TARGETS.
Those are in /etc/
or in /usr/lib/systemd/system
There are 2 targets:
multiuser – server without GUI
graphical – GUI
When enable a server, a symbolic link is created in /usr/lib/systemd/system/
the rest are into:
To define, in systemd is a which decide what will start. This can be change by changing the symbolic link.
Check active targets:
# systemctl list-units –type=target
We have the service which is responsible to start specific things from OS. Also is the targets which is a collection of a services. The target itself define dependencies with other targets in order to be sure that all requirements are started as need it and in order to put services into a target, will have to create a wants. A wants is a symbolic link which is created automatically when is issue the command “systemctl enable serviceName”

Switching Between systemd Targets
Check the status target:
# systemctl list-units -type=target
Change to minimum mode:
# system isolate
Check the targets:
# systemctl list-units -type=target
From rescue mode there is the only option to exit and reboot from grub:
# exit
From boot menu:
type: e (from edit)
go to line which starts with “linux16”
At end of line add:
ctrl+x to start system.
Type password to get access.
From rescue mode press “ctrl+d” in order to go to GRUB and exit.
Add at end of line linux16:
enter the root passwd
# systemctl list-units –type=target
To start the default target:
# systemctl default


Grand Unified Boot Loader
/etc/default/grub – the most important.
# cd /etc/default/
# vi grub
Here are the parameters.
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:

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.

# lsmod
# modinfo iwlwifi
# cd /etc/modprobe.d
# vi iwlwifi.conf
options iwlwifi led_mode=1
# 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
# 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.
# 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
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.
# systemctl reboot

Creating a LUKS Encrypted Partition

# fdisk /dev/sdb
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.