🚀 Mastering Linux System Administration & Automation | 90 Days of DevOps - Week 2
🔹 From user management to automated backups – A hands-on journey into Linux system administration & automation for DevOps! 💻
Task 4 : Volume Management & Disk Usage
4️⃣ Volume Management & Disk Usage
Task:
Create a directory
/mnt/devops_data
.Mount a new volume (or loop device for local practice).
Verify using
df -h
andmount | grep devops_data
.
Step 1: Create a Directory
sudo mkdir -p /mnt/devops_data
Why? Directories are mount points for attaching storage.
Step 2: Create a Loop Device (Virtual Disk)
sudo dd if=/dev/zero of=/loop_devops.img bs=1M count=1024
sudo mkfs.ext4 /loop_devops.img
Pro Tip: dd
creates raw binary files, while mkfs
formats them.
Step 3: Mount the Virtual Disk
sudo mount -o loop /loop_devops.img /mnt/devops_data
Verification:
df -h | grep devops_data # Check disk space
mount | grep devops_data # Confirm mount details
/loop_devops.img 969M 2.6M 900M 1% /mnt/devops_data
Task 5 : Process Management & Monitoring
5️⃣ Process Management & Monitoring
Task:
Start a background process (
ping
google.com
> ping_test.log &
).Use
ps
,top
, andhtop
to monitor it.Kill the process and verify it's gone.
Step 1: Start Background Process
ping google.com > ping_test.log &
Note: &
runs the process in the background.
Step 2: Monitor with CLI Tools
ps
:ps aux | grep ping
top
: Interactive process viewer (sort withShift+M
for memory)htop
: Colorful, user-friendly alternative (install viasudo apt install htop
)
Step 3: Terminate the Process
kill -9 <PID> # Replace with actual Process ID
pkill -f "ping google.com" # Pattern-based kill
Verification:
ps aux | grep ping # Should show only the grep command
ls -lh ping_test.log # Check if file size stopped growing
6️⃣ Automate Backups with Shell Scripting
Task:
Write a shell script to back up
/devops_workspace
asbackup_$(date +%F).tar.gz
.Save it in
/backups
and schedule it usingcron
.Make the script display a success message in green text using
echo -e
.
Step 1 : Write a shell script to back up
/devops_workspace
asbackup_$(date +%F).tar.gz
.
This is the shell script that can take a periodic backup of the scripts / directories and also uploads the backup to aws s3
Step 2 : Save it in /backups
and schedule it using cron
.
I have scheduled a periodic backup for every minute. below is the example script for taking backup every minute.
write a command crontab -e
to shcedule a cron.
By Saving the above script, we have to enter a command watch ls
this command shows the live page of the entered command
This above script displays the live backup process.
🔥 Key Takeaways:
✔ Linux administration is the foundation of DevOps!
✔ Automating tasks with shell scripting boosts efficiency.
✔ Logs are gold for debugging and monitoring.
✔ Managing users, processes, and storage is essential in production environments.