df命令\du命令\磁盤分區4.1-4.4


一、df命令 
df 查看已掛載磁盤的總容量、使用容量、剩餘容量等,可以不加任何參數,默認是按k爲單位顯示的


第一列是分區的名字,第二列爲該分區總共的容量,第三列爲已經使用了多少,第四列爲還剩下多少,第五列爲已經使用百分比,如果這個數值到達90%以上應該注意,會引起系統崩潰的


df常用選項有: 
-i :查看inodes使用狀況 
-h :使用合適的單位顯示,例如 ‘G’ 
-k :以 K 爲單位顯示 
-m :以M 爲單位顯示 


二、du命令 
du命令是用來查看某個文件或目錄的大小 
命令:du 
命令格式:du [選項] 文件或目錄名 
選項: 
-h 以合理的單位顯示內存 
-s 只顯示總和(及當前目錄) 
-a 能將所有文件都顯示出來,包括子目錄,孫目錄。


例如:
-s選項
只查看當前文件
du -s /root/
56  /root/


-h選項
以合理單位顯示
du -h /root
16K /root/.ssh
0   /root/shuai/aoli
0   /root/shuai/deng
0   /root/shuai
0   /root/deng
56K /root


-a 選項
隱藏文件,子目錄子文件,孫目錄,當前目錄,全都顯示。 
du -a /root/
4   /root/.bash_logout
4   /root/.bash_profile
4   /root/.bashrc
4   /root/.cshrc
4   /root/.tcshrc
4   /root/anaconda-ks.cfg
8   /root/.bash_history
4   /root/.ssh/known_hosts
4   /root/.ssh/id_rsa
4   /root/.ssh/id_rsa.pub
4   /root/.ssh/authorized_keys
16  /root/.ssh
0   /root/shuai/aoli
0   /root/shuai/deng
0   /root/shuai/3.txt
0   /root/shuai
0   /root/deng/1.txt
0   /root/deng/shuai
0   /root/deng
4   /root/1.txt.bak
4   /root/1.txt
56  /root/

常用du -sh filename簡單直觀
du -sh /root/
258k  /root

*(重要) 三、磁盤分區 
因爲我們用的是虛擬機,所以要先給虛擬機添加一塊磁盤,按如下操作方法添加: 
1、先關閉正在運行的Linux系統 ,使用命令 init 0 
2、到vmware的Linux虛擬機界面,點 “Edit virtual machine settings”, 點一下左側靠下面的 “Add…” 按鈕 
3、在左側選中 “Hard Disk” 默認就是這一行,點右下角的 “Next”, 繼續點 “Next” 
4、“Virtual disk type” 選擇 IDE,點 “Next” 
5、繼續點 “Next”, “Disk size” 默認即可,最後點 “Finish”

fdisk -l 可查看所有硬盤 
這時就要重啓才能識別。


重啓,識別新硬盤
reboot
fdisk -l

磁盤 /dev/sda:21.5 GB, 21474836480 字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標籤類型:dos
磁盤標識符:0x0008a618

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    41943039    18668544   83  Linux

磁盤 /dev/sdb:10.7 GB, 10737418240 字節,20971520 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節

就能識別出來了。


fdisk 磁盤劃分分區 
命令:fdisk 
命令格式:fdisk 磁盤名
fdisk /dev/sdb
進去磁盤分區 


按m可以獲取幫助信息
命令(輸入 m 獲取幫助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)


n:表示建立一個新分區 
w:表示保存 
p:表示打印當前分區情況 
q:表示退出(不保存) 
d:刪除一個分區 
添加一個主分區


命令(輸入 m 獲取幫助):n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
分區號 (2-4,默認 2):
起始 扇區 (10487808-20971519,默認爲 10487808):
將使用默認值 10487808
Last 扇區, +扇區 or +size{K,M,G} (10487808-20971519,默認爲 20971519):+1G
分區 2 已設置爲 Linux 類型,大小設爲 1 GiB


添加一個擴展分區

命令(輸入 m 獲取幫助):n
    Partition type:
       p   primary (2 primary, 0 extended, 2 free)
       e   extended
    Select (default p): e
    分區號 (3,4,默認 3):
    起始 扇區 (12584960-20971519,默認爲 12584960):
    將使用默認值 12584960
    Last 扇區, +扇區 or +size{K,M,G} (12584960-20971519,默認爲 20971519):+2G
    分區 3 已設置爲 Extended 類型,大小設爲 2 GiB


添加完擴展分區後就可以添加邏輯分區了


命令(輸入 m 獲取幫助):n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
添加邏輯分區 5
起始 扇區 (12587008-16779263,默認爲 12587008):
將使用默認值 12587008
Last 扇區, +扇區 or +size{K,M,G} (12587008-16779263,默認爲 16779263):+1G
分區 5 已設置爲 Linux 類型,大小設爲 1 GiB


打印出添加的分區


命令(輸入 m 獲取幫助):p


磁盤 /dev/sdb:10.7 GB, 10737418240 字節,20971520 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標籤類型:dos
磁盤標識符:0x230515a6


   設備 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    12584959     1048576   83  Linux
/dev/sdb3        12584960    16779263     2097152    5  Extended
/dev/sdb5        12587008    14684159     1048576   83  Linux


主分區和擴展分區在(sdb1~sdb4)這裏,而邏輯分區,在sdb5到以後。


刪除分區


命令(輸入 m 獲取幫助):d
分區號 (1-3,5,默認 5):2
分區 2 已刪除


分完區後,想保存,按w退出,不想保存,按q退出。


ps: 關於主分區,擴展分區,和邏輯分區的關係。主分區加邏輯分區只能有4個,而且其中擴展分區最多隻能有一個。邏輯分區是隻能存在擴展分區裏面,並且邏輯分區區號從5開始,依次排下去。


ps:fdisk這個分區工具,只能劃分小於2TB的分區,並且,主分區只能有4個。而GPT分區格式,突破了這些限制,它沒有主分區、擴展分區、邏輯分區之分,在一塊磁盤上最多可以分128個分區出來,支持大於2T的分區,最大卷可達18EB。


擴展知識: 
 parted分區gpt格式
http://www.apelearn.com/bbs/thread-7243-1-1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章