Linux常用命令(4)-磁碟管理__Linux
最後更新:2018-07-22
來源:互聯網
上載者:User
案資料除了檔案實際內容外, 通帯有非帯多癿屬性,例如 Linux 作業系統的檔案許可權(rwx)和檔案屬性(拞有者、群組、時間參數等)。
檔案系統會將這兩部資料分別存放在不同的區塊,許可權屬性放置到 inode 中,至亍實際資料則放置到 data block 區塊中。 另外,還有一個超級區塊 (superblock) 會記彔整個
檔案系統癿整體資訊,包括 inode 不 block 癿總量、使用量、剩餘量等。
每個inode與block 都有編號,三者資料的含義可以簡略說明如下:
superblock:記錄此 filesystem的整體資訊,包括 inode/block的總量、使用量、剩餘量, 以及檔案系統癿格式不相關資訊等;
inode:記彔檔案的屬性,一個檔案佔用一個 inode,同時記彔此檔案的資料所在的 block 號碼;
block:實際記彔檔案癿內容,若檔案太大時,會佔用多個 block。
檔案系統的簡單操作
#df -k 列出檔案系統的整體磁碟使用量。單位是k, 選擇性參數[k],[m],[i]inodes 顯示inode資訊。 df 主要讀叏癿資料幾乎都是針對一整個檔案系統,因此讀取的範圍主要是在Superblock內的信
息。
# df -m /home
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/sda8 12084 4833 6638 43% /home
#du -k 評估檔案或者目錄的磁碟使用量.選擇性參數[k],[m],[s]表示求和只輸出總容量
# du -k /home/chenlly/eclipse/configuration
104 /home/chenlly/eclipse/configuration/org.eclipse.equinox.simpleconfigurator
8 /home/chenlly/eclipse/configuration/org.eclipse.equinox.source
36 /home/chenlly/eclipse/configuration/org.eclipse.update
156 /home/chenlly/eclipse/configuration
如果你叧想要知道該目彔佔了多少總容量的話用-s
# du -s /home/chenlly/eclipse/configuration
156 /home/chenlly/eclipse/configuration
#df -h 要查看磁碟還剩多少空間
#du -sh * 你是需要知道當前的檔案夾下的磁碟使用方式
# mount 負載檔案系統
在弄清楚mount之前要弄清的概念:
裝置一般在/dev目錄裡 /dev/hda1 hd表示硬碟 fd 表示磁碟片 eth 網路裝置(eth0 第一個網路裝置) a標識第一個裝置,通常一個裝置介面可以接四個裝置(如四個硬碟),1表示第一個分區,所以hdb2表示的是第二塊硬碟的第二個分區
mount -t vfstype 顯示被負載檔案系統的類型
比如,要訪問CD-ROM裡的內容,需要將CD-ROM裝置掛載在某個檔案下,Linux可以標識的檔案系統有如下幾種
FAT32 :vfat
NTFS :ntfs
CD-ROM:iso9660
Linux檔案系統:EXT2 EXT3
應用:mount -t iso9660 /dev/hdc/mnt/cdrom 將CD-ROM 掛載在mnt/cdrom下,一般在mnt下有如下目錄:mnt/cdrom,mnt/floppy
比如利用mount掛載windows下的c盤 ,首先在mnt下建立winc目錄
mkdir winc
mount -t vfat /dev/hda1/mnt/winc
unmount 卸載檔案系統
unmount /cdrom
eg:CentOS掛載新硬碟
1.查看當前硬碟使用狀況:
df -h
2.查看新硬碟,Disk /dev/sda 4T的硬碟是需要掛載的。
#fdisk –l
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 64 36405 291908608 8e Linux LVM
Disk /dev/sda: 4000.8 GB, 4000787030016 bytes
255 heads, 63 sectors/track, 486401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa820dbce
Disk /dev/mapper/VolGroup-LogVol01: 264.6 GB, 264551530496 bytes
255 heads, 63 sectors/track, 32163 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-LogVol00: 34.4 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
3、硬碟分區,由於centOS 只能一次掛載2T。所有4T的需要分兩個區
#sudo fdisk /dev/sda
Command (m for help):m
(1)、輸入m 進入協助介面
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
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)
(2)、 輸入n 添加分區
Command (m for help): n
Command action
e extended
p primary partition (1-4)
(3)、選擇分區數
Partition number (1-4): 2
(4)設定柱面,這裡選擇預設值就可以
First cylinder (267350-486401, default 267350): 267350
Last cylinder, +cylinders or +size{K,M,G} (267350-486401, default 486401): 486401
4、掛載分區
# fdisk -l 查看分區情況
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 64 36405 291908608 8e Linux LVM
Disk /dev/sda: 4000.8 GB, 4000787030016 bytes
255 heads, 63 sectors/track, 486401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa820dbce
Device Boot Start End Blocks Id System
/dev/sda1 1 267349 2147480811 83 Linux
/dev/sda2 267350 486401 1759535190 83 Linux
Disk /dev/mapper/VolGroup-LogVol01: 264.6 GB, 264551530496 bytes
255 heads, 63 sectors/track, 32163 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-LogVol00: 34.4 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
發現多了/dev/sda1和/dev/sda2兩個分區
(1)、建立目錄maphd1和maphd2 用於掛載/dev/sda1 和 /dev/sda2兩個分區
(2)、在掛載之前先格式化
# mkfs.ext4 /dev/sda1
# mkfs.ext4 /dev/sda2
(3)、分別掛載
# mount /dev/sda1 /maphd1
# mount /dev/sda2 /maphd2
5. 設定開機啟動自動掛載
新建立的分區不能開機自動掛載,每次重啟機器都要手動掛載。
設定開機自動掛載需要修改/etc/fstab檔案
#vi /etc/fstab
在檔案的最後增加一行
/dev/sda1 /maphd1 ext4 defaults 1 2
/dev/sda1 /maphd1 ext4 defaults 1 2