搜尋
首頁系統教程LinuxLinux系統磁碟詳解

Linux系統磁碟詳解

May 02, 2024 pm 04:31 PM
linuxcentoslinux教程紅帽linux系統linux指令linux認證紅帽linuxlinux視頻

1、磁碟分類

目前市面上的磁碟分類有:IDE磁碟(多用於PC機)、SATA磁碟、SAS磁碟、SSD磁碟等這麼多種分類,企業中伺服器大多為後面的兩種,SATA磁碟多用於企業內部的一些業務、SAS磁碟多用於對外的業務(一些業務平台)。

SATA磁碟目前容量最大為4T、SAS磁碟一般都在300G--600G居多,企業生產環境中使用也最多的是這種容量的,實際生產中磁碟的使用主要是看效能需求,也就是磁碟的讀寫速度。

2、磁碟的體系結構

企業級伺服器多區塊磁碟的狀況

Linux系統磁碟詳解

#3、磁碟容量的計算

磁碟的結構一般包括磁軌、碟面、磁區、碰頭等

一個磁軌的大小=512 位元組*磁區數

一個磁碟面的大小=磁軌的大小*磁軌數

一個磁碟的大小=磁碟面大小*磁頭數

因此,一個磁碟的容量=512 位元組*磁區數*磁軌數*磁頭數

Linux系統磁碟詳解

4、 磁碟分割區

#所有磁碟的分割資訊都是儲存在分割表中,Linux系統只支援4個分割區表格資訊(主分割區 擴充分割區),一個分割區表的大小在64bytes

Linux一般分為三個分區分別是:boot分區、swap分區、/根分區

Linux的分割區編號:主分割區1-4,邏輯分割區從5開始計算

實際生產環境分割區需求

1、 最少要有/和swap兩個分割區

2、 swap(虛擬記憶體)=1.5*實體記憶體大小,一般大小於或等於16G的實體記憶體的伺服器,swap分割區一般都直接設定為16G大小

3、建議設定/boot分區,Linux引導分區,如核心檔案等,一般所有檔案總共幾十M的大小,因此這個分割區就設定為100-200M即可

5、磁碟分割工具fdisk

fdisk是針對磁碟容量小於2T

[root@cairui ~]# fdisk --help
fdisk: invalid option -- '-'

fdisk: Usage:
fdisk [options] change partition table
fdisk [options] -l list partition table(s)
fdisk -s give partition size(s) in blocks

Options:
-b sector size (512, 1024, 2048 or 4096)
-c switch off DOS-compatible mode
-h print help
-u give sizes in sectors instead of cylinders
-v print version
-C specify the number of cylinders
-H specify the number of heads
-S specify the number of sectors per track

: Success

Linux系統磁碟詳解

