hoatranlab.io.vn Zalo: 0917516878 Hotline: 0917516878 [email protected]
HoaTranLab Logo HoaTranLab
Linux Bible 11th Edition • Chapter 9

Installing Linux

Cài đặt Linux từ ISO: tải Fedora/RHEL, quy trình Anaconda, phân vùng ổ đĩa, chọn filesystem, cài tự động với Kickstart.

Mục Tiêu Chương 9

Tải ISO Linux

Tải Fedora Workstation/Server và RHEL từ nguồn chính thức. Verify checksum SHA256 để xác minh tính toàn vẹn.

Tạo Boot Media

Tạo USB bootable với dd hoặc Rufus. Boot từ USB, DVD, hoặc PXE network boot cho môi trường doanh nghiệp.

Anaconda Installer

Điều hướng GUI installer Anaconda: chọn ngôn ngữ, timezone, keyboard, network, và software selection.

Phân vùng ổ đĩa

Hiểu partition layout: /boot, /boot/efi, swap, / (root), /home. Dùng LVM, standard partition, hoặc Btrfs subvolumes.

Filesystem Types

So sánh ext4 (stable), xfs (scalable, default RHEL), btrfs (snapshots, compression). Biết khi nào dùng loại nào.

Kickstart Automation

Cài đặt tự động không cần tương tác với file Kickstart. Dùng cho deployment hàng loạt trong doanh nghiệp.

Lý Thuyết: Cài đặt Linux

1. Tải và Verify ISO

Terminal – Download và Verify ISO

# Tải Fedora Workstation (ví dụ):

$ wget https://download.fedoraproject.org/pub/fedora/linux/releases/41/Workstation/x86_64/iso/Fedora-Workstation-Live-41.iso

# Verify SHA256 checksum:

$ sha256sum Fedora-Workstation-Live-41.iso

abc123... Fedora-Workstation-Live-41.iso

# So sánh với checksum từ trang web chính thức

# Tạo USB bootable với dd:

$ sudo dd if=Fedora-Workstation-Live-41.iso of=/dev/sdb bs=4M status=progress oflag=sync

# CẢNH BÁO: Thay /dev/sdb bằng đúng device USB của bạn!

2. Anaconda Installer – Các bước cài đặt

Anaconda là GUI installer của Fedora/RHEL. Sau khi boot từ USB, bạn sẽ thấy GRUB menu → chọn "Install Fedora" → giao diện Anaconda.

Các màn hình cấu hình trong Anaconda:

1

Language Selection

Chọn ngôn ngữ hiển thị và ngôn ngữ hệ thống (English US được khuyến nghị cho server)

2

Date & Time

Chọn timezone (Asia/Ho_Chi_Minh), bật NTP để đồng bộ thời gian tự động

3

Software Selection

Server với GUI, Minimal Install, Workstation, Custom. Minimal cho VM/container host

4

Installation Destination

Chọn ổ đĩa và cấu hình phân vùng (tự động hoặc thủ công)

5

Network & Hostname

Đặt hostname, cấu hình network interface (DHCP hoặc static IP)

6

Root Password & User

Set root password (hoặc lock root), tạo user đầu tiên với quyền admin (wheel)

3. Phân vùng ổ đĩa – Partition Layout

Cấu hình phân vùng tốt đảm bảo hiệu suất, bảo mật và dễ quản lý. Khuyến nghị cho server production:

Mount PointKích thước đề xuấtFilesystemMục đích
/boot/efi600 MBFAT32 (vfat)UEFI bootloader files
/boot1 GBext4 hoặc xfsKernel và initrd images
swap= RAM (max 8GB)swapVirtual memory, hibernation
/20-50 GBxfs (RHEL default)Root filesystem, OS files
/homePhần còn lạixfs hoặc ext4User data, dễ backup riêng

4. Filesystem Types: ext4, xfs, btrfs

ext4

  • ✓ Rất ổn định, battle-tested
  • ✓ Hỗ trợ rộng rãi
  • ✓ Max file: 16 TB
  • ✓ Max volume: 1 EB
  • ✗ Không có checksums
  • ✗ Ít tính năng nâng cao
  • Dùng cho: /boot, desktop

xfs

  • ✓ Tốt với file lớn
  • ✓ Hiệu suất cao (parallel I/O)
  • ✓ Max file: 8 EB
  • ✓ Default RHEL/Fedora
  • ✗ Không shrink volume
  • ✗ Không có snapshots tích hợp
  • Dùng cho: / và /home server

