[DevOps Bootcamp Notes] - Operating Systems & Linux Basics

What is Memory Swapping?

When ever RAM(memory) is filled (or) when the RAM is out of memory then the operating system handle swapping the memory between applications. One app becomes inactive, new one gets resources. Operating system will unload memory(clear memory for one application) and save it on the disk and load the new processes data in that cleared memory.

In a nutshell, swapping means, clearing memory and saving it to the disk and loading new processes data into that cleared memory, which will take sometime and slows down the system.

Type1 Vs Type2 hypervisor?

Creating virtual machines on top of existing operating system(with a hypervisor) is called Type2 hypervisor.In this case host operating system (or) main OS is already there on the hardware in this case. On top of the OS, we install the hypervisor. Typically used for personal computers.


Type1: It exactly works in the same way except installing the hypervisor directly on the Hardware(instead of OS). Type1 hypervisor also called as Bare Metal hypervisor.Example: vmware ESXi, Microsoft hyper-v. Mostly used by organizations to run their infrastructure.


File Systems (Windows & Linux)

Windows -> A:, B: insertable disks (like flopy disks) i.e., insert and take out, C: internal hard drive, remaining letters D:,E:,etc are assigned to the rest of the disks.

Linux->

/ - root directory

/home - Contains home directories of all non-root users.Root user's home Directory is /root

/bin - Contains executables for most essential user commands(binary is the format that the computers can understand)

/sbin - Contains the system binaries(commands) that requires super user privilege(sudo) to execute

/lib - Essential shared libraries that executables from /bin or/sbin use. One program can split their libraries in the libraries folers: /lib,/lib32,/lib64,/libx32

/usr - this was used for user home directories when /home is not there. It also has /bin and /sbin folders as well(duplicated files as in /bin), just to have historical reasons. And because of storage limitations it was split to root binary folders and user binary folders.However the storage limitation doesn't exist anymore, so the split doesn't make sense anymore. However the concept still remains from the old times.Beaware that when we execute those commands(ls,cp) they will get executed from /usr/bin folder. Another difference between those two locations are,some operating systems outer level /bin and /sbin contains less no of commands than /usr/bin and /usr/sbin. Just be aware that those two are very similar(/bin and /usr/bin).

Inside /usr there is another folder local(/usr/local), it aslo has bin,sbin and lib folders. The programs that you install on the computer will be installed in these folders.like docker, java,etc. Programs installed in /usr/local will be available for all users on the computer. To restrict any appilcation from other users, you can install it in your home directory(ex: /home/user1).

/opt - Third party external applications will be installed here. Difference between /opt and /usr/local directory is, some applications that do not split code/files in different directories. Those applications/programs will install all the components in /opt directory without spliting their components(ex: code editors/IDE) . The programs which split its components usually installs binaries in /bin and libraries in /lib folder. Again, what ever we install in /opt will be available system wide for all the users.

/boot - contains files required for booting

/etc - place where configuration for system-wide applications is stroed(network config,password info).Orginally it was to store everything else.But it actually emerged to main configuration location.

/dev - location of device files(like webcam,keyboard,hard drive,etc).Apps and driverss will access this, Not the user.

/var - contains files to which the system writes data during the course of its operation. "/var/cache" contains cached data from application programs. Generally /var folder is for stroing logs from different processes that are running on the computer.

/tmp - temporary resources required for some process, kept here temporarily

/media - contains subdirectories, where removable media devices inserted into the computer are mounted. They will be also referenced in /dev folder.

Example: when you insert a CD. A directory will automatically be created and you can access the contents of the CD inside the directory.

/mnt - temporary mount points.Historically, sys admins mounted temporary file systems there.If you want to manually mount your file system to your operating system, then you can use /mnt for that

Few commands:

ls -R <dir> - To display contents inside <dir>
ctrl + r - Search (in) history
history 20 - print last 20 lines from history
usermod -aG sudo user1 - add user1 to sudo group

Difference between apt and apt-get commands?

apt is more user friendly (shows progress of installation by default) than apt-get
search command is not available in apt-get

See list of repositories/repos : /etc/apt/sources.list

How is Sanp different(App manager)?

