Linux文件(jian)系統(tong)管(guan)理(li)
時間:2018-09-27 來源:未知
一、使(shi)用 ext4、xfs 格(ge)式(shi)化磁盤并掛載,實現重啟后(hou)可自動掛載
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 是(shi)格式化后的磁盤格式,/dev/sda3 是(shi)將要(yao)格式化的磁盤
# mount /dev/sda3 /mnt/sda 將 /dev/sda3 掛載到 /mnt/sda 下
2、xfs 格式化磁(ci)盤:
格式化 xfs 需要(yao)用到 xfs工具集,先下載xfsprogs
# yum install xfsprogs
# mkfs.xfs -f /dev/sda3 -f 參數的作用是如果當前要格式化的磁盤已經(jing)是其他格式的文件(jian)系(xi)統(tong),則覆(fu)蓋
3、實現重啟自(zi)動掛載
# vim /etc/fstab 磁盤掛載(zai)文(wen)件,要掛載(zai)的文(wen)件系統格式不同,掛載(zai)的參數也不同
a) ext3 / ext4 格式磁盤的掛載(zai),在文件中加入(ru)下面參數:
/dev/sda? mount_to_file ext3 default 0 0
上面的(de) ? 指的(de)是你(ni)要(yao)掛(gua)載的(de)磁盤的(de)盤符,mount_to_file 是你(ni)要(yao)把(ba)磁盤掛(gua)載到哪,ext3 是你(ni)要(yao)掛(gua)載的(de)磁盤的(de)格式,default 指明按照(zhao)默(mo)認參數掛(gua)載, 0 0 表(biao)示(shi)開機不檢查
b) fat32 格(ge)式磁盤的掛(gua)載,在(zai)文件中加入下(xia)面參數(shu):
/dev/sda? mount_to_file vfat user,rw,utf8,umask=000 0 1
這(zhe)里的?和(he) mount_to_file 跟上面的一樣,vfat 為文件格式,user,rw指(zhi)的是(shi)給用戶讀(du)寫的權限,utf8加(jia)上后會將Windows下的中文轉換(huan)為 utf8格式,umask=000 指(zhi)的是(shi)給
所有用戶(hu)賦予了讀寫(xie)的權(quan)限, 0 0 表示開機(ji)檢查(cha)
二、進行磁盤分區
# fdisk 參數(shu)說明
a :指定啟(qi)動分區
d :刪除(chu)一個存(cun)在的分區
l :顯(xian)示分區 ID 號的(de)列表(biao)
m:查看 fdisk 命令幫助
n :創建一個新的分區
p :顯示分區列表
t :修(xiu)改分區 ID 號
w:對分區(qu)表的修改保(bao)存,保(bao)存后(hou)會立即生效
# 對(dui) /dev/sda3 磁盤進(jin)行分區
[root@Demon /]# fdisk /dev/sda (這里(li)沒有(you)盤符)
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 (刪(shan)除磁盤)
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 (創建新(xin)的分(fen)區)
Command action
e extended
p primary partition (1-4) (主分區)
e (擴展分區(qu))
Partition number (1-4): 4
First cylinder (574-13054, default 574): (選(xuan)擇分區起始柱面)
Using default value 574
Last cylinder, +cylinders or +size{K,M,G} (574-13054, default 13054): (選擇分(fen)區(qu)結束柱面)
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 (創(chuang)建邏輯分(fen)區(qu))
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
接下(xia)來(lai)格式(shi)化分區(qu)
# mkfs -t ext4 /dev/sda4
三、查看磁盤(pan)容量(liang)
# df -lh
df 命令參數:
-a 全(quan)部(bu)文件系統列表
-h 方便閱讀(du)顯示(shi),一般用來查找(zhao)大(da)文件(jian)
-H 相當(dang)于(yu) -h ,不過1k = 1000 而不是 1024
-i 顯示 inode 信息(xi),inode包含的(de)信息(xi):文(wen)件的(de)字節數(shu),擁有(you)者(zhe)id,組id,權限,改動(dong)時間,鏈接數(shu),數(shu)據block的(de)位置(zhi),
不表示文件大小(xiao)
-k 區塊為1024字節(jie)
-l 只顯示本地文件系統
-m 區塊為1048576 字節
--no-sync 忽略(lve)sync 命令
-P 輸出格式為 POSIX
--sync 在(zai)取得磁盤信息前,先(xian)執行 sync 命令
-T 文件系(xi)統類(lei)型