btrfs

  • ✓ Snapshots tích hợp
  • ✓ Compression (zstd)
  • ✓ Checksums tự động
  • ✓ Subvolumes linh hoạt
  • ✗ Phức tạp hơn
  • ✗ RAID5/6 không ổn định
  • Dùng cho: Fedora desktop (default)

Kickstart – Cài đặt Tự động

5. Kickstart File Format

Kickstart cho phép cài đặt Linux hoàn toàn tự động, không cần tương tác. File Kickstart được trỏ đến qua boot parameter inst.ks=.

Kickstart file – ks.cfg

# Installation method

text

url --url="https://mirror.fedoraproject.org/fedora/linux/releases/41/Everything/x86_64/os/"

# System settings

lang en_US.UTF-8

keyboard us

timezone Asia/Ho_Chi_Minh --utc

# Network

network --bootproto=dhcp --device=eth0 --onboot=yes --hostname=myserver

# Security

rootpw --iscrypted $6$rounds=500000$hashed_password_here

selinux --enforcing

firewall --enabled --ssh

# Disk partitioning

zerombr

clearpart --all --initlabel

part /boot --fstype=xfs --size=1024

part /boot/efi --fstype=efi --size=600

part swap --size=4096

part / --fstype=xfs --size=20480 --grow

# Software packages

%packages

@^minimal-environment

openssh-server

vim-enhanced

%end

# Post-install scripts

%post

useradd -m -G wheel admin

echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/admin

systemctl enable sshd

%end

reboot

6. Post-installation Steps

Terminal – Post-install

# 1. Update hệ thống ngay sau cài đặt:

$ sudo dnf update -y

# 2. Kiểm tra SELinux status:

$ sestatus

SELinux status: enabled

SELinuxfs mount: /sys/fs/selinux

Current mode: enforcing

# 3. Cấu hình firewall:

$ sudo systemctl status firewalld

$ sudo firewall-cmd --list-all

# 4. Kiểm tra networking:

$ ip addr show

$ ip route

# 5. Check disk usage:

$ df -h

$ lsblk

Lab Thực Hành – Chapter 9

1

Tải và Verify ISO Fedora

Terminal

$ curl -LO https://download.fedoraproject.org/pub/fedora/linux/releases/41/Server/x86_64/iso/Fedora-Server-dvd-x86_64-41-1.6.iso

$ sha256sum Fedora-Server-dvd-x86_64-41-1.6.iso

abc123def456... Fedora-Server-dvd-x86_64-41-1.6.iso

# So sánh với giá trị trên trang download chính thức

$ file Fedora-Server-dvd-x86_64-41-1.6.iso

Fedora-Server-dvd-x86_64-41-1.6.iso: ISO 9660 CD-ROM filesystem

2

Tạo USB Bootable

Terminal

# Xác định device USB:

$ lsblk

sdb 8:16 1 14.9G 0 disk # USB drive

# Tạo USB bootable (CẢNH BÁO: xóa hết dữ liệu USB):

$ sudo dd if=Fedora-Server-dvd-x86_64-41-1.6.iso \

of=/dev/sdb bs=4M status=progress oflag=sync

1073741824 bytes (1.1 GB) copied, 45.3 s, 23.7 MB/s

$ sync

# Đảm bảo dữ liệu đã được flush sang USB

3

Kiểm tra Partition và Filesystem (Post-install)

Terminal

$ lsblk -f

NAME FSTYPE LABEL UUID MOUNTPOINTS

sda

├─sda1 vfat F2A4-... /boot/efi

├─sda2 xfs abc1-... /boot

└─sda3 LVM2_member

├─rl-root xfs /

├─rl-swap swap [SWAP]

└─rl-home xfs /home

$ cat /etc/fstab

UUID=abc1-... /boot xfs defaults 0 0

UUID=def2-... / xfs defaults 0 0

4

Tạo Kickstart file đơn giản

Terminal

# Sau khi cài bằng Anaconda, file ks.cfg được lưu tại:

$ ls /root/anaconda-ks.cfg

/root/anaconda-ks.cfg

$ cat /root/anaconda-ks.cfg

# Đây là file Kickstart được tạo tự động từ lần cài trước

# Validate kickstart file:

$ sudo dnf install pykickstart -y

$ ksvalidator /root/anaconda-ks.cfg

No errors found in kickstart file.

5

Post-install Configuration Checklist

Terminal

$ sudo dnf update -y && sudo dnf autoremove -y

$ sudo hostnamectl set-hostname myserver.example.com

$ timedatectl set-timezone Asia/Ho_Chi_Minh

$ timedatectl set-ntp true

$ sudo systemctl enable --now sshd firewalld

$ sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload

$ cat /etc/os-release

NAME="Fedora Linux" VERSION="41 (Server Edition)"

