linux CentOS7 磁盘分区fdisk 、df 、du、parted 命令实例
生活随笔
收集整理的這篇文章主要介紹了
linux CentOS7 磁盘分区fdisk 、df 、du、parted 命令实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、 df命令
分區查看工具:
1. df
[fxq@vm_46_188_centos?~]$?df Filesystem?????1K-blocks????Used?Available?Use%?Mounted?on /dev/vda1???????20510332?4844740??14617076??25%?/ devtmpfs??????????499348???????0????499348???0%?/dev tmpfs?????????????508452???????0????508452???0%?/dev/shm tmpfs?????????????508452???12660????495792???3%?/run tmpfs?????????????508452???????0????508452???0%?/sys/fs/cgroup tmpfs?????????????101692???????0????101692???0%?/run/user/0 [fxq@vm_46_188_centos?~]$2. df -h
[fxq@vm_46_188_centos?~]$?df?-h Filesystem??????Size??Used?Avail?Use%?Mounted?on /dev/vda1????????20G??4.7G???14G??25%?/ devtmpfs????????488M?????0??488M???0%?/dev tmpfs???????????497M?????0??497M???0%?/dev/shm tmpfs???????????497M???13M??485M???3%?/run tmpfs???????????497M?????0??497M???0%?/sys/fs/cgroup tmpfs???????????100M?????0??100M???0%?/run/user/0 [fxq@vm_46_188_centos?~]$3.df -i
[fxq@vm_46_188_centos?~]$?df?-i Filesystem??????Inodes??IUsed???IFree?IUse%?Mounted?on /dev/vda1??????1310720?121406?1189314???10%?/ devtmpfs????????124837????298??124539????1%?/dev tmpfs???????????127113??????1??127112????1%?/dev/shm tmpfs???????????127113????381??126732????1%?/run tmpfs???????????127113?????13??127100????1%?/sys/fs/cgroup tmpfs???????????127113??????1??127112????1%?/run/user/0 [fxq@vm_46_188_centos?~]$4. df -m
[fxq@vm_46_188_centos?~]$?df?-m Filesystem?????1M-blocks??Used?Available?Use%?Mounted?on /dev/vda1??????????20030??4732?????14275??25%?/ devtmpfs?????????????488?????0???????488???0%?/dev tmpfs????????????????497?????0???????497???0%?/dev/shm tmpfs????????????????497????13???????485???3%?/run tmpfs????????????????497?????0???????497???0%?/sys/fs/cgroup tmpfs????????????????100?????0???????100???0%?/run/user/05. 單位換算:
10024Byte=1KB
1024KB =1MB
1024MB=1GB
1024GB=1TB
/dev/shm 內存:
6.free 查看swap
[root@vm_46_188_centos?~]#?free?total????????used????????free??????shared??buff/cache???available Mem:????????1016904??????325292???????90592???????12680??????601020??????504572 Swap:?????????????0???????????0???????????0 [root@vm_46_188_centos?~]#二、 du命令
du -sh /etc/
du -sh /etc/passwd
ls -lh /etc/passwd
當文件小于4KB時,也會顯示4KB
du -sb 可查看原大小 =ls -lh
du /root/ 查看文件夾內文件大小
[root@vm_46_188_centos?~]#?du?-sh?/root/28M /root/ [root@vm_46_188_centos?~]#?du?-s?/root/27768 /root/ [root@vm_46_188_centos?~]#?du?/root/ 4 /root/fxq 4 /root/ffff 4 /root/234 8 /root/.ssh/fengxiaoqing/.git/logs/refs/remotes/origin 12 /root/.ssh/fengxiaoqing/.git/logs/refs/remotes 8 /root/.ssh/fengxiaoqing/.git/logs/refs/heads 24 /root/.ssh/fengxiaoqing/.git/logs/refs 32 /root/.ssh/fengxiaoqing/.git/logs44 /root/.ssh/fengxiaoqing/.git/hooks 8 /root/.ssh/fengxiaoqing/.git/objects/5e 8 /root/.ssh/fengxiaoqing/.git/objects/46 8 /root/.ssh/fengxiaoqing/.git/objects/87 8 /root/.ssh/fengxiaoqing/.git/objects/f2 4 /root/.ssh/fengxiaoqing/.git/objects/pack 8 /root/.ssh/fengxiaoqing/.git/objects/02 4 /root/.ssh/fengxiaoqing/.git/objects/info 8 /root/.ssh/fengxiaoqing/.git/objects/9d6 0 /root/.ssh/fengxiaoqing/.git/objects4 /root/.ssh/fengxiaoqing/.git/branches 8 /root/.ssh/fengxiaoqing/.git/info 8 /root/.ssh/fengxiaoqing/.git/refs/remotes/origin 12 /root/.ssh/fengxiaoqing/.git/refs/remotes 8 /root/.ssh/fengxiaoqing/.git/refs/heads 4 /root/.ssh/fengxiaoqing/.git/refs/tags2 8 /root/.ssh/fengxiaoqing/.git/refs20 0 /root/.ssh/fengxiaoqing/.git20 8 /root/.ssh/fengxiaoqing22三、 磁盤分區
fdisk -l 查看本機硬盤.
[root@vm_46_188_centos?~]#?fdisk?-l Disk?/dev/vda:?21.5?GB,?21474836480?bytes,?41943040?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:?dosDisk?identifier:?0x0005fc9aDevice?Boot??????Start?????????End??????Blocks???Id??System /dev/vda1???*????????2048????41943039????20970496???83??Linux [root@vm_46_188_centos?~]#w 查看負載
[root@vm_46_188_centos?~]#?w22:58:39?up?21?days,??5:50,??1?user,??load?average:?3.59,?4.43,?4.76USER?????TTY??????FROM?????????????LOGIN@???IDLE???JCPU???PCPU?WHAT root?????pts/0????60.10.158.223????21:25????7.00s??0.16s??0.00s?w [root@vm_46_188_centos?~]#mbr 最多有4個主分區, 最大2T
[root@fxq-1?~]#?fdisk?-l 磁盤?/dev/sda:32.2?GB,?32212254720?字節,62914560?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0x0004f0b3設備?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????62914559????29154304???83??Linux磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節[root@fxq-1?~]# [root@fxq-1?~]#?fdisk?-l磁盤?/dev/sda:32.2?GB,?32212254720?字節,62914560?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0x0004f0b3設備?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????62914559????29154304???83??Linux磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節[root@fxq-1?~]#?fdisk?/dev/sdb 歡迎使用?fdisk?(util-linux?2.23.2)。Device?does?not?contain?a?recognized?partition?table 使用磁盤標識符?0xc2b902ea?創建新的?DOS?磁盤標簽。命令(輸入?m?獲取幫助): 命令操作a???toggle?a?bootable?flagb???edit?bsd?disklabelc???toggle?the?dos?compatibility?flagd???delete?a?partitiong???create?a?new?empty?GPT?partition?tableG???create?an?IRIX?(SGI)?partition?tablel???list?known?partition?typesm???print?this?menun???add?a?new?partitiono???create?a?new?empty?DOS?partition?tablep???print?the?partition?tableq???quit?without?saving?changess???create?a?new?empty?Sun?disklabelt???change?a?partition's?system?idu???change?display/entry?unitsv???verify?the?partition?tablew???write?table?to?disk?and?exitx???extra?functionality?(experts?only)命令(輸入?m?獲取幫助):n Partition?type:p???primary?(0?primary,?0?extended,?4?free)e???extended Select?(default?p): 分區號?(1-4,默認?1): 起始?扇區?(2048-41943039,默認為?2048): 將使用默認值?2048Last?扇區,?+扇區?or?+size{K,M,G}?(2048-41943039,默認為?41943039): 分區?1?已設置為?Linux?類型,大小設為?2?GiB命令(輸入?m?獲取幫助):磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0xc2b902ea設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1????????????2048?????4196351?????2097152???83??Linux命令(輸入?m?獲取幫助): Partition?type:p???primary?(1?primary,?0?extended,?3?free)e???extended Select?(default?p): 分區號?(2-4,默認?2): 起始?扇區?(4196352-41943039,默認為?4196352): 將使用默認值?4196352Last?扇區,?+扇區?or?+size{K,M,G}?(4196352-41943039,默認為?41943039): 分區?2?已設置為?Linux?類型,大小設為?5?GiB命令(輸入?m?獲取幫助):n If?you?want?to?create?more?than?four?partitions,?you?must?replace?a primary?partition?with?an?extended?partition?first.命令(輸入?m?獲取幫助):d 分區號?(1-4,默認?4): 分區?4?已刪除命令(輸入?m?獲取幫助)磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0xc2b902ea設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1????????????2048?????4196351?????2097152???83??Linux /dev/sdb2?????????4196352????14682111?????5242880???83??Linux /dev/sdb3????????14682112????31459327?????8388608???83??Linux命令(輸入?m?獲取幫助): Partition?type:p???primary?(3?primary,?0?extended,?1?free)e???extended Select?(default?e):? 已選擇分區?4起始?扇區?(31459328-41943039,默認為?31459328): 將使用默認值?31459328Last?扇區,?+扇區?or?+size{K,M,G}?(31459328-41943039,默認為?41943039): 將使用默認值?41943039分區?4?已設置為?Extended?類型,大小設為?5?GiB命令(輸入?m?獲取幫助):磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0xc2b902ea設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1????????????2048?????4196351?????2097152???83??Linux /dev/sdb2?????????4196352????14682111?????5242880???83??Linux /dev/sdb3????????14682112????31459327?????8388608???83??Linux /dev/sdb4????????31459328????41943039?????5241856????5??Extended命令(輸入?m?獲取幫助): All?primary?partitions?are?in?use 添加邏輯分區?5起始?扇區?(31461376-41943039,默認為?31461376):??? 將使用默認值?31461376Last?扇區,?+扇區?or?+size{K,M,G}?(31461376-41943039,默認為?41943039): 分區?5?已設置為?Linux?類型,大小設為?4?GiB命令(輸入?m?獲取幫助):磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0xc2b902ea設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1????????????2048?????4196351?????2097152???83??Linux /dev/sdb2?????????4196352????14682111?????5242880???83??Linux /dev/sdb3????????14682112????31459327?????8388608???83??Linux /dev/sdb4????????31459328????41943039?????5241856????5??Extended /dev/sdb5????????31461376????39849983?????4194304???83??Linux命令(輸入?m?獲取幫助): All?primary?partitions?are?in?use 添加邏輯分區?6起始?扇區?(39852032-41943039,默認為?39852032): 將使用默認值?39852032Last?扇區,?+扇區?or?+size{K,M,G}?(39852032-41943039,默認為?41943039): 值超出范圍。 Last?扇區,?+扇區?or?+size{K,M,G}?(39852032-41943039,默認為?41943039):+100M??????? 分區?6?已設置為?Linux?類型,大小設為?100?MiB命令(輸入?m?獲取幫助):磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0xc2b902ea設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1????????????2048?????4196351?????2097152???83??Linux /dev/sdb2?????????4196352????14682111?????5242880???83??Linux /dev/sdb3????????14682112????31459327?????8388608???83??Linux /dev/sdb4????????31459328????41943039?????5241856????5??Extended /dev/sdb5????????31461376????39849983?????4194304???83??Linux /dev/sdb6????????39852032????40056831??????102400???83??Linux 設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb1????????????2048?????4196351?????2097152???83??Linux /dev/sdb2?????????4196352????14682111?????5242880???83??Linux /dev/sdb3????????14682112????31459327?????8388608???83??Linux /dev/sdb4????????31459328????41943039?????5241856????5??Extended /dev/sdb5????????31461376????39849983?????4194304???83??Linux /dev/sdb6????????39852032????40056831??????102400???83??Linux命令(輸入?m?獲取幫助): 分區號?(1-6,默認?6): 分區?1?已刪除命令(輸入?m?獲取幫助):磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0xc2b902ea設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb2?????????4196352????14682111?????5242880???83??Linux /dev/sdb3????????14682112????31459327?????8388608???83??Linux /dev/sdb4????????31459328????41943039?????5241856????5??Extended /dev/sdb5????????31461376????39849983?????4194304???83??Linux /dev/sdb6????????39852032????40056831??????102400???83??Linux命令(輸入?m?獲取幫助): 分區號?(2-6,默認?6): 分區?5?已刪除命令(輸入?m?獲取幫助):磁盤?/dev/sdb:21.5?GB,?21474836480?字節,41943040?個扇區 Units?=?扇區?of?1?*?512?=?512?bytes 扇區大小(邏輯/物理):512?字節?/?512?字節 I/O?大小(最小/最佳):512?字節?/?512?字節 磁盤標簽類型:dos 磁盤標識符:0xc2b902ea設備?Boot??????Start?????????End??????Blocks???Id??System /dev/sdb2?????????4196352????14682111?????5242880???83??Linux /dev/sdb3????????14682112????31459327?????8388608???83??Linux /dev/sdb4????????31459328????41943039?????5241856????5??Extended /dev/sdb5????????39852032????40056831??????102400???83??Linux命令(輸入?m?獲取幫助):擴展學習
parted分區gpt格式?http://www.apelearn.com/bbs/thread-7243-1-1.html
我們在課上講的fdisk分區工具,它的分區格式為MBR,特點是,最多分4個主分區,磁盤大小不能超過2T。而GPT分區格式,突破了這些限制,它沒有主分區、擴展分區、邏輯分區之分,在一塊磁盤上最多可以分128個分區出來,支持大于2T的分區,最大卷可達18EB。?相信,隨著存儲級別的升級,將來的分區格式逐漸會淘汰MBR,而GPT成為主流。parted?工具常用功能: 當在命令行輸入parted后,進入parted命令的交互模式。輸入help會顯示幫助信息。下面就簡單介紹一下常用的功能1、check?簡單檢查文件系統。建議用其他命令檢查文件系統,比如fsck2、help?顯示幫助信息3、mklabel?創建分區表,?即是使用msdos(MBR)還是使用gpt,或者是其他方式分區表4、?mkfs?創建文件系統。該命令不支持ext3?格式,因此建議不使用,最好是用parted分好區,然后退出parted交互模式,用其他命令進行分區,比如:mkfs.ext35、mkpart?創建新分區。 格式:mkpart?PART-TYPE??[FS-TYPE]??START??END PART-TYPE?類型主要有primary(主分區),?extended(擴展分區),?logical(邏輯區).?擴展分區和邏輯分區只對msdos。 fs-type???文件系統類型,主要有fs32,NTFS,ext2,ext3等 start?end?分區的起始和結束位置。6、mkpartfs?建立分區及其文件系統。目前還不支持ext3文件系統,因此不建議使用該功能。最后是分好區后,退出parted,然后用其他命令建立文件系統。7、print?輸出分區信息。該功能有3個選項,free?顯示該盤的所有信息,并顯示磁盤剩余空間 number?顯示指定的分區的信息 all?顯示所有磁盤信息8、resize?調整指定的分區的大小。目前對ext3格式支持不是很好,所以不建議使用該功能。9、rescue?恢復不小心刪除的分區。如果不小心用parted的rm命令刪除了一個分區,那么可以通過rescue功能進行恢復。恢復時需要給出分區的起始和結束的位置。然后parted就會在給定的范圍內去尋找,并提示恢復分區。10、rm?刪除分區。命令格式?rm??number?。如:rm?3?就是將編號為3的分區刪除11、select?選擇設備。當輸入parted命令后直接回車進入交互模式是,如果有多塊硬盤,需要用select?選擇要操作的硬盤。如:select?/dev/sdb12、set?設置標記。更改指定分區編號的標志。標志通常有如下幾種:boot??hidden???raid???lvm?等。 boot?為引導分區,hidden?為隱藏分區,raid?軟raid,lvm?為邏輯分區。 如:set?3??boot??on???設置分區號3?為啟動分區 注:以上內容為parted常用的功能,由于該工具目前對ext3支持得不是很好,因此有些功能無法應用,比如move(移動分區)和resize等。parted分區功能事例。1、用命令模式?為/dev/sdb創建gpt類型文件分區表,并分500G分區。然后為該分區創建ext3文件系統。并將該分區掛載在/test文件夾下。#??parted??/dev/sdb??mklabel?????—創建分區表#??parted??/dev/sdb??mkpart??ext3??0??500000????—創建500G分區/dev/sdb1#?mkfs.ext3??/dev/sdb1??????—-將分區/dev/sdb1格式化成ext3格式文件系統#?mount??/dev/sdb1?/test???—將/dev/sdb1?掛載在/test下如果讓系統自動掛載/dev/sdb1?需手工編輯/etc/fstab文件。并在文件末尾添加如下內容: /dev/sdb1?????????????/test????????????????ext3????defaults????????0?02、創建大小為4G的交互分區。由于已經創建了500G的/dev/sdb1?,因此再創建的分區為/dev/sdb2#?parted?/dev/sdb?mkpart?swap?500000?504000?—創建4G分區/dev/sdb2#?mkswap??/dev/sdb2???—-將/dev/sdb2創建為交換分區#?swapon?/dev/sdb2???—-激活/dev/sdb2如果讓系統自動掛載/dev/sdb2這個交換分區,需手工編輯/etc/fstab文件。并在文件末尾添加如下內容: /dev/sdb2?????????????swap????????????????swap????defaults????????0?03、恢復被誤刪除的分區(也可以參考testdisk命令)。由于parted直接寫磁盤,因此一旦不小心刪除了某一分區,建議立即用rescue恢復。下面通過事例來理解恢復過程。#?parted?/dev/sdb?mkpart?ext3?504000?514000?—-創建10G分區/dev/sdb3#?mkfs.ext3?/dev/sdb3??—將/dev/sdb3格式化成ext3文件系統。#?parted?/dev/sdb?rm?3?—-刪除/dev/sdb3#?parted?/dev/sdb?rescue?504000?514000????—依照屏幕提示,輸入yes即可恢復被誤刪除分區parted分區實例
http://note.youdao.com/share/?id=42eff7fc6d14daeb5d710e9f6c4c7b59&type=note#/
本文轉自 楓葉云 ?51CTO博客,原文鏈接:http://blog.51cto.com/fengyunshan911/1957487
總結
以上是生活随笔為你收集整理的linux CentOS7 磁盘分区fdisk 、df 、du、parted 命令实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 魔兽世界怀旧服月卡跟普通服通用吗 《魔兽
- 下一篇: 平安口袋银行怎么解绑银行卡