磁碟管理之 raid 檔案系統 分割槽
第1章 RAID 磁碟陣列
1.1 使用raid的目的
1)獲得更大的容量
2)讓資料更安全
3)讀寫速度更快
1.2 raid0、raid1、raid5、raid10對比
raid型別 |
數量 |
優點 |
缺點 |
使用型別 |
raid0 條帶 |
至少1塊硬碟。 |
把所有硬碟的容量加在一起,讀寫速度更快 |
一塊硬碟損壞,整體都不能使用 |
資料不是很重要,追求效能 資料庫的從庫 叢集的某個節點 |
raid1 映象 |
只能是兩塊硬碟 |
安全,有100%的冗餘 |
寫入速度比較慢 讀取還可以 成本較高 |
對資料安全要求比較高,不需要太多的效能 |
raid5 |
至少三塊硬碟 |
有奇偶校驗,有一定的冗餘,最多損壞1塊硬碟 損失一塊硬碟的容量 |
讀取效能可以 寫入很慢 |
比較通用。 +spare 可以作為熱備 |
raid10 |
最少4塊硬碟 數量必須是偶數 |
讀寫的速度都很快,安全性較高冗餘,最多可以損壞一半 |
成本高 容量浪費一半 |
資料庫 重要的檔案 |
第2章 磁碟分割槽
2.1 mbr是什麼
mbr引導:主引導記錄
2.1.1 mbr在哪裡
磁碟的0磁頭 0磁軌 1扇區 前446位元組
一個扇區的大小為512位元組
前446位元組 mbr
中間64位元組 分割槽表
最後2位元組 分割槽結束表示55AA
2.1.2 分割槽表
在分割槽表的64位元組裡,劃分為4個格子 16*4
每個格子裡存放的是分割槽的資訊(主分割槽 擴充套件分割槽)
2.1.3 如何檢視磁碟第一個扇區裡的內容
拿出出來前512個位元組
[[email protected] ~]# dd if=/dev/sda of=/tmp/512.bin bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000190527 s, 2.7 MB/s
看下檔案的型別
[[email protected] ~]# file /tmp/512.bin
/tmp/512.bin: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x6280, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 409600 sectors; partition 2: ID=0x82, starthead 159, startsector 411648, 1572864 sectors; partition 3: ID=0x83, starthead 135, startsector 1984512, 18987008 sectors, code offset 0x48
2.1.4 如何檢視二進位制檔案的內容
od命令檢視二進位制檔案的內容
[[email protected] ~]# od -xa /tmp/512.bin
……
0000760 0000 0000 0000 0000 0000 0000 0000 aa55 結束識別符號
nul nul nul nul nul nul nul nul nul nul nul nul nul nul U *
0001000
2.2 主分割槽、擴充套件分割槽、邏輯分割槽的關係
2.2.1 主分割槽
最多有4個主分割槽
2.2.2 擴充套件分割槽
沒有辦法直接使用 ,需要劃分成邏輯分割槽才可以使用。
2.2.3 邏輯分割槽
必須要在擴充套件分割槽下面劃分邏輯分割槽才可以使用。
邏輯分割槽
sas/sata/scsi/ 中為 sda 5-15
2.3 在系統中磁碟分割槽的命名
磁碟裝置都放在/dev/目錄下
sas/sata/scsi/介面 sd 開頭
ide 介面 hd開頭
2.3.1 磁碟名稱示例
第一塊硬碟 sda
第二塊硬碟 sdb
第三塊硬碟 sdc
2.3.2 第一塊硬碟 sda
主分割槽 1-4
擴充套件分割槽 1-4 一般為4
邏輯分割槽 從5+開始
2.3.3 分割槽的命名規則
第一塊硬碟的第一個主分割槽:sda1
第一塊硬碟的第一個邏輯分割槽:sda5
第二塊硬碟的第二個邏輯分割槽:sdb6
2.4 回顧分割槽方式
2.4.1 沒有重要資料
/boot 200M 存放系統的引導資訊 核心
swap 交換分割槽 防止記憶體用光了 臨時的一個記憶體
如果你的記憶體小於8G swap是記憶體的1.5倍 如果你的記憶體大於8G swap給8G
/ 根分割槽 剩餘多少給多少
2.4.2 很多重要資料
/boot 200M 存放系統的引導資訊 核心
swap 交換分割槽 防止記憶體用光了 臨時的一個記憶體
如果你的記憶體小於8G swap是記憶體的1.5倍 如果你的記憶體大於8G swap給8G
/ 根分割槽 20G-200G
/data 存放重要的資料 剩餘多少給多少
2.4.3 不知道資料是否重要
/boot 200M 存放系統的引導資訊 核心
swap 交換分割槽 防止記憶體用光了 臨時的一個記憶體
如果你的記憶體小於8G swap是記憶體的1.5倍 如果你的記憶體大於8G swap給8G
/ 根分割槽 20G-200G
剩餘空間不分 放著誰使用這臺伺服器誰來分割槽
2.5 ps 命令內容詳解--每列的含義
2.5.1 ps aux 中的vsz與rss
[[email protected] shm]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 19352 1300 ? Ss Sep14 0:01 /sbin/ini
使用者 程序號 CPU 記憶體
⚠VSZ 程序所佔用的虛擬記憶體的大小(實體記憶體+swap)
⚠RSS 程序所佔用的記憶體(實體記憶體)
2.5.2 ps -ef 列含義系簡介
[[email protected] shm]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Sep14 ? 00:00:01 /sbin/init
使用者名稱 程序號 子程序號 運行了什麼命令
第3章 磁碟分割槽
3.1 linux裡面的分割槽工具
fdisk 主要是給磁碟小於2T(只能出來分割槽表是mbr的)
parted 主要是給磁碟大於2T(gpt)
3.2 通過fdisk給磁碟進行分割槽(建立一個10M主分割槽和一個40M邏輯分割槽)
3.2.1 使用fdisk會提示一個錯誤
[[email protected] ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x31dcd35a.
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)
警告 : 可以關閉dos的相容模式,使用扇區作為分割槽的預設單位 -cu ↓
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help):
3.2.2 fdisk新增上了 -cu 引數
-cu 引數是在分割槽的時候,能夠以扇區的方式進行。
[[email protected] ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb9f506a4.
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)
Command (m for help):
3.2.3 檢視fdisk的幫助資訊
Command (m for help): m
Command action
d delete a partition 刪除一個分割槽
m print this menu 顯示幫助選單
n add a new partition 建立一個分割槽
p print the partition table 顯示分割槽表
q quit without saving changes 退出不儲存
w write table to disk and exit 儲存並退出
3.2.4 建立一個主分割槽
Command (m for help): n
Command action
e extended 擴充套件分割槽
p primary partition (1-4) 主分割槽
p
Partition number (1-4): 1 第一個分割槽
First sector (2048-208895, default 2048): 直接回車為預設
Using default value 2048 預設選擇第一個扇區
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): +10M
3.2.5 顯示一下分出來的分割槽
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83
3.2.6 建立一個擴充套件分割槽
擴充套件分割槽的分割槽原則是:剩多少給多少
Command (m for help): n
Command action
e extended 擴充套件分割槽
p primary partition (1-4)
e
Partition number (1-4): 2
First sector (22528-208895, default 22528):
Using default value 22528
Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895):
Using default value 208895
3.2.7 顯示現在的分割槽表資訊
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 208895 93184 5 Extended
3.2.8 在拓展分割槽下建立邏輯分割槽
Command (m for help): n
Command action
l logical (5 or over) 邏輯分割槽,建立完擴充套件分割槽後只能建立邏輯分割槽
p primary partition (1-4)
l
First sector (24576-208895, default 24576):
Using default value 24576
Last sector, +sectors or +size{K,M,G} (24576-208895, default 208895): +40M
3.2.9 顯示一下當前的分割槽表
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 208895 93184 5 Extended
/dev/sdb5 24576 106495 40960 83 Linux
3.2.10 儲存並退出
fdisk 必須儲存以後才能生效,w為儲存並退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.3 【示例】新增一塊硬碟sdb 100m劃分一個分割槽 ,掛載到/mnt目錄
3.3.1 第一步 建立一個主分割槽
[[email protected] ~]# fdisk -cu /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-208895, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):
Using default value 208895
都選擇預設就是使用整塊盤的空間建立一個分割槽
3.3.2 顯示當前的分割槽表
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 208895 103424 83 Linux
3.3.3 儲存並退出
fdisk 必須儲存以後才能生效,w為儲存並退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.3.4 第二步 格式化建立檔案系統
mkfs ==make filesystem即建立檔案系統。
[[email protected] ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0) #block的大小
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25896 inodes, 103424 blocks #inode與block的數量
5171 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1992 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3.3.5 第三步 關閉分割槽的自我檢查
tune2fs 命令
-c 掛載多少次 0 為關閉
-i 隔多長時間 0 為關閉
[[email protected] ~]# tune2fs -c 0 -i 0 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
3.3.6 第四步 掛載磁碟
[[email protected] ~]# mount /dev/sdb1 /mnt/
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.9G 6.5G 23% /
tmpfs 238M 0 238M 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sdb1 94M 1.6M 88M 2% /mnt
3.3.7 第五步 讓磁碟永久掛載 開機自動掛載
兩個檔案可以實現:
/etc/rc.local
/etc/fstab
在/etc/rc.local檔案中,寫入什麼命令都可以執行。
3.3.8 /etc/fstab 檔案的內容
[[email protected] ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Aug 10 18:33:48 2017
#
# 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=49bad9e9-cf33-4a15-ba84-4fd28e70bd29 / ext4 defaults 1 1
UUID=7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8 /boot ext4 defaults 1 2
UUID=46bc0a52-b13f-4845-8baa-90207849d5c5 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
磁碟分割槽裝置 掛載點 檔案系統的型別 掛載引數 是否進行dump備份 是否進行fsk磁碟檢查
3.3.9 將掛載資訊寫入配置檔案
[[email protected] ~]# tail -1 /etc/fstab
/dev/sdb1 /mnt ext4 defaults 0 0
3.3.10 顯示系統中的uuid
使用blkid 命令可以檢視系統磁碟的uuid
[[email protected] ~]# blkid
/dev/sda3: UUID="49bad9e9-cf33-4a15-ba84-4fd28e70bd29" TYPE="ext4"
/dev/sda1: UUID="7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8" TYPE="ext4"
/dev/sda2: UUID="46bc0a52-b13f-4845-8baa-90207849d5c5" TYPE="swap"
/dev/sdb1: UUID="7101630b-b325-49d1-92b9-0a500c2a07f6" TYPE="ext4"
3.4 在掛載磁碟的時候出現未格式化錯誤
對磁碟進行一些操作的時候可能會提示沒有格式化磁碟,需要格式化。
[[email protected] ~]# tune2fs -c0 -i0 /dev/sdc
tune2fs 1.41.12 (17-May-2010)
tune2fs: Bad magic number in super-block while trying to open /dev/sdc
Couldn't find valid filesystem superblock.
沒有找到可用的檔案系統
作者: 慘綠少年出處: http://clsn.io
第1章 RAID 磁碟陣列
1.1 使用raid的目的
1)獲得更大的容量
2)讓資料更安全
3)讀寫速度更快
1.2 raid0、raid1、raid5、raid10對比
raid型別 |
數量 |
優點 |
缺點 |
使用型別 |
raid0 條帶 |
至少1塊硬碟。 |
把所有硬碟的容量加在一起,讀寫速度更快 |
一塊硬碟損壞,整體都不能使用 |
資料不是很重要,追求效能 資料庫的從庫 叢集的某個節點 |
raid1 映象 |
只能是兩塊硬碟 |
安全,有100%的冗餘 |
寫入速度比較慢 讀取還可以 成本較高 |
對資料安全要求比較高,不需要太多的效能 |
raid5 |
至少三塊硬碟 |
有奇偶校驗,有一定的冗餘,最多損壞1塊硬碟 損失一塊硬碟的容量 |
讀取效能可以 寫入很慢 |
比較通用。 +spare 可以作為熱備 |
raid10 |
最少4塊硬碟 數量必須是偶數 |
讀寫的速度都很快,安全性較高冗餘,最多可以損壞一半 |
成本高 容量浪費一半 |
資料庫 重要的檔案 |
第2章 磁碟分割槽
2.1 mbr是什麼
mbr引導:主引導記錄
2.1.1 mbr在哪裡
磁碟的0磁頭 0磁軌 1扇區 前446位元組
一個扇區的大小為512位元組
前446位元組 mbr
中間64位元組 分割槽表
最後2位元組 分割槽結束表示55AA
2.1.2 分割槽表
在分割槽表的64位元組裡,劃分為4個格子 16*4
每個格子裡存放的是分割槽的資訊(主分割槽 擴充套件分割槽)
2.1.3 如何檢視磁碟第一個扇區裡的內容
拿出出來前512個位元組
[[email protected] ~]# dd if=/dev/sda of=/tmp/512.bin bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000190527 s, 2.7 MB/s
看下檔案的型別
[[email protected] ~]# file /tmp/512.bin
/tmp/512.bin: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x6280, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 409600 sectors; partition 2: ID=0x82, starthead 159, startsector 411648, 1572864 sectors; partition 3: ID=0x83, starthead 135, startsector 1984512, 18987008 sectors, code offset 0x48
2.1.4 如何檢視二進位制檔案的內容
od命令檢視二進位制檔案的內容
[[email protected] ~]# od -xa /tmp/512.bin
……
0000760 0000 0000 0000 0000 0000 0000 0000 aa55 結束識別符號
nul nul nul nul nul nul nul nul nul nul nul nul nul nul U *
0001000
2.2 主分割槽、擴充套件分割槽、邏輯分割槽的關係
2.2.1 主分割槽
最多有4個主分割槽
2.2.2 擴充套件分割槽
沒有辦法直接使用 ,需要劃分成邏輯分割槽才可以使用。
2.2.3 邏輯分割槽
必須要在擴充套件分割槽下面劃分邏輯分割槽才可以使用。
邏輯分割槽
sas/sata/scsi/ 中為 sda 5-15
2.3 在系統中磁碟分割槽的命名
磁碟裝置都放在/dev/目錄下
sas/sata/scsi/介面 sd 開頭
ide 介面 hd開頭
2.3.1 磁碟名稱示例
第一塊硬碟 sda
第二塊硬碟 sdb
第三塊硬碟 sdc
2.3.2 第一塊硬碟 sda
主分割槽 1-4
擴充套件分割槽 1-4 一般為4
邏輯分割槽 從5+開始
2.3.3 分割槽的命名規則
第一塊硬碟的第一個主分割槽:sda1
第一塊硬碟的第一個邏輯分割槽:sda5
第二塊硬碟的第二個邏輯分割槽:sdb6
2.4 回顧分割槽方式
2.4.1 沒有重要資料
/boot 200M 存放系統的引導資訊 核心
swap 交換分割槽 防止記憶體用光了 臨時的一個記憶體
如果你的記憶體小於8G swap是記憶體的1.5倍 如果你的記憶體大於8G swap給8G
/ 根分割槽 剩餘多少給多少
2.4.2 很多重要資料
/boot 200M 存放系統的引導資訊 核心
swap 交換分割槽 防止記憶體用光了 臨時的一個記憶體
如果你的記憶體小於8G swap是記憶體的1.5倍 如果你的記憶體大於8G swap給8G
/ 根分割槽 20G-200G
/data 存放重要的資料 剩餘多少給多少
2.4.3 不知道資料是否重要
/boot 200M 存放系統的引導資訊 核心
swap 交換分割槽 防止記憶體用光了 臨時的一個記憶體
如果你的記憶體小於8G swap是記憶體的1.5倍 如果你的記憶體大於8G swap給8G
/ 根分割槽 20G-200G
剩餘空間不分 放著誰使用這臺伺服器誰來分割槽
2.5 ps 命令內容詳解--每列的含義
2.5.1 ps aux 中的vsz與rss
[[email protected] shm]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 19352 1300 ? Ss Sep14 0:01 /sbin/ini
使用者 程序號 CPU 記憶體
⚠VSZ 程序所佔用的虛擬記憶體的大小(實體記憶體+swap)
⚠RSS 程序所佔用的記憶體(實體記憶體)
2.5.2 ps -ef 列含義系簡介
[[email protected] shm]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Sep14 ? 00:00:01 /sbin/init
使用者名稱 程序號 子程序號 運行了什麼命令
第3章 磁碟分割槽
3.1 linux裡面的分割槽工具
fdisk 主要是給磁碟小於2T(只能出來分割槽表是mbr的)
parted 主要是給磁碟大於2T(gpt)
3.2 通過fdisk給磁碟進行分割槽(建立一個10M主分割槽和一個40M邏輯分割槽)
3.2.1 使用fdisk會提示一個錯誤
[[email protected] ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x31dcd35a.
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)
警告 : 可以關閉dos的相容模式,使用扇區作為分割槽的預設單位 -cu ↓
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help):
3.2.2 fdisk新增上了 -cu 引數
-cu 引數是在分割槽的時候,能夠以扇區的方式進行。
[[email protected] ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb9f506a4.
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)
Command (m for help):
3.2.3 檢視fdisk的幫助資訊
Command (m for help): m
Command action
d delete a partition 刪除一個分割槽
m print this menu 顯示幫助選單
n add a new partition 建立一個分割槽
p print the partition table 顯示分割槽表
q quit without saving changes 退出不儲存
w write table to disk and exit 儲存並退出
3.2.4 建立一個主分割槽
Command (m for help): n
Command action
e extended 擴充套件分割槽
p primary partition (1-4) 主分割槽
p
Partition number (1-4): 1 第一個分割槽
First sector (2048-208895, default 2048): 直接回車為預設
Using default value 2048 預設選擇第一個扇區
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): +10M
3.2.5 顯示一下分出來的分割槽
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83
3.2.6 建立一個擴充套件分割槽
擴充套件分割槽的分割槽原則是:剩多少給多少
Command (m for help): n
Command action
e extended 擴充套件分割槽
p primary partition (1-4)
e
Partition number (1-4): 2
First sector (22528-208895, default 22528):
Using default value 22528
Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895):
Using default value 208895
3.2.7 顯示現在的分割槽表資訊
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 208895 93184 5 Extended
3.2.8 在拓展分割槽下建立邏輯分割槽
Command (m for help): n
Command action
l logical (5 or over) 邏輯分割槽,建立完擴充套件分割槽後只能建立邏輯分割槽
p primary partition (1-4)
l
First sector (24576-208895, default 24576):
Using default value 24576
Last sector, +sectors or +size{K,M,G} (24576-208895, default 208895): +40M
3.2.9 顯示一下當前的分割槽表
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 208895 93184 5 Extended
/dev/sdb5 24576 106495 40960 83 Linux
3.2.10 儲存並退出
fdisk 必須儲存以後才能生效,w為儲存並退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.3 【示例】新增一塊硬碟sdb 100m劃分一個分割槽 ,掛載到/mnt目錄
3.3.1 第一步 建立一個主分割槽
[[email protected] ~]# fdisk -cu /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-208895, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):
Using default value 208895
都選擇預設就是使用整塊盤的空間建立一個分割槽
3.3.2 顯示當前的分割槽表
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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 identifier: 0xb9f506a4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 208895 103424 83 Linux
3.3.3 儲存並退出
fdisk 必須儲存以後才能生效,w為儲存並退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.3.4 第二步 格式化建立檔案系統
mkfs ==make filesystem即建立檔案系統。
[[email protected] ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0) #block的大小
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25896 inodes, 103424 blocks #inode與block的數量
5171 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1992 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3.3.5 第三步 關閉分割槽的自我檢查
tune2fs 命令
-c 掛載多少次 0 為關閉
-i 隔多長時間 0 為關閉
[[email protected] ~]# tune2fs -c 0 -i 0 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
3.3.6 第四步 掛載磁碟
[[email protected] ~]# mount /dev/sdb1 /mnt/
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 8.8G 1.9G 6.5G 23% /
tmpfs 238M 0 238M 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sdb1 94M 1.6M 88M 2% /mnt
3.3.7 第五步 讓磁碟永久掛載 開機自動掛載
兩個檔案可以實現:
/etc/rc.local
/etc/fstab
在/etc/rc.local檔案中,寫入什麼命令都可以執行。
3.3.8 /etc/fstab 檔案的內容
[[email protected] ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Aug 10 18:33:48 2017
#
# 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=49bad9e9-cf33-4a15-ba84-4fd28e70bd29 / ext4 defaults 1 1
UUID=7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8 /boot ext4 defaults 1 2
UUID=46bc0a52-b13f-4845-8baa-90207849d5c5 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
磁碟分割槽裝置 掛載點 檔案系統的型別 掛載引數 是否進行dump備份 是否進行fsk磁碟檢查
3.3.9 將掛載資訊寫入配置檔案
[[email protected] ~]# tail -1 /etc/fstab
/dev/sdb1 /mnt ext4 defaults 0 0
3.3.10 顯示系統中的uuid
使用blkid 命令可以檢視系統磁碟的uuid
[[email protected] ~]# blkid
/dev/sda3: UUID="49bad9e9-cf33-4a15-ba84-4fd28e70bd29" TYPE="ext4"
/dev/sda1: UUID="7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8" TYPE="ext4"
/dev/sda2: UUID="46bc0a52-b13f-4845-8baa-90207849d5c5" TYPE="swap"
/dev/sdb1: UUID="7101630b-b325-49d1-92b9-0a500c2a07f6" TYPE="ext4"
3.4 在掛載磁碟的時候出現未格式化錯誤
對磁碟進行一些操作的時候可能會提示沒有格式化磁碟,需要格式化。
[[email protected] ~]# tune2fs -c0 -i0 /dev/sdc
tune2fs 1.41.12 (17-May-2010)
tune2fs: Bad magic number in super-block while trying to open /dev/sdc
Couldn't find valid filesystem superblock.
沒有找到可用的檔案系統