Snap is a bundle of an app and its dependencies

Provides a place to upload snaps, and for users to browse and install the software.

Snap is basically an alternative. When we have both available, we can choose apt only due its its efficient storage usability(of already installed packages). Since snap is using bundled libraries/packages it will still download existing dependencies as it is a bundled solution.

PPA(Personal Package Archive)

- PPAs are provided by the community

- Anybody can create this PPA - private repository to distribute the software

- Be aware of possible risks before adding a PPA.

Linux distros grouped, based on same source code. Distros in same category, use the same package manager.

Debian based distributions: Uses apt rep (or) apt-get
Ubuntu
Debian
Linux Mint
Red Hat Based distributions:Uses YUM package manager
RHEL
CentOS
Fedora

Vi/vim useful commands:

Use below commands in command mode(press esc):
  • u - to undo things
  • A - to goto end of the file and enable insert mode
  • dd - delete entire line
  • d10d - delete 10 lines from the current line
  • 0 - to jump to start of the line
  • G - jump to the last line
  • 10G - jump to 10th line
  • dw - delete entire word
  • x - to delete single character
  • R - to replace a character
  • RW - to replace a word
  • /key - search for a string "key". type "n" to jump to next match and type "N" to jump to previous match.
  • :%s/old/new/g - replace the string called "old" with "new" in the entire file

Add a secondary group to user - usermod -G group1,group2 user1 (this will overwrite secondary grops of an user)

- usermod -aG group3,group4 user1 (this will append the groups to existing groups)

delete an user from a group - sudo gpasswd -d user1 group1

Useful Linux/Unix commands:

cat /var/log/messages | less - "less":Displays file contents one page at a time.
Allows to navigate forward and backward(press "b") through the file.Mostly used for opening large files, as less doesn't read the entire file, which results in faster load times. Also we can read the file without printing the output on the terminal.

history | grep start - "grep":Globally search for regular expression and print out.

Every program has 3 built-in streams:

STDIN (0) - Standard input
STDOUT (1) - Standard Output
STDERR (2) - Standard Error

Networking:

Switch: Sits within the LAN. Facilitates the connection between all the devices within the LAN.
Router: Sits between LAN and outside networks(WAN-Wide Area Network). Connects devices on LAN and WAN. Allows networked devices to access the internet.

Devices in the LAN belongs to same IP address range.

Subnet=logical subdivision of an IP network

Subnetting=Process of dividing a network into two or more networks.

CIDR(Classless Inter-Domain Routing) Block: Subnet mask dictates how many bits are fixed.

255.255.0.0(subnet mask) - means the 16 bits are fixed(i.e., 255.255.)
255.255.255.0 - means 24 bits are fixed

We can also represent this for an IP address starting with 192.168.0.0, as follows:

192.168.0.0/16 - /16 bits are fixed
(OR)
192.168.0.0/24 - /24 bits are fixed.

Network Address Translation (NAT):When we send a request to connect to a site like facebook , our laptop IP address range does not arrive at facebook server instead it is replaced by the IP address of the router. Router is called a network address translation(NAT is key functionality of the Router).

Domain Name Service(DNS): Translates domain names to IP addresses.

Network Commands:

ifconfig - to get IP address
netstat -lpnt - shows active connections(actively listening ports)
ps aux - current running processes, on which ports they are running along with resources info
nslookup - To get IP address of any domain.
ping - To check a service is accessible or not.

Other:
List alias - alias -p
Remve alias - unalias [alias_name]
Check processes running on specific port: lsof -i :port_number(example: lsof -i :8080)


───────── Source & Credits to: TechWorldWithNana & BestTechReads ─────────

DISCLAIMER

This content has been shared under Educational And Non-Profit Purposes Only. No Copyright Infringement Intended, All Rights Reserved to the Actual Owner

The purpose of sharing the content on this website is to Educate. The author/owner of the content does not warrant that the information provided on this website is fully complete and shall not be responsible for any errors or omissions. The author/owner shall have neither liability nor responsibility to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the contents of this website. So, use the content of this website at your own risk.

For Copyright Content Removal Please Contact us by Email at besttechreads[at]gmail.com

Post a Comment

Previous Post Next Post