Mastering Linux Administration: Take your sysadmin skills to the next level by configuring and maintaining Linux systems
By Alexandru Calcatinge and Julian Balog
()
About this ebook
Harness the power of Linux in modern data center management, leveraging its unparalleled versatility for efficiently managing your workloads in on-premises and cloud environments. In this second edition, you'll find updates on the latest advancements in Linux administration including containerization, shell scripting, and hypervisors.
Written by an experienced Linux trainer, this book will start you off with Linux installation on on-premises systems. As you progress, you’ll master the Linux command line, files, packages, and filesystems. You'll explore essential Linux commands and techniques to secure your Linux environment. New to this edition is a chapter on shell scripting, providing structured guidance on using shell programming for basic Linux automation. This book also delves into the world of containers, with two new chapters dedicated to Docker containers and hypervisors, including KVM virtual machines. Once adept with Linux containers, you'll learn about modern cloud technologies, managing and provisioning container workloads using Kubernetes, and automating system tasks using Ansible. Finally, you'll get to grips with deploying Linux to the cloud using AWS and Azure-specific tools.
By the end of this Linux book, you'll have mastered everyday administrative tasks, seamlessly navigating workflows spanning from on-premises to the cloud.
Related to Mastering Linux Administration
Related ebooks
Software Architecture with C# 12 and .NET 8: Build enterprise applications using microservices, DevOps, EF Core, and design patterns for Azure Rating: 0 out of 5 stars0 ratingsCentOS High Availability Rating: 5 out of 5 stars5/5Systems Programming with C# and .NET: Building robust system solutions with C# 12 and .NET 8 Rating: 0 out of 5 stars0 ratingsCentOS High Performance Rating: 0 out of 5 stars0 ratingsNode.js for Beginners: A comprehensive guide to building efficient, full-featured web applications with Node.js Rating: 0 out of 5 stars0 ratingsC++ Cookbook: How to write great code with the latest C++ releases (English Edition) Rating: 0 out of 5 stars0 ratingsPython AI Programming: Navigating fundamentals of ML, deep learning, NLP, and reinforcement learning in practice Rating: 0 out of 5 stars0 ratingsApplied Machine Learning Solutions with Python: SOLUTIONS FOR PYTHON, #1 Rating: 0 out of 5 stars0 ratingsASP.NET 8 Best Practices: Explore techniques, patterns, and practices to develop effective large-scale .NET web apps Rating: 0 out of 5 stars0 ratingsJetpack Compose 1.5 Essentials: Developing Android Apps with Jetpack Compose 1.5, Android Studio, and Kotlin Rating: 0 out of 5 stars0 ratingsLearn C++ by Example: Covers versions 11 to 23 Rating: 0 out of 5 stars0 ratingsBuilding Scalable Web Apps with Node.js and Express Rating: 0 out of 5 stars0 ratingsFast Python: High performance techniques for large datasets Rating: 0 out of 5 stars0 ratingsScala for Machine Learning Rating: 0 out of 5 stars0 ratingsTroubleshooting Java: Read, debug, and optimize JVM applications Rating: 0 out of 5 stars0 ratingsThe Art of Docker: Streamline App Development and Deployment with Containerization (Computer Programming) Rating: 0 out of 5 stars0 ratingsTools and Skills for .NET 8: Get the career you want with good practices and patterns to design, debug, and test your solutions Rating: 0 out of 5 stars0 ratingsHands-On Microservices with Django: Build cloud-native and reactive applications with Python using Django 5 Rating: 0 out of 5 stars0 ratingsJulia as a Second Language Rating: 0 out of 5 stars0 ratingsBash Cookbook: Leverage Bash scripting to automate daily tasks and improve productivity Rating: 0 out of 5 stars0 ratingsPHP and MySQL Web Development All-in-One Desk Reference For Dummies Rating: 0 out of 5 stars0 ratingsCybersecurity - Attack and Defense Strategies: Infrastructure security with Red Team and Blue Team tactics Rating: 5 out of 5 stars5/5Introducing Deno: A First Look at the Newest JavaScript Runtime Rating: 0 out of 5 stars0 ratingsiOS in Practice Rating: 0 out of 5 stars0 ratings
System Administration For You
CompTIA A+ Complete Review Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 5 out of 5 stars5/5Linux for Beginners: Linux Command Line, Linux Programming and Linux Operating System Rating: 4 out of 5 stars4/5Networking for System Administrators: IT Mastery, #5 Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Practical Data Analysis Rating: 4 out of 5 stars4/5Bash Command Line Pro Tips Rating: 5 out of 5 stars5/5Learning Microsoft Endpoint Manager: Unified Endpoint Management with Intune and the Enterprise Mobility + Security Suite Rating: 0 out of 5 stars0 ratingsPowerShell: A Beginner's Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Cybersecurity: The Beginner's Guide: A comprehensive guide to getting started in cybersecurity Rating: 5 out of 5 stars5/5Linux Command-Line Tips & Tricks Rating: 0 out of 5 stars0 ratingsHow To Speed Up Computer: Your Step-By-Step Guide To Speeding Up Computer Rating: 0 out of 5 stars0 ratingsLinux Bible Rating: 0 out of 5 stars0 ratingsEthical Hacking Rating: 4 out of 5 stars4/5The Complete Powershell Training for Beginners Rating: 0 out of 5 stars0 ratingsLinux Commands By Example Rating: 5 out of 5 stars5/5Citrix Virtual Apps and Desktops Troubleshooting Rating: 5 out of 5 stars5/5Mastering Windows PowerShell Scripting Rating: 4 out of 5 stars4/5Easy Linux For Beginners Rating: 2 out of 5 stars2/5PowerShell: A Comprehensive Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Command Line Git - Everything You Need To Know To Get Started Rating: 0 out of 5 stars0 ratingsPowerShell Automation and Scripting for Cybersecurity: Hacking and defense for red and blue teamers Rating: 0 out of 5 stars0 ratingsLearn SQL Server Administration in a Month of Lunches Rating: 3 out of 5 stars3/5ServiceNow IT Operations Management Rating: 5 out of 5 stars5/5Improve your skills with Google Sheets: Professional training Rating: 0 out of 5 stars0 ratingsFreeBSD Mastery: Jails: IT Mastery, #15 Rating: 5 out of 5 stars5/5How To Recover Deleted Files: Your Step-By-Step Guide To Recovering Deleted Files Rating: 0 out of 5 stars0 ratingsLinux Shell Scripting Cookbook - Third Edition Rating: 4 out of 5 stars4/5
Reviews for Mastering Linux Administration
0 ratings0 reviews
Book preview
Mastering Linux Administration - Alexandru Calcatinge
Mastering Linux Administration
Copyright © 2024 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Pavan Ramchandani
Publishing Product Manager: Prachi Sawant
Book Project Manager: Ashwini Gowda
Senior Editors: Shruti Menon and Adrija Mitra
Technical Editor: Irfa Ansari
Copy Editor: Safis Editing
Proofreader: Safis Editing
Indexer: Rekha Nair
Production Designer: Jyoti Kadam
Senior DevRel Marketing Coordinator: Marylou De Mello
First published: June 2021
Second edition: March 2024
Production reference: 1230224
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB, UK.
ISBN 978-1-83763-069-1
www.packtpub.com
This is to everyone who did not believe in me, and to everyone who believed in me.
To my mother and father, my twin sister, my beloved Uca, and my truthful friends.
In memory of my late grandfather, Miron, who would have loved to see this new book finished before he passed away.
Contributors
About the author
Alexandru Calcatinge is an open-minded architect with a background in computer science and mathematics. He is a senior university lecturer with a PhD in urban planning from Ion Mincu University of Architecture and Urban Planning and a postgraduate degree in DevOps from Caltech’s Center for Technology and Management Education (CTME). He teaches students about architectural programming and development and open source technologies. He has authored five books on architecture and urban planning and numerous scientific articles on urban and rural development. Alex was certified as a Linux trainer in 2017. He loves the DevOps philosophy and the possibilities that cloud technologies bring for the future. He is also a certified programming analyst, computer network administrator, trainer, designer, and life coach.
I want to thank the people who have been close to me and supported me unconditionally, especially my parents, my twin sister, and my friends. I want to express my deepest gratitude to my one and only Uca for sticking by my side during a time of turmoil, and for her constant support and trust in me.
Julian Balog is a senior software engineer with more than 15 years of experience in the industry. Currently, his work primarily focuses on application delivery controllers, containerized workflows, networking, and security. With a never-ending passion for Linux and open-source technologies, Julian is always in pursuit of learning new things while solving problems and making things work through simple, efficient, and practical engineering. He lives with his wife, two children, and an Aussie-doodle in the greater Seattle area, Washington.
The authors would like to thank the wonderful editorial and production team at Packt for their professional leadership, dedication, and guidance throughout the writing of this book. We are indebted to them for many helpful suggestions and the comprehensive revision of the drafts. We are also grateful to the reviewers for their critical comments. We could not have hoped for a better team and support.
About the reviewers
Himanshu Sharma has nearly 18 years of experience in designing, architecting, and developing cloud and network software. He previously worked for some of the biggest companies such as Brocade and Juniper and start-ups such as Netskope. Currently, he is working with Netskope as a Principal Engineer, responsible for Netskope’s security service offering. He designed, architected, and developed Netskope’s advanced threat protection services from the ground up. He has a keen interest and experience in developing scalable cloud services with cutting-edge technologies. His favorite hobbies are skiing and playing video games.
I would like to thank my wife, Puja, who gave me all her support, and my two loving and beautiful daughters, Navya and Jaanvi.
Also, I want to thank my brother, Sudhanshu, for always having my back, and my parents for all their sacrifices to get me where I am today.
Dennis Salamanca is a passionate technology enthusiast with a solid track record of over 12 years in the IT industry. Throughout his career, he has had the privilege of working with renowned industry leaders such as Amazon, VMware, Microsoft, and Hewlett-Packard Enterprise. His dedication to continuous learning is reflected in an extensive collection of over 15 technical certifications spanning various domains including cloud, storage, Linux, Kubernetes, and virtualization. Notably, he is actively involved in the development team for Linux+ and Cloud+ certifications and proudly contributes as a member of the esteemed CompTIA Linux and Cloud Subject Matter Experts and Technical Advisory Committee.
I would like to acknowledge my wife and family for all their support over these years. Without their motivation and support, nothing would’ve been possible.
Table of Contents
Preface
Part 1: Basic Linux Administration
1
Installing Linux
Technical requirements
Introducing the Linux operating system
Exploring Linux distributions
Choosing a Linux distribution
Installing Linux – the basics
How to install Linux on bare metal
Linux in a VM
VM provisioning using Hyper-V
VM provisioning using Oracle’s VirtualBox
Enabling Windows Subsystem for Linux
Installing Linux – the advanced stages
The Linux boot process
PXE network boot explained
Linux distributions – a practical guide
Case study – development workstation
Case study – secure web server
Use case – personal blog
Use case – media server
Summary
Questions
Further reading
2
The Linux Shell and Filesystem
Technical requirements
Introducing the Linux shell
Establishing the shell connection
The command-line prompt
Shell command types
Explaining the command structure
Consulting the manual
The Linux filesystem
Directory structure
Working with files and directories
Understanding file paths
Basic file operations
Commands for file viewing
Commands for file properties
Using text editors to create and edit files
Using Vim to edit text files
The nano text editor
Summary
Questions
Further reading
3
Linux Software Management
Technical requirements
Linux software package types
The DEB and RPM package types
The snap and flatpak package types
Managing software packages
Managing DEB packages
Managing RPM packages
Using the snap and flatpak packages
Installing new desktop environments in Linux
Installing KDE Plasma on Fedora Linux
Summary
Questions
Further reading
4
Managing Users and Groups
Technical requirements
Managing users
Understanding sudo
Creating, modifying, and deleting users
Managing groups
Creating, modifying, and deleting groups
Managing permissions
File and directory permissions
Summary
Questions
Further reading
5
Working with Processes, Daemons, and Signals
Technical requirements
Introducing processes
Understanding process types
The anatomy of a process
Working with processes
Using the ps command
Using the pstree command
Using the top command
Using the kill and killall commands
Using the pgrep and pkill commands
Working with daemons
Working with systemd daemons
Explaining inter-process communication
Working with signals
Summary
Questions
Further reading
Part 2: Advanced Linux Administration
6
Working with Disks and Filesystems
Technical requirements
Understanding devices in Linux
Linux abstraction layers
Device files and naming conventions
Understanding filesystem types in Linux
Understanding disks and partitions
Common disk types
Partitioning disks
Introducing LVM in Linux
LVM snapshots
Summary
Questions
Further reading
7
Networking with Linux
Technical requirements
Exploring basic networking
Computer networks
The OSI model
The TCP/IP network stack model
TCP/IP protocols
IP addresses
Sockets and ports
Linux network configuration
Working with network services
DHCP servers
DNS servers
Authentication servers
File sharing
Printer servers
File transfer
Mail servers
NTP servers
Remote access
Understanding network security
Summary
Questions
Further reading
8
Linux Shell Scripting
Technical requirements
Exploring the Linux shell
Bash shell features
Bash shell variables
Basics of shell scripting
Creating a shell script file
Variables in shell scripts
Using mathematical expressions in shell scripts
Using programming structures
Using arrays in Bash
Reading input data
Formatting output data
Understanding exit statuses and testing structures
Using conditional if statements
Using looping statements
Working with functions
Using sed and (g)awk commands
Using scripts to showcase interprocess communication
Shared storage
Unnamed pipes
Named pipes
Sockets
Scripting for administrative tasks
Creating scripts for system administrative tasks
Packaging scripts
Summary
Questions
Further reading
9
Securing Linux
Technical requirements
Understanding Linux security
Introducing SELinux
Working with SELinux
Introducing AppArmor
Working with AppArmor
Final considerations
Working with firewalls
Understanding the firewall chain
Introducing Netfilter
Working with iptables
Introducing nftables
Using firewall managers
Summary
Exercises
Further reading
10
Disaster Recovery, Diagnostics, and Troubleshooting
Technical requirements
Planning for disaster recovery
A brief introduction to risk management
Risk calculation
Designing a DRP
Backing up and restoring the system
Disk cloning solutions
Introducing common Linux diagnostic tools for troubleshooting
Tools for troubleshooting boot issues
Tools for troubleshooting general system issues
Tools for troubleshooting network issues
Tools for troubleshooting hardware issues
Summary
Questions
Further reading
Part 3: Server Administration
11
Working with Virtual Machines
Technical requirements
Introduction to virtualization on Linux
Efficiency in resource usage
Introduction to hypervisors
Understanding Linux KVMs
Choosing the hypervisor
Using the KVM hypervisor
Working with basic KVM commands
Creating a VM using the command line
Basic VM management
Advanced KVM management
Connecting to a VM
Cloning VMs
Creating VM templates
Obtaining VM and host resource information
Managing VM resource usage
Provisioning VMs using cloud-init
Understanding how cloud-init works
Installing and configuring cloud-init
Public key authentication with SSH
Summary
Exercises
Further reading
12
Managing Containers with Docker
Technical requirements
Understanding Linux containers
Comparing containers and VMs
Understanding the underlying container technology
Understanding Docker
Working with Docker
Which Docker version to choose?
Installing Docker
Using some Docker commands
Managing Docker containers
Working with Dockerfiles
Building container images from Dockerfiles
Deploying a containerized application with Docker
Deploying a website using Docker
Summary
Questions
Further reading
13
Configuring Linux Servers
Technical requirements
Introducing Linux services
Setting up SSH
Installing and configuring OpenSSH on Ubuntu
Setting up a DNS server
Caching a DNS service
Creating a primary DNS server
Setting up a secondary DNS server
Setting up a DHCP server
Setting up an NFS server
Installing and configuring the NFS server
Configuring the NFS client
Testing the NFS setup
Setting up a Samba file server
Installing and configuring Samba
Creating Samba users
Accessing the Samba shares
Summary
Questions
Further reading
Part 4: Cloud Administration
14
Short Introduction to Cloud Computing
Technical requirements
Introduction to cloud technologies
Exploring the cloud computing standards
Understanding the architecture of the cloud
Knowing the key features of cloud computing
Introducing IaaS solutions
Amazon EC2
Microsoft Azure Virtual Machines
Other strong IaaS offerings
Introducing PaaS solutions
Amazon Elastic Beanstalk
Google App Engine
DigitalOcean App Platform
Open source PaaS solutions
Introducing CaaS solutions
Introducing the Kubernetes container orchestration solution
Deploying containers in the cloud
Introducing microservices
Introducing DevOps
Exploring cloud management tools
Ansible
Puppet
Chef Infra
Summary
Further reading
15
Deploying to the Cloud with AWS and Azure
Technical requirements
Working with AWS EC2
Introducing and creating AWS EC2 instances
Introducing AWS EC2 placement groups
Using AWS EC2 instances
Working with the AWS CLI
Working with Microsoft Azure
Creating and deploying a virtual machine
Connecting with SSH to a virtual machine
Managing virtual machines
Working with the Azure CLI
Summary
Questions
Further reading
16
Deploying Applications with Kubernetes
Technical requirements
Introducing Kubernetes
Understanding the Kubernetes architecture
Introducing the Kubernetes object model
The anatomy of a Kubernetes cluster
Installing and configuring Kubernetes
Installing Kubernetes on a desktop
Installing Kubernetes on VMs
Working with Kubernetes
Using kubectl
Deploying applications
Running Kubernetes in the cloud
Summary
Questions
Further reading
17
Infrastructure and Automation with Ansible
Technical requirements
Introducing Ansible architecture and configuration management
Understanding the Ansible architecture
Introducing configuration management
Installing Ansible
Installing Ansible on Ubuntu
Installing Ansible using pip
Working with Ansible
Setting up the lab environment
Configuring Ansible
Using Ansible ad hoc commands
Exploring Ansible modules
Using Ansible playbooks
Using templates with Jinja2
Creating Ansible roles
Summary
Questions
Further reading
Index
Other Books You May Enjoy
Preface
Mastering Linux Administration provides the ultimate coverage of modern server and cloud administration technologies.
Technology evolves at an unprecedented speed, and Linux and related technologies are at the forefront of innovation. This makes it really hard to keep up and learn new things. Present Linux administrators need to know about more than just Linux, thus containerization and cloud technologies are essential for the future DevOps expert.
Linux is the operating system that powers almost everything, from IoT to personal computers to servers, and is the foundation for all cloud technologies. It enables you to master the cloud through the power of the command line.
You will begin by learning about the command line, working with files, processes, users, packages, and filesystems, then you will begin administering network services and hardening security, and finally, you will learn about cloud computing, containers, and orchestration. You will learn how to work at the command line, learn about the most important Linux commands, and master users, processes, and services administration. You will also learn how to harden Linux security using iptables. At the end, you will work with containers, hypervisors, virtual machines, Ansible, and Kubernetes and learn how to deploy Linux on AWS and Azure. By the end of this book, you will have mastered Linux and you will be confident in working with Linux from bare metal to the cloud, in a pure DevOps fashion.
Who this book is for
This book is for Linux administrators who want to understand the fundamentals, as well as modern concepts of Linux system administration. Windows system administrators looking to extend their knowledge to the Linux OS will also benefit from this book.
What this book covers
Chapter 1, Installing Linux, shows you how to install Linux on physical hardware (bare-metal) and inside a virtual machine in Windows. As we are targeting future Linux system administrators, the command line will be used most of the time, with little reference to the GUI. The future Linux professional will learn how to install Linux and how the boot process works.
Chapter 2, The Linux Shell and Filesystem, teaches you how to use the command line and introduces you to the most widely used commands in Linux. You will learn about the structure of a basic command, how the Linux filesystem is organized, the structure of the Linux operating system, and the structure of a file. By the end of the chapter, you will also know how to use VI/VIM, one of the widely used command-line text editors in Linux.
Chapter 3, Linux Software Management, explains how to use specific software management commands, how software packages work depending on the distribution of choice, and how to build your own packages.
Chapter 4, Managing Users and Groups, shows you how to manage user accounts in Linux. This is one of the most important tasks a Linux system administrator should master. You will be introduced to the general concepts, the specific files for user administration, and how to manage accounts. By the end of the chapter, you will know how to work with permissions and how to change them, and you will understand the special permissions and attributes.
Chapter 5, Working with Processes, Daemons, and Signals, explores processes, signals, and services in Linux. You will learn how to manage them, how to use them, and what the differences are between them.
Chapter 6, Working with Disks and Filesystems, teaches you how to manage disks and filesystems, understand storage in Linux, use Logical Volume Management (LVM) systems, and how to mount and partition.
Chapter 7, Networking with Linux, discusses how networking works in Linux, including the key concepts and how to configure your network from the command line and GUI.
Chapter 8, Linux Shell Scripting, shows you how to create and use Bash shell scripts for task automation in Linux. This will prove an invaluable asset for any system administrator.
Chapter 9, Securing Linux, delves into advanced topics of Linux security. You will learn how to work with SELinux and AppArmor.
Chapter 10, Disaster Recovery, Diagnostics, and Troubleshooting, shows you how to do a system backup and restore in a disaster recovery scenario. Also, you will learn how to diagnose and troubleshoot a common array of problems.
Chapter 11, Working with Virtual Machines, describes how to set up and work with KVM virtual machines on Linux.
Chapter 12, Managing Containers with Docker, introduces containers and discusses how to use Docker-specific tools to deploy your applications.
Chapter 13, Configuring Linux Servers, shows you how to configure different types of Linux servers, from Domain Name System (DNS), Dynamic Host Configuration Protocol (DHCP), Secure Shell (SSH), Samba file-sharing servers, and Network File System (NFS). This is one of the core foundations for any good Linux system administrator.
Chapter 14, Short Introduction to Computing, covers the basics of cloud computing. You will be presented with core technologies such as infrastructure-as-a-service (IaaS), platform-as-a-service (PaaS), containers-as-a-service (CaaS), DevOps, and cloud management tools.
Chapter 15, Deploying to the Cloud with AWS and Azure, explains how to deploy Linux to AWS and Azure.
Chapter 16, Deploying Applications with Kubernetes, teaches you how to use Kubernetes to monitor and secure your deployments and how to manage your containers and networks. You will learn what Kubernetes is and how to use its diverse community approaches.
Chapter 17, Infrastructure and Automation with Ansible, introduces Ansible, including how to configure it, and how to manage playbooks, modules, and servers. At the end of this chapter, you will be a master of automation.
To get the most out of this book
You will need Ubuntu Linux LTS or Debian Linux to perform the examples in this book. No prior knowledge of Linux is necessary.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Mastering-Linux-Administration-Second-Edition. If there’s an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: To check the contents of a binary deb package, you can use the ar command.
A block of code is set as follows:
spec:
replicas: 1
Any command-line input or output is written as follows:
$ sudo zypper search nmap
When we wish to draw your attention to a particular part of a code block or command, the relevant lines or items are set in bold:
uid=1004(alex2) gid=1100(admin)
groups=1100(admin),1200(developers),1300(devops),1400(managers)
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: Navigate to Virtual Machines, select your instance, and click Size under Availability + Scale.
Tips or important notes
Appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Share Your Thoughts
Once you’ve read Mastering Linux Administration, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Download a free PDF copy of this book
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?
Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily
Follow these simple steps to get the benefits:
Scan the QR code or visit the link below
https://packt.link/free-ebook/9781837630691
Submit your proof of purchase
That’s it! We’ll send your free PDF and other benefits to your email directly
Part 1:Basic Linux Administration
In this first part, you will master the Linux command line and basic administrative tasks, such as managing users, packages, files, services, processes, signals, and disks.
This part has the following chapters:
Chapter 1, Installing Linux
Chapter 2, The Linux Shell and Filesystem
Chapter 3, Linux Software Management
Chapter 4, Managing Users and Groups
Chapter 5, Working with Processes, Daemons, and Signals
1
Installing Linux
Recent years have been marked by a significant rise in the adoption of Linux as the operating system of choice for both server and desktop computing platforms. From enterprise-grade servers and large-scale cloud infrastructures to individual workstations and small-factor home appliances, Linux has become an ever-present platform for a wide range of applications.
The prevalence of Linux, perhaps now more than ever, brings into the spotlight much-needed administration skills for a growing community of system administrators and developers. In this book, we take a practical approach to Linux administration essentials, with the modern-day system administrator, DevOps team member, and developer in mind.
In this second edition, we will adopt a slightly different approach to installing Linux. As this is a book meant for more advanced readers, we will no longer discuss the basic aspects of installing the operating system in such detail as in the first edition. The information has been updated to the most relevant aspects available as of the beginning of 2023 with regard to operating system versioning.
In this first chapter, we’ll guide you through the Linux installation process, either on physical hardware (bare metal) or using a Virtual Machine (VM).
Here are the topics we cover in this chapter:
Introducing the Linux operating system
Installing Linux – the basics
Enabling the Windows Subsystem for Linux
Installing Linux – the advanced stages
Linux distributions – a practical guide
Technical requirements
We will use the following platforms and technologies in this chapter:
Linux distributions: Ubuntu
VM hypervisors: Oracle VM VirtualBox, VMware Workstation Player, and Hyper-V
VM host platforms: Windows 11 (equally applicable on macOS)
Introducing the Linux operating system
Linux is a relatively modern operating system created in 1991 by Linus Torvalds, a Finnish computer science student from Helsinki. Originally released as a free and open source platform prohibiting commercial redistribution, Linux eventually adopted the GNU General Public Licensing (GPL) model in 1992. This move played a significant role in its wide adoption by the developer community and commercial enterprises alike. It is important to note that the Free Software Foundation community distinctly refers to Linux operating systems (or distributions) as GNU/Linux to emphasize the importance of GNU for free software.
Initially made for Intel x86 processor-based computer architectures, Linux has since been ported to a wide variety of platforms, becoming one of the most popular operating systems currently in use. The genesis of Linux could be considered the origin of an open source alternative to its mighty predecessor, Unix. This system was a commercial-grade operating system developed at the AT&T Bell Labs research center by Ken Thompson and Dennis Ritchie in 1969.
Exploring Linux distributions
A Linux operating system is typically referred to as a distribution. A Linux distribution, or distro, is the installation bundle (usually an ISO image) of an operating system that has a collection of tools, libraries, and additional software packages installed on top of the Linux kernel. A kernel is the core interface between a computer’s hardware and its processes, controlling the communication between the two and managing the underlying resources as efficiently as possible.
The software collection bundled with the Linux kernel typically consists of a bootloader, shell, package management system, graphical user interface, and various software utilities and applications.
The following diagram is a simplified illustration of a generic Linux distribution architecture:
Figure 1.1 – Simplified view of a generic Linux architectureFigure 1.1 – Simplified view of a generic Linux architecture
There are hundreds of Linux distributions currently available. Among the oldest and arguably most popular ones are Debian, Fedora, openSUSE, Arch Linux, and Slackware, with many other Linux distributions either based upon or derived from them. Some of these distros are divided into commercial and community-supported platforms.
Important note
As writing this second edition, CentOS became a rolling release and is the base from which future Red Hat Enterprise Linux (RHEL) versions are derived. Its place was taken by other free community distributions that use the RHEL binaries. Among those, Rocky Linux is a good example, and we will reference it throughout this book. One other community distribution based on RHEL is AlmaLinux.
One of the key differences among Linux distributions is the package management system they use and the related Linux package format. We’ll get into more detail on this topic in Chapter 3. For now, the focus is on choosing the right Linux distribution based on our needs. But before being able to decide, you should first know a little about some of the most widely used distributions. Therefore, in the next section, we will briefly present to you some Linux distros.
Common Linux distributions
This section summarizes the most popular and common Linux distributions at the time of writing this edition, with emphasis on their package manager type. Most of these distros are free and open source platforms. Their commercial-grade variations, if any, are noted:
Fedora, CentOS Stream and RHEL: CentOS and its derivatives use Red Hat Package Manager (RPM) as their package manager. CentOS Stream, now a rolling release distribution, is based on the open source Fedora project. It is suited to both servers and workstations. RHEL is a commercial-grade version derived from CentOS Stream, designed to be a stable platform with long-term support. The community distribution that uses RHEL binaries is Rocky Linux.
Debian: The package manager for Debian and most of its derivatives is Debian Package (DPKG). Debian is releasing at a much slower pace than other Linux distributions, such as Linux Mint or Ubuntu, for example, but it’s relatively more stable.
Ubuntu: Ubuntu uses Advanced Package Tool (APT) and DKPG as package managers. Ubuntu is one of the most popular Linux distributions, releasing every 6 months, with more stable Long Term Support (LTS) releases every other year.
Linux Mint: Linux Mint also uses APT as its package manager. Built on top of Ubuntu, Linux Mint is mostly suitable for desktop use, with a lower memory usage than Ubuntu (with the Cinnamon desktop environment, compared to Ubuntu’s GNOME). There’s also a version of Linux Mint built directly on top of Debian, called Linux Mint Debian Edition (LMDE).
openSUSE: openSUSE uses RPM, Yet another Setup Tool (YaST), and Zypper as package managers. openSUSE has two versions available: one is called Tumbleweed and is a rolling release, a leading-edge Linux distribution; the other is Leap, a regular release version, which uses the same code base as SUSE Linux Enterprise. Both versions are suited to desktop and server environments. SUSE Linux Enterprise Server is a commercial-grade platform. openSUSE was regarded as one of the most user-friendly desktop Linux distributions before the days of Ubuntu.
Important note
In this book, our focus is mainly on the Linux distributions that are widely used in both community and commercial deployments, such as Ubuntu, Fedora/Rocky Linux, and openSUSE. Most of the examples in this book are equally appliable to any Linux distro. We will specify which one we use for given examples or scenarios.
Now that you know a fair amount of information about the most common Linux distros, in the next section we will give you some hints on how to choose a Linux distribution.
Choosing a Linux distribution
There are many aspects involved in selecting a Linux distribution, based on various functional requirements. A comprehensive analysis would be far beyond the scope of this chapter. However, considering a few essential points may help with making the right decision:
Platform: The choice between a server, a desktop, or an embedded platform is probably one of the top decisions in selecting a Linux distribution. Linux server platforms and embedded systems are usually configured with the core operating system services and essential components required for specific applications (such as networking, HTTP, FTP, SSH, and email), mainly for performance and optimization considerations. On the other hand, Linux desktop workstations are loaded (or pre-loaded) with a relatively large number of software packages, including a graphical user interface for a more user-friendly experience. Some Linux distributions come with server and desktop flavors (such as Ubuntu, Fedora, and openSUSE), but most distros have a minimal operating system, with further configuration needed (such as Rocky Linux, and Debian). Usually, such distributions would be good candidates for Linux server platforms. There are also Linux distributions specifically designed for desktop use, such as elementary OS, Pop!_OS, or Deepin. For embedded systems, we have highly optimized Linux distros, such as Raspbian and OpenWRT, to accommodate small-form factor devices with limited hardware resources.
Infrastructure: Today we see a vast array of application and server platform deployments spanning from hardware and local (on-premises) data centers to hypervisors, containers, and cloud infrastructures. Weighing a Linux distribution against any of these types of deployments should take into consideration the resources and costs involved. For example, a multi-CPU, large-memory, and generally high-footprint Linux instance may cost more to run in the cloud or a Virtual Private Server (VPS) hosting infrastructure. Lightweight Linux distributions take fewer resources and are easier to scale in environments with containerized workloads and services (for instance, with Kubernetes and Docker). Most Linux distributions now have their cloud images available for all major public cloud providers (for instance, Amazon AWS, Microsoft Azure, and Google Compute Engine). Docker container images for various Linux distributions are available for download on Docker Hub (https://hub.docker.com). Some Docker images are larger (heavier) than others. For example, the Ubuntu Server Docker image outweighs the Alpine Linux Docker image considerably, and this may tip the balance when choosing one distribution over the other. Also, to address the relatively new shift to containerized workflows and services, some Linux distributions offer a streamlined or more optimized version of their operating system to support the underlying application infrastructure. For example, Fedora features the Fedora CoreOS (for containerized workflows) and Fedora IoT (for Internet of Things ecosystems).
Performance: Arguably, all Linux distributions can be tweaked to high-performance benchmarks in terms of CPU, GPU, memory, and storage. Performance should be considered very closely with the platform and the application of choice. An email backend won’t perform very well on a Raspberry Pi, while a media streaming server would do just fine (with some external storage attached). The configuration effort for tuning the performance should also be taken into consideration. Rocky Linux, Debian, openSUSE, Fedora and Ubuntu all come with server and desktop versions reasonably optimized for their use. The server versions can be easily customized for a particular application or service, by only limiting the software packages to those that are essential for the application. To further boost performance, some would go to the extent of recompiling a lightweight Linux distro (for instance, Gentoo) to benefit from compiler-level optimizations in the kernel for specific subsystems (for instance, the networking stack or user permissions). As with any other criteria, choosing a Linux distribution based on some application or platform performance is a balancing act, and most of the time, common Linux distros will perform exceptionally well.
Security: When considering security, we have to keep in mind that a system is only as secure as its weakest link. An insecure application or system component would put the entire system at risk. Therefore, the security of a Linux distribution should be scrutinized as it pertains to the related application and platform environment. We can talk about desktop security for a Linux distro serving as a desktop workstation, for example, with the user browsing the internet, downloading media, installing various software packages, and running different applications. The safe handling of all these operations (against malware, viruses, and intrusions) would make for a good indicator of how secure a system can be. There are Linux distros that are highly specialized in application security and isolation and are well suited for desktop use: Qubes OS, Kali Linux, Whonix, Tails, and Parrot Security OS. Some of these distributions have been developed for penetration testing and security research.
On the other hand, we may consider the server security aspect of Linux server distributions. In this case, regular operating system updates with the latest repositories, packages, and components would go a long way to securing the system. Removing unused network-facing services and configuring stricter firewall rules are further steps for reducing the possible attack surface. Most Linux distributions are well equipped with the required tools and services to accommodate this reconfiguration. Opting for a distro with frequent and stable upgrades or release cycles is generally the first prerequisite for a secure platform (for instance, Rocky Linux, RHEL, Ubuntu LTS, or SUSE Enterprise Linux).
Reliability: Linux distributions with aggressive release cycles and a relatively large amount of new code added in each release are usually less stable. For such distros, it’s essential to choose a stable version. Fedora, for example, has rapid releases, being one of the fastest-progressing Linux platforms. Yet, we should not heed the myths claiming that Fedora or other similar fast-evolving Linux distros, such as openSUSE Tumbleweed, are less reliable. Don’t forget, some of the most reliable Linux distributions out there, RHEL and SUSE Linux Enterprise (SLE), are derived from Fedora and openSUSE, respectively.
There’s no magic formula for deciding on a Linux distribution. In most cases, the choice of platform (be it server, desktop or IoT) combined with your own personal preferences is what determines the Linux distribution to go for. With production-grade environments, most of the previously enumerated criteria become critical, and the available options for our Linux platform of choice would be reduced to a few industry-proven solutions.
Important note
In this book, our focus is mainly on the Linux distributions that are widely used in both community and commercial deployments, such as Ubuntu, Fedora/Rocky Linux, and openSUSE. That said, most of the examples in this book are equally applicable to any Linux distro. We will specify which one we use for given examples or scenarios.
Now that you know a bit about what a Linux distribution is, along with the most commonly used ones and their use cases, in the following two sections we will present the basic and advanced aspects of Linux installation.
Installing Linux – the basics
This section serves as a quick guide for the basic installation of an arbitrary Linux distribution. For hands-on examples and specific guidelines, we use Ubuntu. We also take a brief look at different environments hosting a Linux installation. There is an emerging trend of hybrid cloud infrastructures, with a mix of on-premises data center and public cloud deployments, where a Linux host can either be a bare-metal system, a hypervisor, a VM, or a Docker container.
In most of these cases, the same principles apply when performing a Linux installation. For detail on Docker-containerized Linux deployments, see Chapter 13.
In the following sections, we will show you how to install Linux on bare metal and on a Windows 11 host using different VM hypervisors, and using WSL. Installing on a macOS host is basically the same as installing on Windows using a VM hypervisor, and we will not cover that.
How to install Linux on bare metal
This section describes the essential steps required for a Linux installation on bare metal. We use this term when referring to hardware such as laptops, desktops, workstations, and servers. In a nutshell, the main steps are downloading the ISO image, creating bootable media, trying out the live mode, and finally, doing the installation.
The steps used here are equally applicable to virtual machine installations, as you will see in the following sections.
Step 1 – Download
We start by downloading our Linux distribution of choice. Most distributions are typically available in ISO format on the distribution’s website. For example, we can download Ubuntu Desktop at https://ubuntu.com/download/desktop.
Using the ISO image, in the next step we can create the bootable media required for the Linux installation. We can also use the ISO image to install Linux in a VM, as shown in the next section.
Step 2 – Create the bootable media
As we install Linux on a PC desktop or workstation (bare-metal) system, the bootable Linux media is generally a CD/DVD or a USB device. With a DVD-writable optical drive at hand, we can simply burn a DVD with our Linux distribution ISO. But because modern-day computers, especially laptops, rarely come equipped with a CD or a DVD unit of any kind, the more common choice for bootable media is a USB drive.
Important note
There’s also a third possibility of using a Preboot eXecution Environment (PXE) boot server. PXE (pronounced pixie) is a client-server environment where a PXE-enabled client (PC/BIOS) loads and boots a software package over a local or wide area network from a PXE-enabled server. PXE eliminates the need for physical boot devices (CD/DVD, USB) and reduces the installation overhead, especially for a large number of clients and operating systems. Probing the depths of PXE internals is beyond the scope of this chapter, but we will give you a short introduction on how it works for Linux installations by the end of this chapter. A good starting point to learn more about PXE is https://en.wikipedia.org/wiki/Preboot_Execution_Environment.
A relatively straightforward way to produce a bootable USB drive with a Linux distribution of our choice is via using tools such a UNetbootin (https://unetbootin.github.io) or Balena Etcher (https://www.balena.io/etcher). Both UNetbootin and Etcher are cross-platform utilities, running on Windows, Linux, and macOS.
We will use Balena Etcher for this example of creating a bootable USB drive in Windows:
Figure 1.2 – Create a bootable USB drive with Balena EtcherFigure 1.2 – Create a bootable USB drive with Balena Etcher
Here are the basic steps for creating a bootable USB drive with Ubuntu Desktop using Balena Etcher. We assume the Ubuntu Desktop ISO image has been downloaded and Etcher is installed (in our case on Windows 11):
Choose the ISO file with your Linux distribution of choice.
Select the USB target destination disk.
Flash the previously selected disk with the ISO of your choice.
The process should take a couple of minutes and the USB drive will be ready. Now, let’s look at how we can take the bootable media for a spin.
Step 3 – Try it out in live mode
This step is optional.
Most Linux distributions have their ISO image available for download as live media. We say most because not all of them offer this option, at least not by default. Nevertheless, among those who do offer live media by default are Ubuntu and Fedora.
Once we have the bootable media created with our Linux distribution of choice, we can run a live environment of our Linux platform without actually installing it. In other words, we can evaluate and test the Linux distribution before deciding whether we want to install it or not. The live Linux operating system is loaded in the system memory (RAM) of our PC, without using any disk storage. We should make sure the PC has enough RAM to accommodate the minimum required memory of our Linux distribution.
When booting the PC from a bootable media, we need to make sure the boot order in the BIOS is set to read our drive with the highest priority. On a Mac, we need to press the Option key immediately after the reboot start-up chime and select our USB drive to boot from. When on a PC, make sure you access your BIOS interface and select the appropriate device for boot. Depending on your system, you will either have to press one of the F2, F10, F12, or F1 keys after hitting Enter, or the Delete key, as a general rule. In some specific cases, there could be another Function key assigned for this. The keys that you need to press are usually specified at the bottom of the initial bootup screen.
Upon reboot, the first splash screen of our Linux distribution should give us the option of running in live mode, as seen in the following illustration for Ubuntu Desktop (Try Ubuntu):
Figure 1.3 – Choosing live mode for Ubuntu DesktopFigure 1.3 – Choosing live mode for Ubuntu Desktop
Next, let’s take a look at the installation procedure of our Linux distro, using the bootable media.
Step 4 – Perform the installation
We start the installation of our Linux distribution by booting the PC from the bootable media created in step 2. To ensure the system can boot from our external device, we are sometimes required to change the boot order in the BIOS, especially if we boot from a USB drive. Do as specified in the previous paragraph to select the right boot drive.
In the following sections, we showcase the installation process of Ubuntu using its ISO images. We choose the Desktop and Server versions for Ubuntu and highlight the main differences between them. As a comparison, Rocky Linux and CentOS Stream come in a single flavor, in essence, a server platform with an optional graphical user interface. Similar to those, openSUSE offers one installation medium for both desktop and server installs. Fedora, on the other hand, has different installation mediums for desktop and server.
We will now walk you through the process of installing Linux inside a VM.
Linux in a VM
In each of the subsections in the Installing Linux section, we will also provide a brief guide on how to prepare a VM environment for the related Linux platform.
A VM is an isolated software abstraction of a physical machine. VMs are deployed on top of a hypervisor. A hypervisor provides the runtime provisioning and resource management of VMs. A couple of general-purpose hypervisors used are the following:
Oracle VM VirtualBox (https://www.virtualbox.org)
VMware Workstation (https://www.vmware.com/products/workstation-pro.html)
Hyper-V (available only in Windows Pro, Enterprise, or Education)
The first two of these hypervisors are cross-platform virtualization applications and run on both Intel and AMD processor architectures on Windows, macOS, and Linux. The latter is only available on Windows Pro, versions 10 and 11.
Important note
At the time of writing this book, hypervisors for the Apple silicon Macs are provided only by VMware Player and Parallels. Oracle VirtualBox is still in preview for the Advanced RISC Machines (ARM) architecture. Both solutions from VMware and Parallels are paid-for software on macOS, so you will need to purchase them in order to use them.
The difference between installing Linux on a VM compared to a physical machine is minor. The notable distinction is related to the VM sizing and configuration steps, making sure the minimum system requirements of the Linux distribution are met. Thus, in the following sections we will install Ubuntu on VMware Workstation under Windows.
Please take into account that installing Linux on VMware Player under macOS is very similar, and we will not duplicate the process in this edition of the book. macOS functionality was discussed in the first edition of the book, but given the limited availability of hypervisors for the Apple silicon platform, we have decided to skip it in this edition. Regarding Linux availability on bare-metal Apple silicon Macs, you could visit Asahi Linux, a project that aims to bring a fully functional Linux distribution to Apple silicon computers. Asahi Linux is available at https://asahilinux.org/.
In the next section, we briefly illustrate the installation of Ubuntu Server LTS. If we plan to install Ubuntu in a VM, there are some preliminary steps required for provisioning the VM environment. Otherwise, we proceed directly to the Installation section.
VM provisioning using VMware Workstation
In the following steps, we will create a VM based on Ubuntu Server using VMware Workstation on Windows 11. At the time of writing, version 17 of the software is available for both free and commercial use.
The first step after initializing the hypervisor is to click on Create a New Virtual Machine. This will open a new window with the new virtual machine wizard, where you can select the ISO image for the Linux distribution you want to install.
Click Browse and then open the image from your hard drive or download destination.
Click Next and you will have to give a name to the new VM and choose a location on your disk for installation. We will leave the default destination as provided by the hypervisor and name the VM Ubuntu Server 22.04.1.
Click Next. In the following window that appears, you have to give the maximum disk size for the VM. By default, it is set to 20 GB as the recommended size for Ubuntu Server. We will leave it as is.
By clicking Next once more, a window with the VM settings is provided. By default, the hypervisor provides 2 CPU cores and 4 GB of RAM to the VM. You can click on the Customize hardware button to change the defaults, depending on your hardware availability. As a rule, we recommend having at least 16 GB of RAM on your system and an 8-core CPU to be able to create reasonable-sized VMs. When everything is set up as you want, click on the Close button on the lower right side of the window. You are now back to the main wizard window.
Click Finish to complete the setup and create and initialize the VM. In the following screenshot you can see the newly created VM, running inside VMware
Figure 1.4 – Power-up and Linux installation on a new VMFigure 1.4 – Power-up and Linux installation on a new VM
Installation process
Here’s the normal installation process for Ubuntu Server LTS, following the initial boot into setup mode:
The initial welcome screen prompts for the language of your choice. Select the one you prefer and press Enter on your keyboard.
You might be prompted to apply an installer update if available. You have the options to update the installer or continue without updating. We choose to update the installer if prompted.
If there is no update available, the next screen prompts you to select your keyboard layout. Select accordingly. In our case, it is English. Select Done and press Enter.
The next prompt asks you to choose the base for the installation from the following options: Ubuntu Server and Ubuntu Server (minimized). You also have the option to search for third-party drivers. We choose Ubuntu Server and select the third-party driver option. You can make your way around the options on the screen using either Tab or the Arrow keys. To select an option, press the Space key. Select Done and press Enter.
The next screen will show you the network connections. If the defaults work for you, hit Enter to go to the next setup screen.
You will be asked about proxy configuration. If you don’t require this, just hit Enter to go to the next screen.
You will now be asked to configure the default Ubuntu mirror for the repository archives. Edit this according to your location, or just leave the defaults provided by the installer. Press Enter.
The next screen prompts you to configure storage and partitioning. We will just use the entire 20 GB disk with the default settings, so select Done and press Enter.
A storage configuration summary is provided. If everything is according to your requirements, just hit Enter.
A warning will pop up, asking whether you are definitely happy with the settings and willing to continue with the installation. Hit Enter.
The next screen asks for your profile information, including your name, the server’s name, the username, and password. Set those up and go to the next screen.
You will be asked to choose whether to install an openSSHserver or not. Select the option to install openSSH. If you have any SSH key(s) you would like to import, you can provide them here. Once finished, go to the next screen.
You will be prompted to select and install specific snap packages for your new server installation. Depending on your requirements, you can install these now, or choose to manually install them later on. Among the provided packages are docker, microk8s, powershell, nextcloud, and livepatch. Select what you need to meet your requirements and continue to the next screen.
The installation process begins. This could take a couple of minutes. Be patient and wait for the reboot option to appear once the operating system is installed.
After you reboot, the login screen appears and you will be able to use your new Ubuntu Server VM from inside Windows 11 using VMware Workstation. We have now completed the Ubuntu Server installation.
Installing any other distribution is very similar to installing Ubuntu. When installing desktop variants, a graphical user interface will be available. In the preceding example, as we installed a server-specific operating system, the graphical user interface was missing, having just a minimal text-based interface.
We will not walk you through the installation process of any other distribution, but we will show you the Rocky Linux installation interface:
Figure 1.5 – The Rocky Linux installation GUIFigure 1.5 – The Rocky Linux installation GUI
So far, we have learned how to perform a basic installation of Linux. Along the way, we created a bootable USB flash drive for our installation media, most commonly used for Linux PC platform installations. We briefly covered VM-specific Linux environments using the VMware Workstation hypervisor for Windows 11.
In the following section, we’ll learn how to install and run a Linux distribution on the Windows platform without the use of a standalone hypervisor by using the Windows Subsystem for Linux.
VM provisioning using Hyper-V
In the following steps, we will create a VM based on Ubuntu Server, using Microsoft’s Hyper-V solution available on Windows 11 Pro.
The first step is to activate the Hyper-V hypervisor, as it is not activated by default. For this, we will need to go to Windows Features and select the Hyper-V checkbox, as shown in the following figure. After activation, a restart is required.
Figure 1.6 – Activating Hyper-V on Windows 11 ProFigure 1.6 – Activating Hyper-V on Windows 11 Pro
To create a new VM, you will have to start Hyper-V Manager. The application has a three-pane interface. In the Actions pane on the right, you should see the New option. Click on it and select the Virtual Machine… option. This will open a new window where you can configure the new VM with the following steps:
Set the name and location; we will give it the name Ubuntu and leave the default location as is. Click Next.
Set the generation of the VM. You have two options, Generation 1 and Generation 2. The second option will be suitable for UEFI-based BIOS and Network installation (PXE). We will select Generation 1 and click Next.
Specify the amount of RAM. By default, this is set to 4 GB minimum, with the option of dynamic memory selected. We will leave the default as is. Click Next.
Configure networking by selecting the appropriate option from the dropdown. You have three options: Not Connected, Default Switch, WSL; we will select Default Switch and click Next.
Configure a virtual hard drive by setting the size and location. Click Next.
In the following window, you have the option to install an operating system now or at a later time. We will select the Ubuntu Desktop ISO image from our location of choice and click Next.
The following window shows the summary of the VM’s configuration. You can change any of it by going back from here. Once done, click the Finish button and the VM will be created.
The following screenshot shows the new Ubuntu VM running inside Hyper-V:
Figure 1.7 – New Ubuntu VM using Hyper-VFigure 1.7 – New Ubuntu VM using Hyper-V
The installation process is similar to the one shown in the previous section, thus we will not reproduce it here again. In the next section, we will use another hypervisor, this time from Oracle.
VM provisioning using Oracle’s VirtualBox
Oracle’s VirtualBox is a free-to-use piece of software that is multi-platform, available on Windows, macOS and Linux. We will show you how to create a Linux VM from Windows 11. We assume that you have VirtualBox already installed. Once you start it, a user-friendly interface is available. The following steps are used to create a new VM. We will use Fedora Workstation for our example:
Click on the New icon to start the process of creating a new VM. This will open a new window where information about the VM’s name and operating system type and ISO location need to be provided. This new window is in Guided Mode by default. You have the option on the lower right side of the window to choose the Expert Mode. This will give you more control over the creation process.
Provide all the needed information. In our case, we will use Fedora, so we will give it the name Fedora. Point to the ISO file’s location and the type of the operating system will change automatically. If you are in Expert Mode, you will have some more auto-hidden sections for Unattended Install, Hardware, and Hard Disk options.
Because we are installing Fedora, the Unattended Install section is grayed out (see Figure 1.11). This option is supported by only a few operating systems (Ubuntu, RHEL, Oracle Linux, and Windows).
In the Hardware section, we will provide the amount of system memory and processors we want the new VM to have. Choose according to your hardware resources, but keep in mind that each operating system has specific system requirements. In our case, we will choose 4 GB of RAM and 2 vCPUs.
The Hard Disk section is where you choose the amount of disk space for the VM’s hard disk. Again, choose according to your resources, but keep in mind that a minimal amount is required to meet specific system requirements. In our opinion, a minimum of 20 GB of hard disk space should be provided. Choose the location of the virtual hard drive and click Finish.
The VM will be created and the window will close, bringing you back to the initial VirtualBox window. Here, you will see all the relevant information about the VM. To power it on, just click on the Start button (the one with a big green right arrow).
A new window with the VM will appear.
The following screenshot shows the VM creation window inside VirtualBox:
Figure 1.8 – VirtualBox interfaceFigure 1.8 – VirtualBox interface
As you can see, creating Linux VMs with all three major hypervisors available (from VMware, Oracle, and Microsoft) is very straightforward and relatively easy to do. No matter which solution you use, the process of installing Linux in a VM is the same.
Aside from VM provisioning, Microsoft Windows offers a relatively new way to run Linux, and this is by using the Windows Subsystem for Linux. We will show you how in the next section.
Enabling Windows Subsystem for Linux
Software developers and system administrators often face a tough decision in choosing the appropriate hardware and operating system platform for the specific requirements of their work or environment. In the past, Windows professionals frequently discovered that some standard development tools, frameworks, or server components were available on the Linux or macOS platforms while lacking native support on Windows. Windows Subsystem for Linux (WSL) attempts to close this gap.
WSL is a Windows platform feature that provides a native GNU/Linux runtime along with the Windows desktop environment available for both versions 10 and 11 of Windows. WSL enables the seamless deployment and integration of select Linux distributions on top of the Windows kernel, without the need for a dedicated hypervisor. With WSL enabled, you can easily install and run Linux as a native Windows application.
Important note
Without WSL, we could only deploy and run a Linux distribution on a Windows platform by using a standalone hypervisor, such as Hyper-V, Oracle VM VirtualBox, or VMware Workstation. WSL eliminates the need for a dedicated hypervisor. At the time of writing, WSL is a Windows kernel extension with a hypervisor embedded.
In this section, we provide the steps required to enable WSL and run an Ubuntu distribution on Windows. Since Windows 11 version 21H2 and Windows 10 versions 21H2 and 22H2, WSL is available by default from the Windows Store, so there is no need to use the command line to install and set it up. Go to the Microsoft Store and search for WSL. From the list shown, select the application shown in the following figure:
Figure 1.9 – WSL application from the Windows StoreFigure 1.9 – WSL application from the Windows Store
After installing WSL, all you need to do is to install any Linux distributions available for it. If you attempt to open the freshly installed WSL application, you will get a