當(dāng)前位置:首頁(yè) > 嵌入式培訓(xùn) > 嵌入式學(xué)習(xí) > 講師博文 > Linux文件系統(tǒng)管理
一、使用 ext4、xfs 格式化磁盤并掛載,實(shí)現(xiàn)重啟后可自動(dòng)掛載
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 參數(shù)的作用是如果當(dāng)前要格式化的磁盤已經(jīng)是其他格式的文件系統(tǒng),則覆蓋
3、實(shí)現(xiàn)重啟自動(dòng)掛載
# vim /etc/fstab 磁盤掛載文件,要掛載的文件系統(tǒng)格式不同,掛載的參數(shù)也不同
a) ext3 / ext4 格式磁盤的掛載,在文件中加入下面參數(shù):
/dev/sda? mount_to_file ext3 default 0 0
上面的 ? 指的是你要掛載的磁盤的盤符,mount_to_file 是你要把磁盤掛載到哪,ext3 是你要掛載的磁盤的格式,default 指明按照默認(rèn)參數(shù)掛載, 0 0 表示開機(jī)不檢查
b) fat32 格式磁盤的掛載,在文件中加入下面參數(shù):
/dev/sda? mount_to_file vfat user,rw,utf8,umask=000 0 1
這里的?和 mount_to_file 跟上面的一樣,vfat 為文件格式,user,rw指的是給用戶讀寫的權(quán)限,utf8加上后會(huì)將Windows下的中文轉(zhuǎn)換為 utf8格式,umask=000 指的是給
所有用戶賦予了讀寫的權(quán)限, 0 0 表示開機(jī)檢查
二、進(jìn)行磁盤分區(qū)
# fdisk 參數(shù)說(shuō)明
a :指定啟動(dòng)分區(qū)
d :刪除一個(gè)存在的分區(qū)
l :顯示分區(qū) ID 號(hào)的列表
m:查看 fdisk 命令幫助
n :創(chuàng)建一個(gè)新的分區(qū)
p :顯示分區(qū)列表
t :修改分區(qū) ID 號(hào)
w:對(duì)分區(qū)表的修改保存,保存后會(huì)立即生效
# 對(duì) /dev/sda3 磁盤進(jìn)行分區(qū)
[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 (創(chuàng)建新的分區(qū))
Command action
e extended
p primary partition (1-4) (主分區(qū))
e (擴(kuò)展分區(qū))
Partition number (1-4): 4
First cylinder (574-13054, default 574): (選擇分區(qū)起始柱面)
Using default value 574
Last cylinder, +cylinders or +size{K,M,G} (574-13054, default 13054): (選擇分區(qū)結(jié)束柱面)
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 (創(chuàng)建邏輯分區(qū))
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
接下來(lái)格式化分區(qū)
# mkfs -t ext4 /dev/sda4
三、查看磁盤容量
# df -lh
df 命令參數(shù):
-a 全部文件系統(tǒng)列表
-h 方便閱讀顯示,一般用來(lái)查找大文件
-H 相當(dāng)于 -h ,不過(guò)1k = 1000 而不是 1024
-i 顯示 inode 信息,inode包含的信息:文件的字節(jié)數(shù),擁有者id,組id,權(quán)限,改動(dòng)時(shí)間,鏈接數(shù),數(shù)據(jù)block的位置,
不表示文件大小
-k 區(qū)塊為1024字節(jié)
-l 只顯示本地文件系統(tǒng)
-m 區(qū)塊為1048576 字節(jié)
--no-sync 忽略sync 命令
-P 輸出格式為 POSIX
--sync 在取得磁盤信息前,先執(zhí)行 sync 命令
-T 文件系統(tǒng)類型