文章插圖

文章插圖
1檢測并確認新硬盤
掛接好新的硬盤設備并啟動主機后,Linux系統會自動檢測并加載該硬盤,無須額外安裝驅動 。執行“fdisk -l”命令即可查看,確認新增硬盤的設備名稱和位置 。作用:列出當前系統中所有硬盤設備及其分區的信息 。
[[email protected] ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000b2b5dDevice BootStartEndBlocksIdSystem/dev/sda1*11310240083LinuxPartition 1 does not end on cylinder boundary./dev/sda213279213401682Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda327926111873408083Linux[[email protected] ~]#上述輸出信息中包含了各硬盤的整體情況和分區情況,其中“/dev/sda”為原有的硬盤設備,對于已有的分區,將通過列表的方式輸出以下信息;Device:分區的設備文件名稱 。Boot:是否是引導分區 。是,則有“*”標識 。Start:該分區在硬盤中的起始位置 。End:該分區在硬盤中的結束位置 。Blocks:分區的大小,以Blocks(塊)為單位,默認的塊大小為1024字節 。Id:分區對應的系統ID號 。83表示Linux中的EXT4分區,8e表示LVM 邏輯卷 。System:分區類型 。
2添加新的硬盤
[[email protected] ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000b2b5dDevice BootStartEndBlocksIdSystem/dev/sda1*11310240083LinuxPartition 1 does not end on cylinder boundary./dev/sda213279213401682Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda327926111873408083LinuxDisk /dev/sdb: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000[[email protected] ~]#3規劃硬盤中的分區在硬盤設備中創建、刪除、更改分區等操作同樣通過fdisk命令進行,只要使用硬盤的設備文件作為參數 。例如,執行“fdisk /dev/sdb”命令,即可進入到交互式的分區管理界面中 。
在該操作界面中的“Command (m for help):”提示符后,輸入特定的分區操作指令,可以完成各項分區管理任務 。輸入“m”指令后,可以查看各種操作指令的幫助信息 。
fdisk 分區工具的交互式操作界面
[[email protected] ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x97fe0724.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. It's strongly recommended toswitch off the mode (command 'c') and change display units tosectors (command 'u').Command (m for help):C/C++Linux服務器開發/后臺架構師【零聲教育】-學習視頻教程-騰訊課堂【文章福利】:小編整理了一些個人覺得比較好的學習書籍、視頻資料共享在群文件里面,有需要的可以自行添加哦!~點擊加入(832218493需要自取)
Command (m for help): mCommand actionatoggle a bootable flagbedit bsd disklabelctoggle the dos compatibility flagddelete a partitionllist known partition typesmprint this menunadd a new partitionocreate a new empty DOS partition tablepprint the partition tableqquit without saving changesscreate a new empty Sun disklabeltchange a partition's system iduchange display/entry unitsvverify the partition tablewwrite table to disk and exitxextra functionality (experts only)Command (m for help):p指令——列出硬盤中的分區情況使用“p”指令可以列出詳細的分區情況,信息顯示的格式與執行“fdisk -l”命令相同,硬盤中尚未建立分區時,輸出的列表信息為空 。
Command (m for help): pDisk /dev/sdb: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x97fe0724Device BootStartEndBlocksIdSystemCommand (m for help):n指令——新建分區使用“n”指令可以進行創建分區的操作,包括主分區和擴展分區 。根據提示繼續輸入“p”選擇創建主分區,輸入“e”選擇創建擴展分區 。之后依次選擇分區序號,起始位置,結束位置或分區大小即可完成新分區的創建 。
選擇分區好時,主分區和擴展分區的序號只能為1-4.分區起始位置一般由fdisk默認識別,結束位置或大小可以使用”+sizeM”或”+sizeG”的形式 。
Command (m for help): nCommand actioneextendedpprimary partition (1-4)pPartition number (1-4): 1First cylinder (1-652, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +5GValue out of range.完成后可以輸入“p”指令查看分區情況;Command (m for help): pDisk /dev/sdb: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x97fe0724Device BootStartEndBlocksIdSystem/dev/sdb116525237158+83Linuxd指令——刪除分區使用“d”指令可以刪除指定的分區,根據提示繼續輸入需要刪除的分區序號,在執行前刪除分區時一定要慎重,應首先使用p指令查看分區的序號,確認無誤后再進行刪除 。
需要注意的是,若擴展分區被刪除,則擴展分區之下的邏輯分區也將被刪除 。因此建議從最后一個分區開始進行刪除,以免fdisk識別的分區序號發生混亂 。
t指令——變更分區的類型
在fdisk分區工具中,新建的分區默認使用的文件系統類型為EXT4,一般不需要更改,但是若新建的分區需要用作swap交換分區或其他類型的文件系統時,則需要對分區類型進行變更以保持一致性,從而避免在管理分區時產生混亂 。
使用“t”指令可以變更分區的ID號,操作時需要依次指定目標分區序號,新的系統ID號 。不同類型的文件系統對應不同的ID號,以16進制數表示,在fdisk交互環境中輸入“l”指令進行列表查看,最常用的EXT4、swap文件系統的ID號分別為83、82,而用于windows中的NTFS文件系統的ID號一般為86 。
w和q指令——退出fdisk分區工具
完成對硬盤的分區操作以后,可以執行w或q指令退出fdisk分區工具 。其中“w”將保存分區操作,而“q”指令將不會保存對硬盤所做的分區操作 。
對已包含數據的硬盤進行分區時,一定要做好數據備份,保存之前要確保操作無誤,以免發生數據損壞,若無法確定本次分區操作是否正確,建議使用“q”指令不保存退出 。
變更磁盤的分區設置以后,建議最好將系統重啟一次,或者執行“partprobe”命令使操作系統檢測新的分區表情況 。在某些Linux操作系統中,若不進行這些操作,可能會導致格式化分區時對硬盤中已有數據的損壞,嚴重者甚至引起系統崩潰 。執行 partprobe命令檢測/dev/sdb磁盤中的分區變化 。
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[[email protected] ~]# partprobe /dev/sdb[[email protected] ~]#4管理文件系統mkfs命令的使用
mkfs命令是一個前端工具,可以自動加載不同的程序來創建各種類型的分區,而后端包括有多個與mkfs命令相關的工具程序,位于/sbin目錄中 。
[[email protected] ~]# ls /sbin/mkfs*/sbin/mkfs/sbin/mkfs.cramfs/sbin/mkfs.ext2/sbin/mkfs.ext3/sbin/mkfs.ext4/sbin/mkfs.ext4dev/sbin/mkfs.msdos/sbin/mkfs.vfat[[email protected] ~]#基本的命令格式mkfs -t 文件系統類型 分區設備
mkswap命令的使用
使用mkswap命令可以在指定的分區上創建交換文件系統,目標分區先通過fdisk工具將ID號設為82 。
對于新增加的交換分區,需要使用swapon命令進行啟用,反之使用swapoff命令可以停用指定的交換分區 。
[[email protected] ~]# fdisk -l /dev/sdaDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000b2b5dDevice BootStartEndBlocksIdSystem/dev/sda1*11310240083LinuxPartition 1 does not end on cylinder boundary./dev/sda213279213401682Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda327926111873408083Linux5掛載、卸載文件系統掛載文件系統
mount命令的基本使用格式
mount [-t 文件系統類型] 存儲設備 掛載點
光盤對應的設備文件通常使用”/dev/cdrom”,其實這是一個鏈接文件,鏈接到實際的光盤設備”/dev/sr0″ 。使用這兩個名稱都可以表示光盤設備 。由于光盤是只讀的存儲介質,因此在掛載時系統會出現”mounting read-only”的提示信息 。
使用不帶任何參數或選項的mount命令時,將顯示出當前系統中已掛載的各個分區的相關信息,最近掛載的文件系統將顯示在最后邊 。
[[email protected] ~]# mount/dev/sda3 on / type ext4 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")/dev/sda1 on /boot type ext4 (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)/dev/sr0 on /media/CentOS_6.5_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)[[email protected] ~]#卸載文件系統需要卸載文件系統時,使用的命令為umount,使用掛載點目錄或對應設備的文件名作為卸載參數,Linux系統中,由于同一個設備可以被掛載到多個目錄下,所以一般建議通過掛載點的目錄位置來進行卸載 。
[[email protected] ~]# umount /dev/cdrom[[email protected] ~]#設置文件系統的自動掛載系統中的/etc/fstab文件可以視為mount命令的配置文件,其中存儲了文件系統的靜態掛載數據 。Linux系統在每次開機時,會自動讀取這個文件的內容,自動掛載所指定的文件系統 。默認的fatab文件中包括了根分區、/boot分區、交換分區及proc、tmpfs等偽文件系統的掛載配置 。
[[email protected] ~]# cat /etc/fstab## /etc/fstab# Created by anaconda on Sat Jun4 06:06:05 2016## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#UUID=793c943d-a96e-453d-8249-a8eb9ad1ec59 /ext4defaults1 1UUID=758a54e1-de64-4e02-a4a9-f09f4c28fdfa /bootext4defaults1 2UUID=0535a0f7-88f2-490c-b26f-94a27e45804d swapswapdefaults0 0tmpfs/dev/shmtmpfsdefaults0 0devpts/dev/ptsdevptsgid=5,mode=6200 0sysfs/syssysfsdefaults0 0proc/procprocdefaults0 0[[email protected] ~]#在”/etc/fstab”文件中,每一行記錄對應一個分區或設備的掛載配置信息,各部分的含義如下 。第1字段:設備名或設備卷標名 。
第2字段:文件系統的掛載點目錄的位置 。
第3字段:文件系統類型,如ext4、swap等 。
第4字段:掛載參數,mount命令”-o”選項后可使用的參數 。
(defaults、rw、ro、noexec分別表示默認參數、可寫、只讀、禁用執行程序)
第5字段:表示文件系統是否需要dump備份,為1時表示需要,為0時將被dump所忽略 。
第6字段:該數字用于決定在系統啟動時進行磁盤檢查的順序 。0表示不進行檢查,1表示優先檢查,2表示其次檢查,對于根分區應設為1,其他分區設為2 。
查看磁盤使用情況
不帶選項及參數的mount命令可以顯示分區的掛載情況,了解系統中已掛載各文件系統的磁盤使用情況可以使用df命令 。
df命令使用文件或者設備作為命令參數,常用的選項為”-h”,”-T” 。”-h”選項可以顯示更易讀的容量單位,而”-T”選項用于顯示對應文件系統的類型 。
[[email protected] ~]# df -hTFilesystemTypeSizeUsed Avail Use% Mounted on/dev/sda3ext418G5.0G12G30% /tmpfstmpfs495M224K495M1% /dev/shm/dev/sda1ext497M30M63M32% /boot[[email protected] ~]#
- 衛衣的帽子怎么撐起來
- 新iphone13怎么激活使用
- 吸塵器吸不進去東西怎么辦
- ipad屏幕比例顯示設置 ipad怎么設置顯示比例
- 蘋果藍牙耳機怎么連電腦使用 蘋果耳機如何連接電腦
- 視頻號直播間推流 視頻號推流直播怎么商品講解
- 抖店app怎么掃碼登錄 抖店怎么掃碼登錄
- 筆記本防火墻怎么關閉win10 聯想筆記本防火墻怎么關閉win10
- iPad不支持flash ipad沒有flash怎么辦
- 帶貨直播腳本怎么寫 如何做好直播帶貨的腳本
