Linux磁盤分區、掛載
1. 分區方式
- mbr分區
- 最多支持四個主分區
- 系統只能安裝在主分區
- 擴展分區要佔一個主分區
- MBR最大隻支持2TB,但擁有最好的兼容性
- gpt分區
- 支持無限多個主分區(但操做系統可能限制,好比windows下最多128個分區)
- 最大支持18EB的大容量(1EB=1024PB,PB=1024TB)
- windows7 64位之後支持gpt
2. Linux分區
2.1 分區原理
- Linux來講不管有幾個分區,分給哪個目錄使用,它歸根結底就只有一個根目錄,一個獨立且惟一的文件結構,Linux中每一個分區都是用來組成整個文件系統的一部分。
- Linux採用了一種叫作「載入」的處理方法,它的整個文件系統中包含了一整套的文件和目錄,且將一個分區和一個目錄聯繫起來。這時要載入的一個分區將使它的存儲空間在一個目錄下得到。
![](http://static.javashuo.com/static/loading.gif)
2.2 硬盤說明
- Linux硬盤分IDE硬盤和SCSI硬盤,目前基本上是SCSI硬盤
- lsblk [-f]:查看當前系統的分區和掛載狀況。(list block)
3. 掛載硬盤
需求是給咱們的Linux系統增長一個新的硬盤,而且掛載到/home/newdisklinux
- 添加硬盤
- 分區:fdsk /dev/sdb
- 格式化:mkfs -t ext4 /dev/sdb1
- 掛載:新建目錄:mkdir /home/newdisk;掛載:mount /dev/sdb1 /home/newdisk
- 設置能夠自動掛載(永久掛載):重啓系統後,仍然能夠掛載。vim etc/fstab 增長掛載信息。mount -a:生效
3.1 具體步驟
3.1.1 增長硬盤
![](http://static.javashuo.com/static/loading.gif)
3.1.2 硬盤分區
![](http://static.javashuo.com/static/loading.gif)
3.1.3 格式化磁盤
![](http://static.javashuo.com/static/loading.gif)
3.1.4 掛載硬盤
![](http://static.javashuo.com/static/loading.gif)
3.1.5 永久掛載
![](http://static.javashuo.com/static/loading.gif)
3.2 取消掛載
4. 磁盤情況查詢
實例vim
![](http://static.javashuo.com/static/loading.gif)
- 查詢指定目錄的磁盤佔用狀況:du -h /目錄,默認爲當前目錄
- -s:指定目錄佔用大小彙總
- -h:帶計量單位
- -a:含文件
- –max-depth=1:子目錄深度
- -c:列出明細的同時,增長彙總值
實例windows
![](http://static.javashuo.com/static/loading.gif)
- 磁盤狀況-工做實用指令
- 統計/home文件夾下文件的個數:ls -l /home | grep "^-" | wc -l
- 統計/home文件夾下目錄的個數:ls -l /home | grep "^d" | wc -l
- 統計/home文件夾下文件的個數,包括子文件夾裏的:ls -lR /home | grep "^-" | wc -l
- 統計文件夾下目錄的個數,包括子文件夾裏的:ls -lR /home | grep "^d" | wc -l
- 以樹狀顯示目錄結構:首先安裝tree指令:yum install tree,tree
實例操作系統
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)