Cloud Knowledge

Your Go-To Hub for Cloud Solutions & Insights

Advertisement

The Ultimate Guide to Storage, Partitioning, and Task Scheduling in Linux

Storage, Partitioning, and Task Scheduling in Linux

Linux is renowned for its versatility, and two essential aspects of system management are storage and partitioning and task scheduling. Whether you’re managing disks, scheduling automated tasks, or enhancing security, Linux provides powerful tools to streamline your operations. This article will explore critical concepts and tools like the lsblk command, disk partitioning methods, crontab, and more.

What is the lsblk Command in Linux?

The lsblk command in Linux lists detailed information about all block devices, such as hard drives, SSDs, USB drives, and their partitions. It’s a vital tool for understanding the system’s storage architecture.

Key Uses of lsblk:
  1. View Block Devices: Lists all block devices on the system.
  2. Check Partition Structure: Displays the partitions and how they’re organized.
  3. Check Mount Points: Identifies where each device is mounted in the filesystem.
  4. Display Device Sizes: Reveals the size of devices and partitions.
Basic Syntax
lsblk [options]
Common Options
  • -a: Show all devices (including empty ones).
  • -f: Display filesystem information (e.g., type, label).
  • -o: Customize the output columns (e.g., NAME, SIZE).
Example Command
 
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT
 

How to Perform Disk Partitioning in Ubuntu

Disk partitioning divides a disk into smaller units, allowing multiple filesystems or operating systems. Here are popular methods:

Using GParted (GUI)
  1. Install GParted:
     
    sudo apt update sudo apt install gparted
  2. Open GParted and select the disk.
  3. Create a partition table (GPT or MBR).
  4. Allocate unallocated space and format the partition.
Using fdisk (Command Line)
  1. View available disks:
    sudo fdisk -l
  2. Partition a disk:
    sudo fdisk /dev/sdX
    • Use n to create a new partition.
    • Specify partition size (e.g., +10G).
  3. Format the partition:
    sudo mkfs.ext4 /dev/sdX1
Using parted (For Larger Disks)
  1. Start parted:
    sudo parted /dev/sdX
  2. Create a GPT partition table:
    mklabel gpt
  3. Create and format partitions:
    mkpart primary ext4 0% 50GB sudo mkfs.ext4 /dev/sdX1

Task Scheduling with Cron and At in Linux

What is Crontab and Cron Jobs?

The crontab file defines scheduled tasks (cron jobs) in Linux. Each cron job specifies the command, its execution time, and intervals.

Crontab Syntax
* * * * * /path/to/command
| | | | |
| | | | +---- Day of the week (0-7, Sunday = 0 or 7)
| | | +------ Month (1-12)
| | +-------- Day of the month (1-31)
| +---------- Hour (0-23)
+------------ Minute (0-59)
Example Cron Jobs
  • Run a script daily at 3 AM:
    0 3 * * * /path/to/script.sh
  • List user cron jobs:
    crontab -l
  • Remove all cron jobs:
    crontab -r
Using at for One-Time Scheduling
  1. Schedule a task at 2:30 PM:
    echo "/path/to/script.sh" | at 2:30 PM
  2. View scheduled jobs:
    atq
  3. Remove a job:
    atrm <job_id>

Enhancing Security with SELinux and UFW

SELinux (Security-Enhanced Linux)

SELinux enforces access control policies, adding a layer of protection.

  • Check SELinux Status:
    sestatus
  • Change Mode:
    sudo setenforce 0 # Permissive
    sudo setenforce 1 # Enforcing
Firewall Management with UFW
  • Enable the firewall:
    sudo ufw enable
  • Allow HTTP traffic:
    sudo ufw allow 80
  • Check UFW status:
    sudo ufw status

Conclusion

Mastering Linux tools like lsblk, fdisk, parted, and cron can significantly improve your system administration efficiency. Whether partitioning disks, scheduling automated tasks, or securing your environment with SELinux and UFW, these tools and techniques are foundational for any Linux user or administrator.

Stay tuned for more insights into Linux storage, partitioning, and system management!

Leave a Reply

Your email address will not be published. Required fields are marked *