一、使用 ext4、xfs 格式化磁盤并掛載,實現重啟后可自動掛載
1、ext4 格式化磁盤:
# fdisk -l 查看磁盤信息
[root@Demon /]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d62df
Device Boot Start End Blocks Id System
/dev/sda1 * 1 52 409600 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 52 574 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 574 13055 100252672 83 Linux
# mkfs -t ext4 /dev/sda3 -t 是格式化后的磁盤格式,/dev/sda3 是將要格式化的磁盤
# mount /dev/sda3 /mnt/sda 將 /dev/sda3 掛載到 /mnt/sda 下
2、xfs 格式化磁盤:
格式化 xfs 需要用到 xfs工具集,先下載xfsprogs
# yum install xfsprogs
# mkfs.xfs -f /dev/sda3 -f 參數的作用是如果當前要格式化的磁盤已經是其他格式的文件系統,則覆蓋
3、實現重啟自動掛載
# vim /etc/fstab 磁盤掛載文件,要掛載的文件系統格式不同,掛載的參數也不同
a) ext3 / ext4 格式磁盤的掛載,在文件中加入下面參數:
/dev/sda? mount_to_file ext3 default 0 0
上面的 ? 指的是你要掛載的磁盤的盤符,mount_to_file 是你要把磁盤掛載到哪,ext3 是你要掛載的磁盤的格式,default 指明按照默認參數掛載, 0 0 表示開機不檢查
b) fat32 格式磁盤的掛載,在文件中加入下面參數:
/dev/sda? mount_to_file vfat user,rw,utf8,umask=000 0 1
這里的?和 mount_to_file 跟上面的一樣,vfat 為文件格式,user,rw指的是給用戶讀寫的權限,utf8加上后會將Windows下的中文轉換為 utf8格式,umask=000 指的是給
所有用戶賦予了讀寫的權限, 0 0 表示開機檢查
二、進行磁盤分區
# fdisk 參數說明
a :指定啟動分區
d :刪除一個存在的分區
l :顯示分區 ID 號的列表
m:查看 fdisk 命令幫助
n :創建一個新的分區
p :顯示分區列表
t :修改分區 ID 號
w:對分區表的修改保存,保存后會立即生效
# 對 /dev/sda3 磁盤進行分區
[root@Demon /]# fdisk /dev/sda (這里沒有盤符)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p (查看磁盤信息)
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d62df
Device Boot Start End Blocks Id System
/dev/sda1 * 1 52 409600 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 52 574 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 574 13055 100252672 83 Linux
Command (m for help): d (刪除磁盤)
Partition number (1-4): 3 (刪除 sda3)
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d62df
Device Boot Start End Blocks Id System
/dev/sda1 * 1 52 409600 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 52 574 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
Command (m for help): n (創建新的分區)
Command action
e extended
p primary partition (1-4) (主分區)
e (擴展分區)
Partition number (1-4): 4
First cylinder (574-13054, default 574): (選擇分區起始柱面)
Using default value 574
Last cylinder, +cylinders or +size{K,M,G} (574-13054, default 13054): (選擇分區結束柱面)
Using default value 13054
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d62df
Device Boot Start End Blocks Id System
/dev/sda1 * 1 52 409600 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 52 574 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda4 574 13054 100251327 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l (創建邏輯分區)
First cylinder (574-13054, default 574):
Using default value 574
Last cylinder, +cylinders or +size{K,M,G} (574-13054, default 13054):
Using default value 13054
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d62df
Device Boot Start End Blocks Id System
/dev/sda1 * 1 52 409600 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 52 574 4194304 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda4 574 13054 100251327 5 Extended
/dev/sda5 574 13054 100251295+ 83 Linux
接下來格式化分區
# mkfs -t ext4 /dev/sda4
三、查看磁盤容量
# df -lh
df 命令參數:
-a 全部文件系統列表
-h 方便閱讀顯示,一般用來查找大文件
-H 相當于 -h ,不過1k = 1000 而不是 1024
-i 顯示 inode 信息,inode包含的信息:文件的字節數,擁有者id,組id,權限,改動時間,鏈接數,數據block的位置,
不表示文件大小
-k 區塊為1024字節
-l 只顯示本地文件系統
-m 區塊為1048576 字節
--no-sync 忽略sync 命令
-P 輸出格式為 POSIX
--sync 在取得磁盤信息前,先執行 sync 命令
-T 文件系統類型