Unit 2. Overview

Unit 2. Overview
2.1. Logging in & out
2.2 I-node and File System Structure
2.3 Booting Sequence & ‘init’ process
2.4 File Access Permissions
Logging In and Logging Out in Linux.
Logging In to a Linux System
When you start or access a Linux system, you must first log in with a valid username and password.
This process authenticates your identity and starts a session.
✅ Login Methods
There are different ways users can log into a Linux system depending on the interface and environment:
1. Graphical Login (GUI-based Login)
Used in desktop environments like GNOME, KDE, or XFCE.
A login screen appears with fields for username and password.
After successful login, the user is directed to their desktop environment.
2. Terminal Login (Command-Line Interface)
🔹 When using a local terminal:
Press
Ctrl + Alt + F1
toF6
to switch to a virtual terminal.You’ll see a login prompt like:
makefilelogin: your_username Password: ********
Upon success, you enter the command-line shell (e.g., Bash).
🔹 When connecting remotely via SSH:
SSH (Secure Shell) allows login to a Linux machine over a network.
Example command (from another system):
username@hostname_or_ip
You’ll be prompted to enter your password.
🛠 What Happens After You Log In?
The system verifies your username and password.
It loads your user environment (like
.bash_profile
or.bashrc
).A shell session is started (usually Bash).
You can now run commands, launch applications, or manage files.
🔒 Security Tips During Login
Always use a strong password.
Avoid logging in as root unless necessary.
Use SSH keys for secure remote login.
Monitor login attempts using:
last who
Logging Out of a Linux System
Logging out ends your user session and releases system resources.
✅ Logout Methods
1. In GUI (Graphical Interface)
Click the logout, shutdown, or exit option from the system menu.
This closes the graphical session and returns to the login screen or powers off.
2. In Terminal (Command Line)
You can log out of the shell session using one of the following:
Command | Description |
---|---|
exit |
Ends the current shell session |
logout |
Logs out from a login shell |
Ctrl + D | Sends EOF (End of File) signal to log out |
🔁 Ending SSH Session
If you logged in via SSH, just type:
exit
Or press Ctrl + D
. This will close the connection to the remote machine.
📋 Commands to View Login Information.
Command | Purpose |
---|---|
whoami |
Displays your current username |
who |
Shows who is logged into the system |
w |
Lists users and what they are doing |
last |
Shows the history of user logins |
id |
Displays user ID and group ID information |
Understanding I-node and File System Structure in Linux/UNIX.
📁 What is a File System?
A file system in Linux/UNIX is a method for storing and organizing files and directories on a storage device like a hard disk or SSD.
It allows the operating system to keep track of where files are stored and how to access them.
📂 Structure of a Linux/UNIX File System
The typical structure of a file system includes the following components:
Boot Block → Contains bootloader code |
Super Block → Holds metadata about the file system |
I-node Table → Stores information (metadata) about files |
Data Blocks → Stores actual file contents |
🔧 1. Boot Block
Located at the beginning of the file system.
Contains the boot loader, responsible for loading the operating system during startup.
📑 2. Super Block
Contains vital information about the file system:
File system type
Size
Number of inodes and blocks
Block size
Mount status
It is essential for mounting and managing the file system.
🧱 3. I-node Table
The inode (index node) is a critical data structure used to store information about files and directories (except their name).
Every file or directory has an associated inode.
📌 I-node (Index Node) Explained
An inode stores metadata about a file, such as:
Metadata | Description |
---|---|
File type | Regular file, directory, link, etc. |
Permissions | Read, write, execute permissions |
Owner and group | UID and GID |
Size | File size in bytes |
Time stamps | Created, modified, accessed |
Link count | Number of hard links |
Pointers to data blocks | Locations of the actual file content |
🔸 Important: File names are not stored in inodes — they are stored in directory entries, which map filenames to inodes.
🧾 4. Data Blocks
These hold the actual contents of files and directories.
Inodes point to these blocks so the system knows where the file data is stored.
🔗 How It All Connects
When a file is accessed, the directory entry provides the inode number.
The inode contains metadata and points to the data blocks.
The data blocks contain the file’s actual content.
🔍 Example Flow: Accessing a File
User accesses: /home/hardik/report.txt
→ OS finds 'report.txt' in the directory structure
→ Retrieves its inode number from directory entry
→ Reads metadata and block pointers from the inode
→ Loads actual data from the data blocks
🧠 Benefits of the I-node-Based File System
Efficient file metadata handling
Supports multiple links to the same file (via inode sharing)
Flexible and scalable for large numbers of files
Separates metadata from filenames for better management
Booting Sequence and the ‘init’ Process in Linux/UNIX.
Booting is the process that starts a computer system and loads the operating system so that it becomes usable.
In Linux and UNIX-based systems, this process is well-structured and involves multiple steps before the user gets access to the system.
🧱 1. BIOS/UEFI Stage.
BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface) is the first code that runs when a system is powered on.
It performs a POST (Power-On Self Test) to check hardware functionality.
Then it searches for a bootable device like a hard drive or USB.
Once found, it hands control over to the bootloader stored on that device.
💻 2. Bootloader Stage (GRUB or LILO)
The bootloader (e.g., GRUB – GRand Unified Bootloader) is a small program responsible for:
Loading and executing the Linux kernel.
Providing a menu to select different OS or kernel versions.
It also passes parameters to the kernel if needed.
🧠 3. Kernel Initialization
Once loaded into memory, the kernel:
Initializes system hardware (CPU, memory, devices).
Sets up memory management and process scheduling.
Mounts the root file system.
Starts the first user-space process, usually
/sbin/init
.
⚙️ 4. The ‘init’ Process
init
is the first user-level process started by the Linux kernel.It always has PID 1 (Process ID 1).
It remains active throughout the session and becomes the parent of all other processes.
🔍 What ‘init’ Does:
Reads Configuration Files:
Traditional
init
refers to/etc/inittab
to determine which processes to start.Defines default runlevel (system state).
Starts System Services:
Based on the runlevel, it launches services like:
Network
Login services
Scheduled jobs
Graphical interface (if applicable)
Maintains Process Tree:
Monitors background services and can restart them if needed.
Handles orphaned processes.
Controls System Shutdown/Reboot:
Initiates proper shutdown procedures by killing processes and unmounting file systems.
🔢 Common Runlevels (in SysV init systems):
Runlevel | Description |
---|---|
0 | Halt the system |
1 | Single-user mode (maintenance) |
3 | Multi-user mode without GUI |
5 | Multi-user mode with GUI |
6 | Reboot the system |
🆕 Modern Alternative: systemd.
Many Linux distributions now use
systemd
, a more advanced and faster init system.Replaces traditional init but still keeps compatibility.
Uses units instead of runlevels and supports parallel startup of services.
Logs events using
journalctl
.
🔁 Summary of the Boot Process:
Booting Step | Description |
---|---|
Power ON | Initial hardware power-up |
BIOS/UEFI → POST | Performs Power-On Self Test to check hardware |
Bootloader (GRUB/LILO) | Loads and executes the Linux kernel |
Kernel Loaded | Initializes system hardware and mounts root file system |
init or systemd starts | Begins user-space initialization and service loading |
Services started → Login/Desktop | Displays login screen or graphical desktop environment |
🔐 File Access Permissions in Linux (Explained in Detail).
In Linux, every file and directory has a set of permissions that controls who can access and manipulate it.
These permissions help ensure security and multi-user control on the system.
📁 Basic Concepts
Each file or directory in Linux has three types of users associated with it:
User Type | Description |
---|---|
Owner | The user who created the file or directory. |
Group | A set of users who share access permissions. |
Others | Everyone else on the system. |
🧪 Types of Permissions.
There are three types of permissions in Linux:
Symbol | Permission | Applies To |
---|---|---|
r | Read | View file content or list directory contents |
w | Write | Modify file content or create/delete files in a directory |
x | Execute | Run the file as a program or access a directory |
🔍 Permission Structure (Using ls -l
).
When you list files using ls -l
, you get output like:
ex :- -rwxr-xr– 1 user group 1234 May 20 12:00 file.sh
Part | Meaning |
---|---|
- | File type (- for file, d for directory, l for link) |
rwx | Owner has read, write, and execute |
r-x | Group has read and execute, but no write |
r-- | Others have read-only access |
⚙️ Changing Permissions with chmod
You can change permissions using the chmod
command.
1. Symbolic Method.
example :-
chmod u+x file.sh # Add execute permission to the user
chmod g-w file.txt # Remove write permission from the group
chmod o=r file.txt # Set read-only for others
Symbol | Refers To |
---|---|
u | User (Owner) |
g | Group |
o | Others |
a | All (user + group + others) |
2. Numeric (Octal) Method.
Permissions are represented using numbers:
Permission | Binary | Octal |
---|---|---|
r | 100 | 4 |
w | 010 | 2 |
x | 001 | 1 |
Example:
chmod 755 file.sh
means:7 (4+2+1)
→ user: read, write, execute5 (4+0+1)
→ group: read, execute5 (4+0+1)
→ others: read, execute
🛡️ Default Permissions: umask.
umask
defines default permission settings when new files/directories are created.For example, a
umask
of022
means:New files: 644 (
rw-r--r--
)New directories: 755 (
rwxr-xr-x
)
📌 Summary Table.
User Type | Read (r) | Write (w) | Execute (x) |
---|---|---|---|
Owner | Yes | Yes | Yes |
Group | Yes | No | Yes |
Others | Yes | No | No |