6

Cài Linux trong VirtualBox/VMware

Quy trình tạo VM để thực hành cài đặt Linux:

  1. 1Tạo VM mới: New → Linux → Fedora (64-bit), RAM ≥ 2GB, Disk ≥ 20GB
  2. 2Settings → Storage → Mount ISO file vào CD/DVD drive
  3. 3Start VM → Boot từ ISO → GRUB menu → "Install Fedora"
  4. 4Anaconda: chọn Language → configure Timezone → Software → Disk
  5. 5Disk Configuration: dùng "Automatic" hoặc "Custom" để tạo partitions
  6. 6Begin Installation → Set root password → Create user → Wait → Reboot

Câu Hỏi Ôn Tập – Chapter 9

1

Anaconda là gì và nó được dùng ở đâu?

Anaconda là GUI/TUI installer mặc định của Fedora và Red Hat Enterprise Linux. Nó cung cấp giao diện đồ họa để cấu hình ngôn ngữ, timezone, disk partitioning, network, software selection và user accounts. Cũng hỗ trợ chế độ text cho môi trường không có GUI, và chế độ tự động hoàn toàn qua Kickstart files.
2

Tại sao cần verify SHA256 checksum của file ISO?

Để xác minh tính toàn vẹn: file không bị hỏng trong quá trình tải, và không bị tampered bởi kẻ tấn công (man-in-the-middle attack). Nếu cài đặt từ ISO bị hỏng, hệ thống có thể lỗi hoặc có backdoor. SHA256 cực kỳ khó giả mạo (collision resistant). Lệnh: sha256sum file.iso và so sánh với giá trị trên trang official.
3

Sự khác nhau giữa ext4 và xfs? RHEL dùng mặc định loại nào và tại sao?

RHEL/Fedora dùng XFS mặc định vì scalability tốt hơn cho workload lớn. XFS tốt với file lớn, parallel I/O, max size 8 EB. ext4 ổn định hơn, hỗ trợ rộng, nhưng max 16 TB file. XFS không thể shrink volume (ext4 có thể). Cả hai đều có journaling. ext4 tốt cho /boot, XFS tốt cho data partitions lớn.
4

Kickstart file là gì? Dùng khi nào?

Kickstart là file văn bản định nghĩa tất cả lựa chọn cài đặt để Anaconda cài tự động không cần tương tác. Dùng khi: cài nhiều máy giống nhau (data center), CI/CD infrastructure provisioning, chuẩn hóa cấu hình. Boot với: inst.ks=http://server/ks.cfg hoặc từ USB: inst.ks=hd:sdb1:/ks.cfg.
5

Tại sao cần phân vùng /boot riêng không đặt trong LVM?

/boot cần truy cập được bởi bootloader (GRUB) trước khi kernel boot, nhưng GRUB không thể đọc LVM, LUKS encryption, hoặc các storage phức tạp khác. /boot phải là partition thường, filesystem đơn giản (ext4 hoặc xfs). /boot/efi cũng phải là FAT32 trên UEFI systems để UEFI firmware đọc được.
6

Lệnh dd dùng để tạo USB bootable như thế nào? Nguy hiểm nào cần tránh?

sudo dd if=linux.iso of=/dev/sdX bs=4M status=progress oflag=sync. Nguy hiểm chính: chỉ định sai device sẽ xóa dữ liệu ổ đĩa hệ thống! Kiểm tra kỹ /dev/sdX bằng lsblk trước. Không có dấu số (sdb không phải sdb1). oflag=sync đảm bảo dữ liệu flush xuống USB trước khi kết thúc. Ngoài dd có thể dùng Balena Etcher (GUI, an toàn hơn).
7

Sau khi cài Linux xong, 3 bước quan trọng nhất cần làm ngay là gì?

1. sudo dnf update -y: cập nhật toàn bộ packages để vá security vulnerabilities. 2. Cấu hình firewall: sudo firewall-cmd --list-all, chỉ mở ports cần thiết. 3. Tạo user admin với sudo và disable/limit root login trực tiếp. Ngoài ra: set timezone, hostname, enable SSH key authentication, tắt password auth nếu có thể.
8

btrfs có ưu điểm gì so với ext4 và xfs mà Fedora chọn làm mặc định?

btrfs có snapshots tích hợp (dùng cho rollback sau update), transparent compression (tiết kiệm dung lượng với zstd), checksums cho cả data và metadata (phát hiện corruption), subvolumes (linh hoạt như LVM nhưng không cần setup riêng), và copy-on-write. Fedora dùng btrfs với subvolumes @ và @home cho desktop workstations. Không phù hợp cho RAID5/6 production.