#
[root@localhost ~]# fdisk /dev/sda1  #对/dev/sda1进行分区操作
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x02fadd9c.
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 to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): 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)
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 设置起始柱面
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
设置大小或柱面
Using default value 2610
Command (m for help): 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)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Command (m for help): p 打印分区表信息
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
121 / 753
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb712cc55
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
分区完成后执行 partprobe 通知系统分区表发生改变
接下来进行格式化分区
[root@Centos ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@Centos ~]# tune2fs -c -1 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
[root@Centos ~]# mount /dev/sdb1 /mnt 挂载分区至/mnt 下
[root@Centos ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 3.5G 44G 8% /
tmpfs 932M 0 932M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
122 / 753
/dev/mapper/VolGroup-lv_home 26G 215M 24G 1% /home
/dev/sdb1 20G 172M 19G 1% /mnt
6、磁碟分割工具parted

由於環境限制無法有2T或以上大小的磁碟,只能模擬環境來使用parted分割區工具來進行分割區

[root@Centos ~]# parted /dev/sdb mklabel gpt
将磁盘转换成 gpt 的格式
[root@Centos ~]# parted /dev/sdb mkpart primary 0 200(200M)
Warning: The resulting partition is not properly aligned for best
performance.
Ignore/Cancel? Ignore
[root@Centos ~]# parted /dev/sdb p 打印分区表信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 200MB 200MB primary
[root@Centos ~]# parted /dev/sdb mkpart primary 201 1073
分区并设置大小
Information: You may need to update /etc/fstab.
[root@Centos ~]# parted /dev/sdb p 打印分区表信息
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 200MB 200MB primary
2 201MB 1073MB 871MB primary
[root@Centos ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
123 / 753
Stride=0 blocks, Stripe width=0 blocks
48960 inodes, 195296 blocks
9764 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
24 block groups
8192 blocks per group, 8192 fragments per group
2040 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 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@Centos ~]# tune2fs -c -1 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
[root@Centos ~]# mount /dev/sdb1 /mnt
[root@Centos ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 3.5G 44G 8% /
tmpfs 932M 0 932M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 26G 215M 24G 1% /home
/dev/sdb1 185M 5.6M 170M 4% /mnt
[root@cairui ~]# parted --help
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE. If no COMMAND(s) are given, run in
interactive mode.

OPTIONs:
-h, --help displays this help message
-l, --list lists partition layout on all block devices
-m, --machine displays machine parseable output
-s, --script never prompts for user intervention
-v, --version displays the version
-a, --align=[none|cyl|min|opt] alignment for new partitions

COMMANDs:
align-check TYPE N check partition N for TYPE(min|opt)
alignment
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help, or help on
COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition
table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on
partition NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
move NUMBER START END move partition NUMBER
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table,
available devices, free space, all found partitions, or a particular
partition
quit exit program
rescue START END rescue a lost partition near START
and END
resize NUMBER START END resize partition NUMBER and its file
system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition
NUMBER
unit UNIT set the default unit to UNIT
version display the version number and
copyright information of GNU Parted

以上是Linux系統磁碟詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:Linux就该这么学。如有侵權,請聯絡admin@php.cn刪除
Linux軟件的未來:Flatpak和Snap會替換本機桌面應用程序嗎?Linux軟件的未來:Flatpak和Snap會替換本機桌面應用程序嗎?Apr 25, 2025 am 09:10 AM

多年來,Linux軟件分佈依賴於DEB和RPM等本地格式,並深深地根深蒂固。 但是,Flatpak和Snap已經出現,有望成為應用程序包裝的通用方法。 本文考試

Linux和Windows處理設備驅動程序的區別有什麼區別?Linux和Windows處理設備驅動程序的區別有什麼區別?Apr 25, 2025 am 12:13 AM

Linux和Windows在處理設備驅動程序上的差異主要體現在驅動管理的靈活性和開發環境上。 1.Linux採用模塊化設計,驅動可以動態加載和卸載,開發者需深入理解內核機制。 2.Windows依賴微軟生態,驅動需通過WDK開發並簽名認證,開發相對複雜但保證了系統的穩定性和安全性。

比較和對比Linux和Windows的安全模型。比較和對比Linux和Windows的安全模型。Apr 24, 2025 am 12:03 AM

Linux和Windows的安全模型各有優勢。 Linux提供靈活性和可定制性,通過用戶權限、文件系統權限和SELinux/AppArmor實現安全。 Windows則注重用戶友好性,依賴WindowsDefender、UAC、防火牆和BitLocker保障安全。

Linux和Windows之間的硬件兼容性有何不同?Linux和Windows之間的硬件兼容性有何不同?Apr 23, 2025 am 12:15 AM

Linux和Windows在硬件兼容性上不同:Windows有廣泛的驅動程序支持,Linux依賴社區和廠商。解決Linux兼容性問題可通過手動編譯驅動,如克隆RTL8188EU驅動倉庫、編譯和安裝;Windows用戶需管理驅動程序以優化性能。

Linux和Windows之間虛擬化支持有哪些差異?Linux和Windows之間虛擬化支持有哪些差異?Apr 22, 2025 pm 06:09 PM

Linux和Windows在虛擬化支持上的主要區別在於:1)Linux提供KVM和Xen,性能和靈活性突出,適合高定制環境;2)Windows通過Hyper-V支持虛擬化,界面友好,與Microsoft生態系統緊密集成,適合依賴Microsoft軟件的企業。

Linux系統管理員的主要任務是什麼?Linux系統管理員的主要任務是什麼?Apr 19, 2025 am 12:23 AM

Linux系統管理員的主要任務包括系統監控與性能調優、用戶管理、軟件包管理、安全管理與備份、故障排查與解決、性能優化與最佳實踐。 1.使用top、htop等工具監控系統性能,並進行調優。 2.通過useradd等命令管理用戶賬戶和權限。 3.利用apt、yum管理軟件包,確保系統更新和安全。 4.配置防火牆、監控日誌、進行數據備份以確保系統安全。 5.通過日誌分析和工具使用進行故障排查和解決。 6.優化內核參數和應用配置,遵循最佳實踐提升系統性能和穩定性。

很難學習Linux嗎?很難學習Linux嗎?Apr 18, 2025 am 12:23 AM

學習Linux並不難。 1.Linux是一個開源操作系統,基於Unix,廣泛應用於服務器、嵌入式系統和個人電腦。 2.理解文件系統和權限管理是關鍵,文件系統是層次化的,權限包括讀、寫和執行。 3.包管理系統如apt和dnf使得軟件管理方便。 4.進程管理通過ps和top命令實現。 5.從基本命令如mkdir、cd、touch和nano開始學習,再嘗試高級用法如shell腳本和文本處理。 6.常見錯誤如權限問題可以通過sudo和chmod解決。 7.性能優化建議包括使用htop監控資源、清理不必要文件和使用sy

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器