mkfs, mkfs -t type = mkfs.typenode
ext:mke2fs
linux
建立文件系統:mke2fs [OPTION]... DEVICEcentos
-t {ext2|ext3|ext4}bash
-b {1024|2048|4096}app
-L 'LABEL'異步
-j: mke2fs -t ext3async
-i #:ide
-N #:工具
-m #: 預留磁盤空間佔據多大百分比的空間爲後期管理使用;佈局
-O FEATURE[,...]
-O ^FEATURE:關閉此特性
has_journal
系統信息查看 blkid DEVICE
文件系統屬性查看及調整工具:
e2lable e2lable DEVICE [LABEL]
tune2fs [OPTION]... DEVICE
顯示ext系列文件系統的屬性,或調整其屬性;
-l:顯示超級塊中的信息;顯示整個文件的屬性及佈局等相關信息;
-L 'LABEL':修改卷標;
-m #: 調整預留給管理員的管理空間百分比;
-j: ext2 --> ext3
-O:文件系統屬性的啓動或關閉
-o:文件系統默認掛載選項的啓用或關閉
dumpe2fs:
-h: 僅顯示超級塊信息;
文件系統檢測,在系統非正常關閉的狀況下,或者感受磁盤有損壞的狀況下使用:
fsck: Filesystem check
fsck -t type 磁盤類型必須與磁盤真實類型一致不然對數據有損
fsck.type
-a: 自動修復錯誤
-r: 交互式修復錯誤
-f: 強制檢測
[root@bogon ~]# fsck -t ext4 /dev/sdb1 fsck from util-linux 2.23.2 e2fsck 1.42.9 (28-Dec-2013) mydata: clean, 11/655360 files, 83137/2621184 blocks
e2fsck:ext系列文件系統專用的檢測修復工具;
-y: 自動回答爲「yes」
-f:force
文件系統的掛載和使用:
kernel --> rootfs(分區)
rootfs分區:
bin, sbin, etc, lib, lib64, dev, tmp, proc, sys
/sbin/init
將額外文件系統與根文件系統某現存的目錄創建起關聯關係,進而使得此目錄作爲其它文件系統訪問入口的行爲,稱之爲掛載;
解除此關聯關係的過程:卸載;
掛載點:mount point, 設備掛載至目錄;
注意:掛載點在掛載在以後,其內部原有的文件會被暫時隱藏;創建使用空目錄作爲掛載點;
掛載方法:
mount:經過讀取/etc/mtab文件來顯示當前系統全部已經掛載的設備;
mount -a:掛載/etc/fstab文件中的全部支持自動掛載的文件系統;
mount [options] [-o options] DEVICE MOUNT_POINT
[options]:命令選項
[-o options]:掛載選項
DEVICE: 要掛載的設備
(1) 設備文件:/dev/sda5
(2) 卷標:-L 'LABEL'
(3) UUID:-U 'UUID'
(4) 僞文件系統名稱
MOUNT_POINT: 掛載點
經常使用選項:
-t type:文件系統類型
-r: 以「只讀」方式掛載此文件系統
-w: 以「讀寫」方式掛載此文件系統
-n:每一個文件系統在掛載時都會自動更新/etc/mtab文件,-n用於禁止此功能;
此時,若是想查看掛載的全部文件系統:cat /proc/mounts
-a: 自動掛載全部支持自動掛載的設備;
-B:綁定目錄至另外一個目錄上;
-o 掛載選項:
async:異步模式
sync: 同步模式
atime/noatime:是否更新訪問時間戳;
diratime/nodiratime:是否更新目錄的訪問時間戳;
auto/noauto: 是否容許此設備被自動掛載;
exec/noexec:是否容許執行此文件系統上應用程序;
dev/nodev:是否支持在此設備上使用設備文件;
suid/nosuid:
remount:從新掛載
ro
rw
user/nouser: 是否容許普通掛載此設備;
acl:是否支持此設備上使用facl;
defaults:rw, suid, dev, exec, auto, nouser, and async
umount:卸載命令
# umount DEVICE
# umount MOUNT_POINT
查看正在訪問指定掛載點的進程:
# fuser -v MOUNT_POINT
終止全部正在訪問指定的掛載點的進程:
# fuser -km MOUNT_POINT
交換分區:
free命令:
查看memory和swap的使用狀態
-m: 以MB爲單位
-g: 以GB爲單位
mkswap:建立交換分區
mkswap [option] DEVICE
-L 'LABEL'
swapon:啓用交換分區
swapon [option] [DEVICE]
-a: 激活全部交換分區
-p PRIORITY: 設定其優先級;
swapoff:禁用交換分區
swapoff [option] [DEVICE]
文件系統等空間佔用信息的查看工個:
df: disk free
-h: human-readable
-i: inode數量
-P: 以Posix兼容的格式輸出
du: disk usage
-h: human-readable
-s: summary
文件系統相關掛載配置文件:/etc/fstab
每行定義一個文件系統;
要掛載的設備或僞文件系統 掛載點 文件系統類型 掛載選項 轉儲頻率 自檢次序
要掛載的設備:
設備文件、LABEL=、UUID=、僞文件系統名稱
掛載選項:
defaults
轉儲頻率:
0: 不轉儲
1: 天天轉儲
2: 每隔一天轉儲
自檢次序:
0:不自檢
1:首先自檢,一般只有/才爲1
2:
...
文件系統上的連接文件:
硬連接:
兩個路徑指向同一個inode
不能對目錄進行;
不能跨分區進行
指向同一個inode的多個不一樣路徑; 建立文件的硬連接會增長inode的引用計數;刪除硬連接僅是刪除其一個訪問路徑,只到最後一個路徑被刪除;
符號連接:
連接文件的數據指向另外一個文件路徑;
能夠對目錄進行;
能夠跨分區;
指向的是另外一個文件路徑;而非inode;
對文件建立符號連接不會增長其引用計數;刪除原文件,符號連接文件也將沒法;
ln [-s] SRC DEST
-s:symbolic link
-v:verbose
建立一個10G的文件系統,類型爲ext4,要求開機可自動掛載至/mydata目錄
[root@bogon ~]# fdisk -l Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000e5d08 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 47171583 23072768 8e Linux LVM /dev/sda3 47171584 89114623 20971520 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/mapper/centos-usr: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-var: 10.7 GB, 10737418240 bytes, 20971520 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 [root@bogon ~]# 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 0x01eef223. 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-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): Using default value 20971519 Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@bogon ~]# fdisk -l Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000e5d08 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 47171583 23072768 8e Linux LVM /dev/sda3 47171584 89114623 20971520 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x01eef223 Device Boot Start End Blocks Id System /dev/sdb1 2048 20971519 10484736 83 Linux Disk /dev/mapper/centos-usr: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-var: 10.7 GB, 10737418240 bytes, 20971520 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 [root@bogon ~]# mke2fs -t ext4 /dev/sd sda sda1 sda2 sda3 sdb sdb1 [root@bogon ~]# mke2fs -t ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621184 blocks 131059 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 80 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@bogon ~]# e2label /dev/sdb1 [root@bogon ~]# e2label /dev/sdb1 mydata [root@bogon ~]# e2label /dev/sdb1 mydata [root@bogon ~]# blkid /dev/sdb1 /dev/sdb1: LABEL="mydata" UUID="b42b248d-0281-4736-8e94-2997ac7e8e9c" TYPE="ext4" [root@bogon ~]# cp /etc/fstab /etc/fstabbak [root@bogon ~]# cd /mydata/ [root@bogon mydata]# ls [root@bogon mydata]# touch aaa [root@bogon mydata]# cd.. bash: cd..: command not found... [root@bogon mydata]# cd .. [root@bogon /]# mount /dev/sd sda sda1 sda2 sda3 sdb sdb1 [root@bogon /]# mount /dev/sdb1 /mydata/ [root@bogon /]# cd mydata/ [root@bogon mydata]# ll total 16 drwx------. 2 root root 16384 Sep 8 13:49 lost+found [root@bogon ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sun Sep 6 07:01:27 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=7568bf84-ac4a-4da4-b4b0-b656073d62b0 / btrfs subvol=root 0 0 UUID=75f891ed-9f28-4c9a-8105-c3751461ffab /boot xfs defaults 0 0 /dev/mapper/centos-usr /usr xfs defaults 0 0 /dev/mapper/centos-var /var xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=b42b248d-0281-4736-8e94-2997ac7e8e9c /mydata ext4 defaults 0 0 [root@bogon ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 44M 18G 1% / devtmpfs 487M 0 487M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 6.9M 490M 2% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup /dev/mapper/centos-usr 10G 5.9G 4.2G 59% /usr /dev/sdb1 9.8G 37M 9.2G 1% /mydata /dev/mapper/centos-var 10G 642M 9.4G 7% /var /dev/sda1 497M 127M 370M 26% /boot [root@bogon ~]# cd /mydata/ [root@bogon mydata]# ls lost+found [root@bogon mydata]# cd [root@bogon ~]# umount /mydata/ [root@bogon ~]# cd /mydata/ [root@bogon mydata]# ls aaa [root@bogon mydata]#