Questions PDF
Questions PDF
# df -h .
However, the disk size reports 20GB:
# fdisk -l
# fdisk /dev/xvda
Command (m for help): p
Once again please take a note of the starting sector 4096. Still in fdisk's interactive mode remove
partition:
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Next, create a new partition right on the top of the previous and ensure that you use same
starting sector:
Command (m for help): n
Make the partition 1 bootable and print new partition table:
Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.
SU & Sudo
Sudo runs a single command with root privileges. ... This is a key difference between su and sudo. Su
switches you to the root user account and requires the root account's password. Sudo runs a single
command with root privileges – it doesn't switch to the root user or require a separate root user password.
What is the background process of SSH
Normal Process
Normal processes are those which have life span of a session. They are started during the session as foreground processes
and end up in certain time span or when the session gets logged out. These processes have their owner as any of the valid
user of the system, including root.
Orphan Process
Orphan processes are those which initially had a parent which created the process but after some time, the parent process
unintentionally died or crashed, making init to be the parent of that process. Such processes have init as their immediate
parent which waits on these processes until they die or end up.
Daemon Process
These are some intentionally orphaned processes, such processes which are intentionally left running on the system are
termed as daemon or intentionally orphaned processes. They are usually long-running processes which are once initiated
and then detached from any controlling terminal so that they can run in background till they do not get completed, or end up
throwing an error. Parent of such processes intentionally dies making child execute in background.
NFS Configuration
NFS Port Number : 111
# cat /etc/sysconfig/network-scripts/ifcfg-bond-slave-ens33
TYPE=Ethernet
NAME=bond-slave-ens33
UUID=79c40960-6b2c-47ba-a417-988332affed1
DEVICE=ens33
ONBOOT=yes
MASTER=bond0
SLAVE=yes
# cat /etc/sysconfig/network-scripts/ifcfg-bond-slave-ens37
TYPE=Ethernet
NAME=bond-slave-ens37
UUID=46222a52-f2ae-4732-bf06-ef760aea0d7b
DEVICE=ens37
ONBOOT=yes
MASTER=bond0
SLAVE=yes
NIC Teaming
# rpm -qa | grep teamd
teamd-1.27-4.el7.x86_64
# nmcli con show
Create the teaming interface:
# nmcli con add type team con-name myteam0 ifname team0 config '{ "runner": {"name":
"loadbalance"}}'
team0 config '{ "runner": {"name": "loadbalance"}}'
[10655.288431] IPv6: ADDRCONF(NETDEV_UP): team0: link is not ready
[10655.306955] team0: Mode changed to "loadbalance"
Connection 'myteam0' (ab0a5f7b-2547-4d4f-8fc8-834030839fc1) successfully added.
#cat /etc/sysconfig/network-scripts/ifcfg-myteam0
DEVICE=team0
TEAM_CONFIG="{ \"runner\": {\"name\": \"loadbalance\"}}"
DEVICETYPE=Team
NAME=myteam0
ONBOOT=yes
# nmcli con add type team-slave con-name team0-slave1 ifname eth1 master team0
[10750.419419] team0: Port device eth1 added
#cat /etc/sysconfig/network-scripts/ifcfg-team0-slave1
NAME=team0-slave1
DEVICE=eth1
ONBOOT=yes
TEAM_MASTER=team0
DEVICETYPE=TeamPort
UMASK
UMASK (User Mask or User file creation MASK) is the default permission or base permissions given when
a new file (even folder too, as Linux treats everything as files) is created on a Linux machine. Most of the
Linux distros give 022 (0022) as default UMASK. In other words, it is a system default permissions for newly
created files/folders in the machine.
When user create a file or directory under Linux or UNIX, she create it with a default set of permissions. In most case
the system defaults may be open or relaxed for file sharing purpose. For example, if a text file has 666 permissions, it
grants read and write permission to everyone. Similarly a directory with 777 permissions, grants read, write, and
execute permission to everyone.
Calculating The Final Permission For FILES
You can simply subtract the umask from the base permissions to determine the final permission for file as follows:
666 – 022 = 644
File base permissions : 666
umask value : 022
subtract to get permissions of new file (666-022) : 644 (rw-r–r–)
Calculating The Final Permission For DIRECTORIES
You can simply subtract the umask from the base permissions to determine the final permission for directory as
follows:
777 – 022 = 755
Directory base permissions : 777
umask value : 022
Subtract to get permissions of new directory (777-022) : 755 (rwxr-xr-x)
Cron Jobs
Cron is one of Linux’s most useful tools and a developer favorite because it allows you to run automated commands
at specific periods, dates, and intervals using both general-purpose and task-specific scripts. Given that description,
you can imagine how system admins use it to automate backup tasks, directory cleaning, notifications, etc.
Cron jobs run in the background and constantly check the /etc/crontab file, and the /etc/cron.*/ and /var/spool/cron/
directories. The cron files are not supposed to be edited directly and each user has a unique crontab.
Types of cron configuration files
There are different types of configuration files:
1. The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root
like privileges. The sixth field (see below for field description) is the name of a user for the command to run
as. This gives the system crontab the ability to run commands as any user.
2. The user crontabs: User can install their own cron jobs using the crontab command. The sixth field is the
command to run, and all commands run as the user who created the crontab
$ crontab –e
The syntax is:
1 2 3 4 5 /path/to/command arg1 arg2 ><or >< 1 2 3 4 5 /root/backup.sh
Where,
1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
/path/to/command – Script or command name to schedule
Run backup cron job script
# crontab -e
Append the following entry:
0 3 * * * /root/backup.sh
Save and close the file.
Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand
List all your cron jobs
# crontab -l
# crontab -u username -l
To remove or erase all crontab jobs use the following command:
# Delete the current cron jobs #
crontab -r
## Delete job for specific user. Must be run as root user ##
crontab -r -u username
special string to save time
Instead of the first five fields, you can use any one of eight special strings. It will not just save your time but it will
improve readability.
Special string Meaning
@reboot Run once, at startup.
@yearly Run once a year, “0 0 1 1 *”.
@annually (same as @yearly)
@monthly Run once a month, “0 0 1 * *”.
@weekly Run once a week, “0 0 * * 0”.
@daily Run once a day, “0 0 * * *”.
@midnight (same as @daily)
@hourly Run once an hour, “0 * * * *”.
Examples
Run ntpdate command every hour: >>>>> @hourly /path/to/ntpdate
Make a backup everyday: >>>>>> @daily /path/to/backup/script.sh
How do I backup installed cron jobs entries?
Simply type the following command to backup your cronjobs to a nas server mounted at
/nas01/backup/cron/users.root.bakup directory:
# crontab -l > /nas01/backup/cron/users.root.bakup
# crontab -u userName -l > /nas01/backup/cron/users.userName.bakup
crond and cron jobs log file
You can use the cat command/grep command/tail command to view crond log file. For example,
cat /var/log/cron
tail -f /var/log/cron
grep "my-script.sh"
tail -f /var/log/cron
Find out if daily backups jobs running or not on FreeBSD Unix server:
$ sudo grep '/usr/local/bin/rsnapshot daily' /var/log/cron
On modern Linux distro one can use the systemctl command or journalctl command:
sudo systemctl status cron
sudo journalctl -u cron
sudo journalctl -u cron | grep backup-script.sh
How to generate core dump in Linux
1) cd /etc
2)vi profile
3) remove "#" from "#ulimit -S -c 0 > /dev/null 2>&1"
4) line must be like "ulimit -S -c 0 > /dev/null 2>&1"
5) save and exit(:wx)
6) login with a userid
7) execute "cat"
8) enter "Ctrl + \" (hit Crtl and \ together
9) a core dump inside you current directory....
Rescue mode is typically running off of a ramdisk with fewer commands available. It’s not a full copy of your installed OS;
it boots cleanly so that you can trust the utilities. That could be from a DVD, USB device, or from a different grub menu
from a known good kernel + initrd image. Most likely it’s from a boot disk. You use this when something is so messed up
that you can’t get the OS to boot at all.
Single user mode boots from your normal installation but skips all of the things that make the OS boot into multiuser. So,
no X, no network services to speak of (like nfsd or samba), potentially no network connectivity at all. You’ll have access to
the full suite of utilities, all filesystems, drivers, and can manually start any applications. You’d typically use this for
filesystem corruption on critical mount points, forgotten passwords you need to break, or problems with graphical drivers
that cause X not to start correctly.