Quản Lý Đĩa Hiệu Quả Trên Hệ Thống Linux

Quy Trình Quản Lý Đĩa Cơ Bản

Quy trình chuẩn để quản lý thiết bị lưu trữ trên Linux bao gồm:

  1. Phân vùng đĩa
  2. Định dạng hệ thống tập tin (ví dụ: XFS, ext4)
  3. Mount thư mục đích
  4. Thực hiện thao tác đọc/ghi

Các Lệnh Cơ Bản

Xem danh sách thiết bị

[14:22:15 root@rhel8 ~]# lsblk -f
NAME        FSTYPE      LABEL UUID                                   MOUNTPOINT
sdx                                                                
├─sdx1      xfs               5a8b3c4d-7e9f-4a1b-8c2d-3e4f5a6b7c8d   /boot
└─sdx2      LVM2_member       9g0h1i2j-3k4l-5m6n-7o8p-9q0r1s2t3u4v 
  ├─volgroup-root xfs               6v7w8x9y-0z1a-2b3c-4d5e-6f7g8h9i0j1k   /
  ├─volgroup-swap swap              1l2m3n4o-5p6q-7r8s-9t0u-1v2w3x4y5z6a   [SWAP]
  └─volgroup-storage xfs              7b8c9d0e-1f2g-3h4i-5j6k-7l8m9n0o1p2q   /storage

Xem thông tin chi tiết phân vùng

[14:25:03 root@rhel8 ~]# fdisk -l /dev/sdx
Disk /dev/sdx: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

Device     Boot      Start        End    Sectors  Size Id Type
/dev/sdx1  *          2048      2097151   2095104  1024M 83 Linux
/dev/sdx2          2097152   209715199  207618048  99.0G 8e Linux LVM

Xem sử dụng không gian lưu trữ

[14:26:11 root@rhel8 ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/volgroup-root 98G  6.5G   92G   7% /
/dev/sdx1              1014M  297M  717M  30% /boot
/dev/mapper/volgroup-storage 50G  248M   50G   1% /storage

Phân Vùng Đĩa

MBR vs GPT

Tiêu chíMBRGPT
Độ lớn tối đa2 TB9.4 ZB
Số phân vùng tối đa4 (chủ + mở rộng)128
Tính tương thíchTốt với hệ thống cũTương thích rộng

Thực hành phân vùng với MBR

[14:30:12 root@rhel8 ~]# fdisk /dev/sdx
Welcome to fdisk (util-linux 2.34).

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +512M
Partition 1 of type Linux and of size 512 MiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
Partition number (2-4, default 2): 
First sector (1048576-209715199, default 1048576): 
Using default value 1048576
Last sector, +sectors or +size{K,M,G} (1048576-209715199, default 209715199): 
Using default value 209715199
Partition 2 of type Extended and of size 98.0 GiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (1049600-209715199, default 1049600): 
Using default value 1049600
Last sector, +sectors or +size{K,M,G} (1049600-209715199, default 209715199): +15G
Partition 5 of type Linux and of size 15 GiB is set

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Định Dạng Hệ Thống Tập Tin

Chọn loại hệ thống tập tin phù hợp:

  • XFS: Tối ưu cho dung lượng lớn, dùng trên RHEL 8+
  • ext4: Hỗ trợ rộng rãi trên Ubuntu/Debian
  • Btrfs: Tích hợp snapshot và kiểm soát dữ liệu
# Định dạng XFS
mkfs.xfs /dev/sdx5

# Định dạng ext4
mkfs.ext4 /dev/sdx6

Mount Vĩnh Cửu

Thực hiện chỉnh sửa /etc/fstab với định dạng:

UUID=7b8c9d0e-1f2g-3h4i-5j6k-7l8m9n0o1p2q /storage xfs defaults 0 2

Truy cập UUID bằng lệnh blkid /dev/sdx5

Xử Lý File Đang Sử Dụng

Trước khi unmount, kiểm tra tiến trình đang sử dụng:

lsof /storage
fuser -km /storage  # Xóa tất cả tiến trình đang sử dụng

Thẻ: xfs ext4 LVM GPT fstab

Đăng vào ngày 7 tháng 7 lúc 07:49