歡迎您光臨本站 註冊首頁

Linux查看磁碟分區等命令和相關工具介紹

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

一、df 命令;

df 是來自於coreutils 軟體包,系統安裝時,就自帶的;我們通過這個命令可以查看磁碟的使用情況以及文件系統被掛載的位置;

舉例:

[root@localhost beinan]# df -lh
Filesystem 容量 已用 可用 已用% 掛載點
/dev/hda8 11G 6.0G 4.4G 58% /
/dev/shm 236M 0 236M 0% /dev/shm
/dev/sda1 56G 22G 35G 39% /mnt/sda1
我們從中可以看到,系統安裝在/dev/hda8 ;還有一個56G的磁碟分區/dev/sda1掛載在 /mnt/sda1中;

其它的參數請參考 man df

二、fdsik

fdisk 是一款強大的磁碟操作工具,來自util-linux軟體包,我們在這裡只說他如何查看磁碟分區表及分區結構;參數 -l ,通過-l 參數,能獲得機器中所有的硬碟的分區情況;

[root@localhost beinan]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 765 6144831 7 HPFS/NTFS
/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/dev/hda3 2806 7751 39728745 5 Extended
/dev/hda5 2806 3825 8193118 83 Linux
/dev/hda6 3826 5100 10241406 83 Linux
/dev/hda7 5101 5198 787153 82 Linux swap / Solaris
/dev/hda8 5199 6657 11719386 83 Linux
/dev/hda9 6658 7751 8787523 83 Linux

在上面Blocks中,表示的是分區的大小,Blocks的單位是byte ,我們可以換算成M,比如第一個分區/dev/hda1的大小如果換算成M,應該是6144831/1024=6000M,也就是6G左右,其實沒有這麼麻煩,粗略的看一下把小數點向前移動三位,就知道大約的體積有多大了;

System 表示的文件系統,比如/dev/hda1 是NTFS格式的;/dev/hda2 表示是fat32格式的文件系統;.

在此例中,我們要特別注意的是/dev/hda3分區,這是擴展分區;他下面包含著邏輯分區,其實這個分區相當於一個容器;從屬於她的有 hda5,hda6,hda7,hda8,hda9 ;

我們還注意到一點,怎麼沒有hda4呢?為什麼hda4沒有包含在擴展分區?一個磁碟最多有四個主分區; hda1-4算都是主分區;hda4不可能包含在擴展分區里,另外擴展分區也算主分區;在本例中,沒有hda4這個分區,當然我們可以把其中的一個分區設置為主分區,只是我當時分區的時候沒有這麼做而已;

再仔細統計一下,我們看一看這個磁碟是不是還有空間?hda1 hda2 hda3=實際已經分區的體積,所以我們可以這樣算 hda1 hda2 hda3=6144831 16386300 39728745 = 62259876 (b),換算成M單位,小數點向前移三位,所以目前已經劃分好的分區大約佔用體積是62259.876(M),其實最精確的計算62259876/1024=60800.67(M);而這個磁碟大小是80.0 GB (80026361856byte),其實實際大小也就是78150.744(M);通過我們一系列的計算,我們可以得出這個硬碟目前還有使用的空間;大約還有18G未分區的空間;

fdisk -l 能列出機器中所有磁碟的個數,也能列出所有磁碟分區情況;比如:

[root@localhost beinan]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 765 6144831 7 HPFS/NTFS
/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/dev/hda3 2806 7751 39728745 5 Extended
/dev/hda5 2806 3825 8193118 83 Linux
/dev/hda6 3826 5100 10241406 83 Linux
/dev/hda7 5101 5198 787153 82 Linux swap / Solaris
/dev/hda8 5199 6657 11719386 83 Linux
/dev/hda9 6658 7751 8787523 83 Linux
Disk /dev/sda: 60.0 GB, 60011642880 bytes
64 heads, 32 sectors/track, 57231 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 57231 58604528 83 Linux

通過上面我們可以知道此機器有兩塊硬碟,我們也可以指定fdisk -l 來查看其中一個硬碟的分區情況;

[root@localhost beinan]# fdisk -l /dev/sda
Disk /dev/sda: 60.0 GB, 60011642880 bytes
64 heads, 32 sectors/track, 57231 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 57231 58604528 83 Linux

通過上面情況可以知道,在/dev/sda 這個磁碟中,只有一個分區;使用量差不多是百分百了;

我們還可以來查看 /dev/hda的

[root@localhost beinan]# fdisk -l /dev/hda

自己試試看?

三、cfdisk 來自於util-linux的軟體包;

cfdisk 也是一款不錯的分區工具;在有些發行版中,此工具已經從util-linux包中剔除;cfdisk 簡單易用是他的特點;和DOS中的fdisk 相似;在本標題中,我們只來解說如何查看機器的中的磁碟分區狀況及所用的文件系統等;

查看磁碟分區的用法 cfdisk -Ps 磁碟設備名;

比如

