Lpic2-201 HandBook
LPIC-2 is the second certification in the multi-level professional certification program of the Linux Professional Institute (LPI). The LPIC-2 will validate the candidate's ability to administer small to medium–sized mixed networks.
Boot Process
1- frimware --> post
2- kernel load
3- kernel run other programs
dmesg
The Linux kernel is the core of the operating system that controls access to the system resources, such as CPU, I/O devices, physical memory, and file systems. The kernel writes various messages to the kernel ring buffer during the boot process, and when the system is running. These messages include various information about the operation of the system. The kernel ring buffer is a portion of the physical memory that holds the kernel’s log messages. It has a fixed size, which means once the buffer is full, the older logs records are overwritten. The dmesg command-line utility is used to print and control the kernel ring buffer in Linux and other Unix-like operating systems. It is useful for examining kernel boot messages and debugging hardware related issues
Note : By default, all users can run the dmesg command. However, on some systems, the access to dmesg may be restricted for non-root users. In this situation, when invoking dmesg you will get an error message like below:
dmesg: read kernel buffer failed: Operation not permitted The kernel parameter kernel.dmesg_restrict specifies whether unprivileged users can use dmesg to view messages from the kernel’s log buffer. To remove the restrictions, set it to zero :
➜ ~ sudo sysctl -w kernel.dmesg_restrict=0
➜ ~ dmesg --color=always | less
➜ ~ dmesg | grep -i usb
Human Readbale :
➜ ~ dmesg -H
To print human-readable timestamps use the -T (--ctime) option:
➜ ~ dmesg -T
Filtering dmesg Output
kern : kernel messages user : user-level messages mail : mail system daemon : system daemons auth : security/authorization messages syslog : internal syslogd messages lpr : line printer subsystem news : network news subsystem
➜ ~ dmesg -f kern,daemon
Each log message is associated with a log level that shows the importance of the message. dmesg supports the following log levels:
emerg : system is unusable alert : action must be taken immediately crit : critical conditions err : error conditions warn : warning conditions notice : normal but significant condition info : informational debug : debug-level messages
➜ ~ dmesg -l err,crit
Clearing the Ring Buffer
➜ ~ sudo dmesg -C
➜ ~ cat /var/log/boot.log
~= dmesg
Bios
MBR : master boot record
Bootloader : find kernel and run it
Grub
grub1 = grub legacy
grub2 = in now and support UEFI
grub2
➜ ~ cd /etc/grub
➜ ~ cd /etc/default/grub
Note-1 : The /etc/default/grub file is short and should be easy to edit. As with any other configuration file, you need to edit the options to your desired state and then change the file. If any of the options below doesn’t already appear in the file, add it on a new line. If it does, edit the existing line instead of adding a duplicate one.
*Choose the Default OS : ** Change the GRUB_DEFAULT= line. By default, GRUB_DEFAULT=0 uses the first entry as the default — change the number to 1 to use the second entry, 2 to use the third entry, or so on. You could also use GRUB_DEFAULT=saved and GRUB would automatically boot the last operating system you chose each time you boot. You can also specify a label in quotes. For example, if you had an operating system named Windows 7 (loader) in your OS list, you could use GRUB_DEFAULT=”Windows 7 (loader)” Save a Default Operating System: If you choose GRUB_DEFAULT=saved, you also need to add a GRUB_SAVEDEFAULT=true line — otherwise it won’t work.
Choose Whether GRUB is Hidden : With only one operating system installed, Ubuntu defaults GRUB to automatically boot to the default OS with the GRUB_HIDDEN_TIMEOUT=0 option. This option specifies GRUB will be hidden and it will automatically boot to the default OS after 0 seconds –immediately, in other words. You can still access the menu by holding Shift as your computer boots. To set a higher timeout, use something like GRUB_HIDDEN_TIMEOUT=5 — GRUB will display an empty screen or splash screen for five seconds, during which you can press any key to view the menu. To prevent GRUB from being automatically hidden, comment the line out — just add a # before it so that it reads #GRUB_HIDDEN_TIMEOUT=0
Control GRUB’s Menu Timeout : If GRUB isn’t automatically hidden, you’ll see the menu each time your computer boots. GRUB will automatically bot the default operating system after a period of time, usually ten seconds. During that time, you can choose another OS or leave it be to automatically boot. To change the timeout period, edit the GRUB_TIMEOUT=10 line and enter any number of seconds you like. (Remember, this is only used if GRUB isn’t hidden.) To prevent GRUB from booting automatically and always wait for you to choose an OS, change the line to GRUB_TIMEOUT=-1
Choose a Background Image : he GRUB_BACKGROUND line controls whether a background image is used — by default, GRUB uses a white-on-black monochrome look. You can add a line like GRUB_BACKGROUND=”/home/user/Pictures/background.png” to specify an image file GRUB will use.
Note : The image file must meet various specifications. GRUB supports JPG/JPEG images, but these are limited to 256 colors — so you probably won’t want to use a JPG image. Instead, you’ll probably want to use a PNG image that can have any number of colors. You could also use a TGA image file.
Make Your Changes Take Effect
➜ ~ sudo update-grub
Config File is :
➜ ~ cat /boot/grub/grub.cfg
Note : in /boot/grub/crub.cfg main things done in menuentries part of file. Note : /boot/grub/grub.cfg file is have one part , that is line linux and initrd line
Note : menu entry of grub2 something like this :
menuentry "centos Linux" {
}
menurntry "windows" {
}
Main Process in Gurb install
➜ ~ grub2-install /dev/sda
➜ ~ grub-mkconfig
➜ ~ grub-mkconfig > /boot/grub/grub.cfg
For More info :RedHat
systemup programs
{ if /sbin/init ;
do
elif /etc/init.d
else /bin/sh
fi }
Systemd
Simply put, a service is a "background process" that is started or stopped based on certain circumstances. You are not required to manually start and/or stop it. A 'systemd service file' is a file that is written in a format such that systemd is able to parse and understand it, and later on do what you told it to do.
Understanding the Basic Structure of a Systemd Service File
{
[Unit] Description=Apache web server After=network.target Before=nextcloud-web.service
[Service] ExecStart=/usr/local/apache2/bin/httpd -D FOREGROUND -k start ExecReload=/usr/local/apache2/bin/httpd -k graceful Type=notify Restart=always
[Install] WantedBy=default.target RequiredBy=network.target
}
The [Unit] section
The Unit section contains details and description about the unit itself. In our case, it contains details about the service. Details like 'what is its description', 'what are its dependencies' and more.
Description : - Human-readable title of the systemd service. After : - Set dependency on a service. For example, if you are configuring Apache web server, you want the server to start after the network is online. This typically includes targets or other services. Before : - Start current service before specified service. In this example, I tell that "I want Apache web server running before the service for Nextcloud is started". This is because, in my case, Nextcloud server depends on the Apache web server. This too, like After, includes targets or other services.
The [Service] section
ExecStart : - The command that needs to be executed when the service starts. In our case, we want the Apache server to start. ExecReload : - This is an optional field. It specifies how a service is restarted. For services that perform disk I/O (especially writing to disk, like a database), it is best to gracefully kill them and start again. Use this field in case you wish to have a specific restart mechanism. Type : - This indicates the start-up type of a process for a given systemd service. Options are simple, exec, forking, oneshot, dbus, notify and idle. (more info here) Restart : - This is another optional field but one that you will very likely use. This specifies if a service should be restarted--depending on circumstances--or not. The available options are no, on-success, on-failure, on-abnormal, on-watchdog, on-abort and always.
he Install section, as the name says, handles the installation of a systemd service/unit file. This is used when you run either systemctl enable and systemctl disable command for enabling or disabling a service.
WantedBy : - This is similar to the After and Before fields, but the main difference is that this is used to specify systemd-equivalent "runlevels". The default.target is when all the system initialization is complete--when the user is asked to log in. Most user-facing services (like Apache, cron, GNOME-stuff, etc.) use this target. RequiredBy : - This field might feel very similar to WantedBy, but the main difference is that this field specifies hard dependencies. Meaning, if a dependency, this service will fail.
➜ ~ systemctl
➜ ~ cd /lib/systemd/system
➜ ~ cat /lib/systemd/system/sshd.service
➜ ~ sudo systemctl start ssh
➜ ~ sudo systemctl stop ssh
➜ ~ sudo systemctl restart ssh
➜ ~ sudo systemctl reload ssh
➜ ~ sudo systemctl status ssh
➜ ~ sudo systemctl enable ssh
➜ ~ sudo systemctl disable ssh
systemctl isolate :
it can be one and cut others. in isolate mode you can go to targets
➜ ~ journalctl
Backup
1- Full backup
2- incrimental
3- differential
4- snapshot : Full backup + diferential
Note : Best Directories will be backup in Linux :
/etc /home /opt /root /usr /var /srv
Backup Apps in Linux:
backup pc bare os
➜ ~ tar cfvz Desktop.tar.gz /home/koosha/Desktop
➜ ~ tar xfv Desktop.tar.gz
➜ ~ tar tf Desktop.tar.gz
: show files in gz file
Tape
mt -f /dev/st0 opration [count] [arg]
opration {
➜ ~ mt -f /dev/st0 rewind
➜ ~ tar cf /dev/st0 /home
➜ ~ rsync -avh /home/koosha/Documents /tmp
➜ ~ rsync -avh /home/koosha/Documents backup:/tmp/
*this will be send files to backup server in we define in /etc/hosts
➜ ~ rsync -avh /home/koosha/Documents 192.138.1.100:/tmp
➜ ~ rsync -avh /home/koosha/Documents hamed@192.138.1.100:/home/Documents
Note : -a is so important because it send files witch is have differebce between them
➜ ~ dd if=/dev/sdb of=/dev/sdc bs=1
➜ ~ dd if=/dev/sda of=/dev/sdb bs=1
➜ ~ dd if=/home/koosha/Downloads/rocky.iso of=/dev/sdb bs=1
➜ ~ dd if=/dev/sdX of=/dev/sdY bs=64K conv=noerror,sync
# clone Your Hard Disk
Important Note : When you want to clone a hard drive, it is better to first make an image file from that hard drive and then make a clone of it on the second hard drive. Because it may not be correct that the cone prepared in the state without image.
*Important Note2 :Be sure to check the clone files again after receiving them.
Compile Kernel
kernel.org
Step 1
The first step is to install the required compilers and tools.
Debian/Ubuntu Linux
➜ ~ sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev
REHL
➜ ~ sudo dnf groupinstall “Development Tools”
➜ ~ sudo dnf install ncurses-devel bison flex elfutils-libelf-devel openssl-devel
Step 2
Get the latest Linux kernel source code : kernel.org
➜ ~ wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.19.8.tar.xz
Step 3
Extract the source
➜ ~ tar xf linux-5.19.8.tar.xz
Step 4
Configure the Linux kernel
➜ ~ cd linux-5.19.8
: This Might be Other Version
➜ ~ cp -v /boot/config-$(uname -r) .config
make menuconfig
Step 5
compile and install
➜ ~ make
➜ ~ sudo make modules_install
➜ ~ sudo make install
Monitoring
memory
1-1) free
1-2) htop
1-3) vmstat
1-4) sar
cpu
2-1) top
2-2) htop
2-3) sar
2-4) iostat
2-5) mpstat
2-6) ps -ef
2-7) w : show users and every one what is doing ...
io
3-1) iotop
3-2) iostat
3-3) lsof
network
4-1) iptraf
4-2) iptraf-ng
4-3) netstat -na
4-4) netstat -nr
4-5) tcpdump
4-6) ntop
4-7) ss : show informations about sockets
4-8) lsof -i
process
5-1) pmap
5-2) pstree
5-3) top
Monitoring tools { nagios, zabbiz, rrdtools, cacti, mrtg }
pmap (Process Map)
pmap ➜ ~
pmap 2506
➜ ~ sudo iptraf
➜ ~ sudo iptraf-ng
: show all data in network
➜ ~ cat /proc/meminfo ➜ ~ cat /proc/meminfo | less
sar
➜ ~ sar 1 4
1 : seccond 4 : number of attempt to show results
vmstat
show status of vurtual buffers
Kernel
hardware --> kernel --> Gnu (GUI) --> Application
➜ ~ ipcs
: show shared memory
➜ ~ ls /boot
In this directory, there may be versions of Linux whose names are vmlinuz Files for init procedure are in this directory and name of this files are
➜ ~ initramfs
in this Directory we have modules of Kernel
➜ ~ cd /lib/modules
SOURCE Files of linux
Debian : /usr/source/linux
RedHat : /usr/source/kernels
Kernel Modules
DKMS = Dynamic kernel Module Support
DKMS (Dynamic Kernel Module Support) is a framework for third party kernel modules which are automatically rebuilt when new kernels are installed. It is highly useful if you are using out-of-tree kernel modules. The most common use-case for DKMS is to install wrappers for binary blob drivers. DKMS is free software under the GNU GPL v2. All the major Linux distributions support it.
➜ ~ lsmod
: modules of kernel
➜ ~ modinfo
➜ ~ modinfo iwlwifi
➜ ~ insmod
➜ ~ insmod /lib/modules/5.14.17-301.fc35.x86_64/kernel/drivers/net/wireless/intel/iwlwifi/iwlwifi.ko.xz
➜ ~ modprobe
modprobe
➜ ~ sudo modprobe -r iwlwifi
: remove wifi kernel ➜ ~ sudo modprobe iwlwifi
: load wifi kernel
➜ ~ lspci
: show all pci devices in system
➜ ~ lspci
➜ ~ lsusb
➜ ~ cd /proc/sys
sysctl : this can read variables of kernel and in some featues can edit them in some cases you can chnage values of network if you'r network is weak.
➜ ~ sysctl -a
File Systems
Types of Linux File Systems
A standard Linux Distribution provides the choice of partitioning disk with the file formats listed below, each of which has special meaning associated with it.
ext2 ext3 ext4 jfs ReiserFS XFS Btrfs
ext2, ext3, ext4
These are the progressive version of Extended Filesystem (ext), which primarily was developed for MINIX. The second extended version (ext2) was an improved version. Ext3 added performance improvement. Ext4 was a performance improvement besides additional providing additional features.
JFS
The Journaled File System (JFS) was developed by IBM for AIX UNIX which was used as an alternative to system ext. JFS is an alternative to ext4 currently and is used where stability is required with the use of very few resources. When CPU power is limited JFS comes handy.
ReiserFS
It was introduced as an alternative to ext3 with improved performance and advanced features. There was a time when SuSE Linux‘s default file format was ReiserFS but later Reiser went out of business and SuSe had no option other than to return back to ext3. ReiserFS supports file System Extension dynamically which was relatively an advanced feature but the file system lacked certain area of performance.
XFS
XFS was a high speed JFS which aimed at parallel I/O processing. NASA still usages this file system on their 300+ terabyte storage serve
Btrfs
B-Tree File System (Btrfs) focus on fault tolerance, fun administration, repair System, large storage configuration and is still under development. Btrfs is not recommended for Production System.
Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)
Using df Command
df command reports file system disk space usage, to include the file system type on a particular disk partition, use the -T flag as below:
➜ ~ df -Th
OR
➜ ~ df -Th | grep "^/dev"
Using fsck Command
*fsck is used to check and optionally repair Linux file systems, it can also print the file system type on specified disk partitions.
The flag -N disables checking of file system for errors, it just shows what would be done (but all we need is the file system type):*
➜ ~ fsck -N /dev/sda3
➜ ~ fsck -N /dev/sdb1
lsblk
➜ ~ lsblk -f
mount
➜ ~ mount | grep "^/dev"
blkid
➜ ~ blkid /dev/sda3
fstab
➜ ~ cat /etc/fstab
Hackers Hijack Linux Devices Using PRoot Isolated Filesystems
Hackers are abusing the open-source Linux PRoot utility in BYOF (Bring Your Own Filesystem) attacks to provide a consistent repository of malicious tools that work on many Linux distributions. A Bring Your Own Filesystem attack is when threat actors create a malicious filesystem on their own devices that contain a standard set of tools used to conduct attacks. This file system is then downloaded and mounted on compromised machines, providing a preconfigured toolkit that can be used to compromise a Linux system further. "First, threat actors build a malicious filesystem which will be deployed. This malicious filesystem includes everything that the operation needs to succeed," explains a new report by Sysdig. "Doing this preparation at this early stage allows all of the tools to be downloaded, configured, or installed on the attacker's own system far from the prying eyes of detection tools."
➜ ~ fdisk -l /dev/sdb1
➜ ~ fdisk /dev/sdb
➜ ~ mkfs.ntfs /dev/sdb1
== ➜ ~ mkfs -t ntfs /dev/sdb1
➜ ~ mkfs.ext4 /dev/sdb1
== ➜ ~ mkfs -t ntfs /dev/sdb1
mount
➜ ~ mount /dev/sdb1 /tmp/koosha
➜ ~ umount -l /tmp/koosha
➜ ~ umount -f /tmp/koosha
➜ ~ cat /etc/fstab
More About fstab
Your Linux system's filesystem table, aka fstab, is a configuration table designed to ease the burden of mounting and unmounting file systems to a machine. It is a set of rules used to control how different filesystems are treated each time they are introduced to a system. Consider USB drives, for example. Today, we are so used to the plug and play nature of our favorite external drives that we may completely forget that operations are going on behind the scenes to mount the drive and read/write data. In the time of the ancients, users had to manually mount these drives to a file location using the mount command. The fstab file became an attractive option because of challenges like this. It is designed to configure a rule where specific file systems are detected, then automatically mounted in the user's desired order every time the system boots. Not only is it less work over time, but it also allows the user to avoid load order errors that could eat up valuable time and energy.
*Table structure The table itself is a 6 column structure, where each column designates a specific parameter and must be set up in the correct order. The columns of the table are as follows from left to right: * Device : usually the given name or UUID of the mounted device (sda1/sda2/etc). Mount Point : designates the directory where the device is/will be mounted. File System Type : nothing trick here, shows the type of filesystem in use. Options : lists any active mount options. If using multiple options they must be separated by commas. Backup Operation : (the first digit) this is a binary system where 1 = dump utility backup of a partition. 0 = no backup. This is an outdated backup method and should NOT be used. File System Check Order : (second digit) Here we can see three possible outcomes. 0 means that fsck will not check the filesystem. Numbers higher than this represent the check order. The root filesystem should be set to 1 and other partitions set to 2.
fstab defaults
ro
rw
sync
user/users
group
owner
Raid
Software RAID and Hardware RAID
Software RAID have low performance, because of consuming resource from hosts. Raid software need to load for read data from software raid volumes. Before loading raid software, OS need to get boot to load the raid software. No need of Physical hardware in software raids. Zero cost investment.
Hardware RAID have high performance. They are dedicated RAID Controller which is Physically built using PCI express cards. It won’t use the host resource. They have NVRAM for cache to read and write. Stores cache while rebuild even if there is power-failure, it will store the cache using battery power backups. Very costly investments needed for a large scale.
Featured Concepts of RAID
Parity method in raid regenerate the lost content from parity saved information’s. RAID 5, RAID 6 Based on Parity. Stripe is sharing data randomly to multiple disk. This won’t have full data in a single disk. If we use 3 disks half of our data will be in each disks.
Mirroring is used in RAID 1 and RAID 10. Mirroring is making a copy of same data. In RAID 1 it will save the same content to the other disk too.
Hot spare is just a spare drive in our server which can automatically replace the failed drives. If any one of the drive failed in our array this hot spare drive will be used and rebuild automatically.
Chunks are just a size of data which can be minimum from 4KB and more. By defining chunk size we can increase the I/O performance.
RAID’s are in various Levels. Here we will see only the RAID Levels which is used mostly in real environment.
RAID0 = Striping RAID1 = Mirroring RAID5 = Single Disk Distributed Parity RAID6 = Double Disk Distributed Parity RAID10 = Combine of Mirror & Stripe. (Nested RAID)
RAID 0 (or) Striping
Striping have a excellent performance. In Raid 0 (Striping) the data will be written to disk using shared method. Half of the content will be in one disk and another half will be written to other disk. Let us assume we have 2 Disk drives, for example, if we write data “TECMINT” to logical volume it will be saved as ‘T‘ will be saved in first disk and ‘E‘ will be saved in Second disk and ‘C‘ will be saved in First disk and again ‘M‘ will be saved in Second disk and it continues in round-robin process. In this situation if any one of the drive fails we will loose our data, because with half of data from one of the disk can’t use to rebuilt the raid. But while comparing to Write Speed and performance RAID 0 is Excellent. We need at least minimum 2 disks to create a RAID 0 (Striping). If you need your valuable data don’t use this RAID LEVEL.
1- High Performance. 2- There is Zero Capacity Loss in RAID 0 3- Zero Fault Tolerance. 4- Write and Reading will be good performance.
RAID 1 (or) Mirroring
Mirroring have a good performance. Mirroring can make a copy of same data what we have. Assuming we have two numbers of 2TB Hard drives, total there we have 4TB, but in mirroring while the drives are behind the RAID Controller to form a Logical drive Only we can see the 2TB of logical drive. While we save any data, it will write to both 2TB Drives. Minimum two drives are needed to create a RAID 1 or Mirror. If a disk failure occurred we can reproduce the raid set by replacing a new disk. If any one of the disk fails in RAID 1, we can get the data from other one as there was a copy of same content in the other disk. So there is zero data loss.
Good Performance. Here Half of the Space will be lost in total capacity. Full Fault Tolerance. Rebuilt will be faster. Writing Performance will be slow. Reading will be good. Can be used for operating systems and database for small scale.
RAID 5 (or) Distributed Parity
RAID 5 is mostly used in enterprise levels. RAID 5 work by distributed parity method. Parity info will be used to rebuild the data. It rebuilds from the information left on the remaining good drives. This will protect our data from drive failure. Assume we have 4 drives, if one drive fails and while we replace the failed drive we can rebuild the replaced drive from parity informations. Parity information’s are Stored in all 4 drives, if we have 4 numbers of 1TB hard-drive. The parity information will be stored in 256GB in each drivers and other 768GB in each drives will be defined for Users. RAID 5 can be survive from a single Drive failure, If drives fails more than 1 will cause loss of data’s.
Excellent Performance Reading will be extremely very good in speed. Writing will be Average, slow if we won’t use a Hardware RAID Controller. Rebuild from Parity information from all drives. Full Fault Tolerance. 1 Disk Space will be under Parity. Can be used in file servers, web servers, very important backups.
RAID 6 Two Parity Distributed Disk
RAID 6 is same as RAID 5 with two parity distributed system. Mostly used in a large number of arrays. We need minimum 4 Drives, even if there 2 Drive fails we can rebuild the data while replacing new drives. Very slower than RAID 5, because it writes data to all 4 drivers at same time. Will be average in speed while we using a Hardware RAID Controller. If we have 6 numbers of 1TB hard-drives 4 drives will be used for data and 2 drives will be used for Parity.
Poor Performance. Read Performance will be good. Write Performance will be Poor if we not using a Hardware RAID Controller. Rebuild from 2 Parity Drives. Full Fault tolerance. 2 Disks space will be under Parity. Can be Used in Large Arrays. Can be use in backup purpose, video streaming, used in large scale.
RAID 10 (or) Mirror & Stripe
RAID 10 can be called as 1+0 or 0+1. This will do both works of Mirror & Striping. Mirror will be first and stripe will be the second in RAID 10. Stripe will be the first and mirror will be the second in RAID 01. RAID 10 is better comparing to 01. Assume, we have 4 Number of drives. While I’m writing some data to my logical volume it will be saved under All 4 drives using mirror and stripe methods. If I’m writing a data “TECMINT” in RAID 10 it will save the data as follow. First “T” will write to both disks and second “E” will write to both disk, this step will be used for all data write. It will make a copy of every data to other disk too. Same time it will use the RAID 0 method and write data as follow “T” will write to first disk and “E” will write to second disk. Again “C” will write to first Disk and “M” to second disk.
Good read and write performance. Here Half of the Space will be lost in total capacity. Fault Tolerance. Fast rebuild from copying data. Can be used in Database storage for high performance and availability.
For first step you should be create btrfs file system in device
➜ ~ mkfs.btrfs /dev/sdb1
or ➜ ~ mkfs.btrfs /dev/sdb1 /dev/sdb2
➜ ~ mount /dev/sdb1 /mnt
➜ ~ cd /mnt
➜ ~ touch koohsa.txt
➜ ~ btrfs filesystem show
subvolume : Threre are sub directories cat be mount seperatly
➜ ~ btrfs subvolume create mew_sub
cd new_sub touch file_in_newsub
➜ ~ btrfs subvolume list mnt
➜ ~ btrfs subvolume get-default mnt
Note: you can mount this subvolume to another directory,this is so importatnt
➜ ~ mount -o subvol=new_sub /dev/sdb1 /tmp/test
Get Snapshot
➜ ~ btrfs subvolume snapshot new_sub new_sub_snaphot
NFS (network file systems)
AutoFs :
with AutoFs you can mount easly NFS devices and you can add then *into /etc/fstab bun this Option is easy and Fast. if install this service on you system you can see settings in /etc/auto.master
EFS (Encrypted fs)
ecryptfs : package of this ecrypfs-utils
➜ ~ mount -t ext4 /dev/sdc1 /mnt
➜ ~ mount -t ecryptfs /mnt /mnt
After this we can go /mnt and working with this directory. files will be save in this Directory Envrypted. you can add this in /etc/fstab and run it normally
Maintain FileSystems
e2lable
debugfs
➜ ~ debugfs /dev/sda2
for help insert ?
➜ ~ e2lable /dev/sdb2 Koosha_Disk
➜ ~ uuigen /dev/sdb1
➜ ~ blkid /dev/sdb1
➜ ~ lsblk
➜ ~ tune2fs /dev/sdb1 -U 9e8bac51-7642-440b-84c8-87781049eb0b
Types of HardDisk
HDD (Hard Disk Drive)
SSD (Solid State Drive)
NVMe(SSID on bus pci)
Controllers of hard disk( Storage Connectivity Protocol)
IDE/ATA
serial/ATA
SCSI : this protocol is for more speed (640MB/s)
SAS (serial attach SCSI): this protol speed in 12GB/s
FC (Fibre channel): spped up to 32G/s
IP
DMA (Direct Memory access)
scsi : scsi is protocol and standard for devices connect with eachother faster tha n befora
iscsi : this allow working with scsi in Devices in internet.
hdparm
hdparm is command for get information about Your ATA.
➜ ~ hdparm -I /dev/sdb
sdparm
This is same like hdparm but it is for scsi.
sysctl
Linux kernel is the core of the Linux operating system and distributions. Linux kernel is the lowest level of the operating system and provides different system resources and services to the user level. these resources may have a different configuration where sometimes they may change. The sysctl command is used to list, set, and update the Linux kernel-related configuration and parameters.
The /proc/sys Directory
Linux is a file-based operating system where everything in the operating system can be used as a file. The kernel parameters are also provided as a file in the /proc/sys directory. This directory provided files and folders that can be used to display and change the kernel parameter and configuration.
Display All Kernel Parameters
➜ ~ sysctl -a
Display Special One
➜ ~ sysctl dev.cdrom.autoeject
Modify, Change or Update Kernel Parameters
➜ ~ sysctl -w dev.cdrom.autoeject=1
Note : this is for Doing chnaging just at this time not permanent
/etc/sysctl.conf Configuration File
When the system reboots the default kernel parameters and configuration is read from /etc/sysctl.conf file. This makes the kernel parameters and configuration be stored permanently. The syntax of the configuration file is the same as the sysctl command.
For More Information sysctl
LVM
disk 1 = /dev/sdb1
disk 2 = /dev/sdc1
disk 3 = /dev/sdd1
pv = { pvcreate /dev/sdb1 pvcreate /dev/sdc1 pvcreate /dev/sdd1 }
➜ ~ pvscan
➜ ~ pvdisplay
vg = { vgcreate vg00 /dev/sdb1 /dev/sdc1 /dev/sdd1 }
➜ ~ vgdisplay
➜ ~ pvdisplay
lv = { lvcreate -L 3.5G vg00 }
➜ ~ lvscan
➜ ~ mkfs.ext4 /dev/vg00/lvol0
now add one more disk to system and extend it for lv after fdisk this Disk Continue ...
➜ ~ pvcreate /dev/sde4
➜ ~ pvscan
➜ ~ vgextend vg00 /dev/sde4
➜ ~ lvextend -L 5G -v /dev/vg00/lvol0
Note : we extend volume to 5G.
➜ ~ lvdisplay
➜ ~ df -h
=> resize2fs /dev/vg00/lvol0
Note : we always get snapshot before backup
Get snapshot of created volume group
➜ ~ lvcreate -v -L 100m -s -n backup /dev/vg00/lvol0
{ -v : verbose -L : size -s : snapshot -n : backup }
➜ ~ lvrename /dev/vg00/lvol0 mydisk
maper
➜ ~ dmsetup info
➜ ~ dmsetup info /dev/vg00/mydisk
Protecting Files and Directories
Protecting a Files
To protect file, use the following command –
➜ ~ sudo chattr +i abc.txt
Now try to remove file, using rm command as shown below –
➜ ~ rm abc.txt
The sample output should be like this –
rm: remove write-protected regular file 'abc.txt'?
Removing the protection of file
To remove the protection of file, use the following command –
➜ ~ sudo chattr -i abc.txt
To verify the above command, use the following command as shown below-
➜ ~ rm abc.txt
The above command removes the file without giving information. Protecting Directories In the below example abc is a directory name Protecting a directory
To protect directory, use the following command –
➜ ~ sudo chattr -R +i abc
To verify the above command, use the following command as shown below –
➜ ~ rm -r abc
The sample output should be like this –
rm: descend into write-protected directory 'abc'?
Removing protection to the directory
To remove protection to the directory, use the following command-
➜ ~ sudo chattr -R -i abc
To verify the above command, use the following command as shown below –
➜ ~ rm -r abc
Sources
Last updated