Quản lý phân vùng với fdisk trên Linux

fdisk là công cụ phổ biến dùng để quản lý phân vùng ổ cứng trên các hệ điều hành Linux. Bài viết này hướng dẫn chi tiết cách phân vùng, định dạng và cấu hình mount tự động sau khi khởi động.

Các lệnh phổ biến trong fdisk

Tham số Mô tả
m Xem tất cả các tùy chọn
n Tạo phân vùng mới
d Xóa phân vùng
l Danh sách các kiểu phân vùng
t Thay đổi kiểu phân vùng
p Xem bảng phân vùng
w Lưu và thoát
q Thoát mà không lưu

Xem thông tin ổ cứng

[root@ken ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb

Tạo phân vùng mới trên /dev/sdb

[root@ken ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x52997d99.

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

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x52997d99

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Định dạng phân vùng mới

[root@ken ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done 

Mount phân vùng và kiểm tra

[root@ken ~]# mkdir /part
[root@ken ~]# mount /dev/sdb1 /part
[root@ken ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  1.2G   16G   7% /
devtmpfs                 476M     0  476M   0% /dev
tmpfs                    488M     0  488M   0% /dev/shm
tmpfs                    488M  7.7M  480M   2% /run
tmpfs                    488M     0  488M   0% /sys/fs/cgroup
/dev/sda1               1014M  130M  885M  13% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb1                 93M  1.6M   85M   2% /part

Cấu hình mount tự động khi khởi động

[root@ken ~]# echo "/dev/sdb1 /part ext4 defaults 0 0" >> /etc/fstab

Cấu trúc dòng trong /etc/fstab

Thiết bị Điểm mount Hệ thống file Tùy chọn Sao lưu Kiểm tra
/dev/sdb1 /part ext4 defaults 0 0

Thẻ: fdisk disk partitioning Linux system administration storage management

Đăng vào ngày 12 tháng 9 lúc 02:29