[root@localhost beinan]cfdisk -Ps
[root@localhost beinan]cfdisk -Ps /dev/hda
[root@localhost beinan]cfdisk -Ps
Partition Table for /dev/hda
First Last
# Type Sector Sector Offset Length Filesystem Type (ID) Flag
-- ------- ----------- ----------- ------ ----------- -------------------- ----
1 Primary 0 23438834 63 23438835 Linux (83) Boot
2 Primary 23438835 156296384 0 132857550 Extended (05) None
5 Logical 23438835 155268224 63 131829390 Linux (83) None
6 Logical 155268225 156296384 63 1028160 Linux swap (82) None

我們只用的參數 -Ps,就列出了磁碟的分區情況;目前在Slackware Debian Mandrake 等主流發行版中存在cfdisk ,而fedora 4.0把這個小工具剔除了;有點可惜;這是我在Slackware中操作的;

如果您這樣操作,就更直觀了;

[root@localhost beinan]cfdisk 磁碟設備名

舉例:

[root@localhost beinan]cfdisk /dev/hda

您所看到的是如下的模式:


cfdisk 2.12a
Disk Drive: /dev/hda
Size: 80026361856 bytes, 80.0 GB
Heads: 255 Sectors per Track: 63 Cylinders: 9729
Name Flags Part Type FS Type [Label] Size (MB)
-------------------------------------------------------------------------------------------
hda1 Boot Primary Linux ReiserFS 12000.69
hda5 Logical Linux ReiserFS 67496.65
hda6 Logical Linux swap 526.42
[Bootable] [ Delete ] [ Help ] [Maximize] [ Print ] [ Quit ]
[ Type ] [ Units ] [ Write ]
Toggle bootable flag of the current partition

您進入了cfdisk 的操作界面;用鍵盤移動指針到[Quit]就可以退出;

四、parted 功能不錯的分區工具;在Fedora 4.0中有帶,可以自己安裝上;在此主題中,我們只說如何查看磁碟的分區情況;

調用方法簡單,parted 默認是打開的設備是/dev/hda ,也可以自己指定;比如 parted /dev/hda 或/dev/sda 等;退出的方法是 quit

[root@localhost beinan]# parted
使用 /dev/hda
(parted) p
/dev/hda 的磁碟幾何結構:0.000-76319.085 兆位元組
磁碟標籤類型:msdos
Minor 起始點 終止點 類型 文件系統 標誌
1 0.031 6000.842 主分區 ntfs 啟動
2 6000.842 22003.088 主分區 fat32 lba
3 22003.088 60800.690 擴展分區
5 22003.119 30004.211 邏輯分區 reiserfs
6 30004.242 40005.615 邏輯分區 reiserfs
7 40005.646 40774.350 邏輯分區 linux-swap
8 40774.381 52219.094 邏輯分區 ext3
9 52219.125 60800.690 邏輯分區 reiserfs

我們在partd 的操作面上,用p就可以列出當前磁碟的分區情況,如果想要查看其它磁碟,可以用 select 功能,比如 select /dev/sda ;

五、qtparted ,與parted 相關的軟體還有qtparted ,也能查看到磁碟的結構和所用的文件系統,是圖形化的;

[beinan@localhost ~]# qtparted

圖形化的查看,一目了然;


點擊小圖看大圖

六、sfdisk 也是一個分區工具,功能也多多;我們在這裡只說他的列磁碟分區情況的功能;

[root@localhost beinan]# sfdisk -l

自己看看吧;

sfdisk 有幾個很有用的功能;有興趣的弟兄不妨看看;

七、partx 也簡要的說一說,有些系統自帶了這個工具,功能也簡單,和fdisk 、parted、cfdisk 來說不值一提;不用也罷;

用法: partx 設備名

[root@localhost beinan]# partx /dev/hda


# 1: 63- 12289724 ( 12289662 sectors, 6292 MB)
# 2: 12289725- 45062324 ( 32772600 sectors, 16779 MB)
# 3: 45062325-124519814 ( 79457490 sectors, 40682 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
# 5: 45062388- 61448624 ( 16386237 sectors, 8389 MB)
# 6: 61448688- 81931499 ( 20482812 sectors, 10487 MB)
# 7: 81931563- 83505869 ( 1574307 sectors, 806 MB)
# 8: 83505933-106944704 ( 23438772 sectors, 12000 MB)
# 9: 106944768-124519814 ( 17575047 sectors, 8998 MB)

八、查看目前機器中的所有磁碟及分區情況:

[beinan@localhost ~]$ cat /proc/partitions
major minor #blocks name
3 0 78150744 hda
3 1 6144831 hda1
3 2 16386300 hda2
3 5 8193118 hda5
3 6 10241406 hda6
3 7 787153 hda7
3 8 11719386 hda8
3 9 8787523 hda9
8 0 58605120 sda
8 1 58604528 sda1

九、mac-fdisk 這個工具主要是用在Powerpc版本的Linux中,咱們常用X86版本中沒有這個工具;這個只是介紹一下;


[火星人 ] Linux查看磁碟分區等命令和相關工具介紹已經有403次圍觀

http://coctec.com/docs/linux/show-post-56336.html