首页 系统教程 操作系统 Linux系统磁盘详解

Linux系统磁盘详解

May 02, 2024 pm 04:31 PM
linux centos linux教程 红帽 linux系统 linux命令 linux认证 红帽linux linux视频

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中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
威尔R.E.P.O.有交叉游戏吗?
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

centos和ubuntu的区别 centos和ubuntu的区别 Apr 14, 2025 pm 09:09 PM

CentOS 和 Ubuntu 的关键差异在于:起源(CentOS 源自 Red Hat,面向企业;Ubuntu 源自 Debian,面向个人)、包管理(CentOS 使用 yum,注重稳定;Ubuntu 使用 apt,更新频率高)、支持周期(CentOS 提供 10 年支持,Ubuntu 提供 5 年 LTS 支持)、社区支持(CentOS 侧重稳定,Ubuntu 提供广泛教程和文档)、用途(CentOS 偏向服务器,Ubuntu 适用于服务器和桌面),其他差异包括安装精简度(CentOS 精

centos如何安装 centos如何安装 Apr 14, 2025 pm 09:03 PM

CentOS 安装步骤:下载 ISO 映像并刻录可引导媒体;启动并选择安装源;选择语言和键盘布局;配置网络;分区硬盘;设置系统时钟;创建 root 用户;选择软件包;开始安装;安装完成后重启并从硬盘启动。

Centos停止维护后的选择 Centos停止维护后的选择 Apr 14, 2025 pm 08:51 PM

CentOS 已停止维护,替代选择包括:1. Rocky Linux(兼容性最佳);2. AlmaLinux(与 CentOS 兼容);3. Ubuntu Server(需要配置);4. Red Hat Enterprise Linux(商业版,付费许可);5. Oracle Linux(与 CentOS 和 RHEL 兼容)。在迁移时,考虑因素有:兼容性、可用性、支持、成本和社区支持。

docker desktop怎么用 docker desktop怎么用 Apr 15, 2025 am 11:45 AM

如何使用 Docker Desktop?Docker Desktop 是一款工具,用于在本地机器上运行 Docker 容器。其使用步骤包括:1. 安装 Docker Desktop;2. 启动 Docker Desktop;3. 创建 Docker 镜像(使用 Dockerfile);4. 构建 Docker 镜像(使用 docker build);5. 运行 Docker 容器(使用 docker run)。

docker原理详解 docker原理详解 Apr 14, 2025 pm 11:57 PM

Docker利用Linux内核特性,提供高效、隔离的应用运行环境。其工作原理如下:1. 镜像作为只读模板,包含运行应用所需的一切;2. 联合文件系统(UnionFS)层叠多个文件系统,只存储差异部分,节省空间并加快速度;3. 守护进程管理镜像和容器,客户端用于交互;4. Namespaces和cgroups实现容器隔离和资源限制;5. 多种网络模式支持容器互联。理解这些核心概念,才能更好地利用Docker。

docker镜像失败怎么办 docker镜像失败怎么办 Apr 15, 2025 am 11:21 AM

Docker镜像构建失败的故障排除步骤:检查Dockerfile语法和依赖项版本。检查构建上下文中是否包含所需源代码和依赖项。查看构建日志以获取错误详细信息。使用--target选项构建分层阶段以识别失败点。确保使用最新版本的Docker引擎。使用--t [image-name]:debug模式构建镜像以调试问题。检查磁盘空间并确保足够。禁用SELinux以防止干扰构建过程。向社区平台寻求帮助,提供Dockerfile和构建日志描述以获得更具体的建议。

vscode需要什么电脑配置 vscode需要什么电脑配置 Apr 15, 2025 pm 09:48 PM

VS Code 系统要求:操作系统:Windows 10 及以上、macOS 10.12 及以上、Linux 发行版处理器:最低 1.6 GHz,推荐 2.0 GHz 及以上内存:最低 512 MB,推荐 4 GB 及以上存储空间:最低 250 MB,推荐 1 GB 及以上其他要求:稳定网络连接,Xorg/Wayland(Linux)

centos停止维护后怎么办 centos停止维护后怎么办 Apr 14, 2025 pm 08:48 PM

CentOS 停止维护后,用户可以采取以下措施应对:选择兼容发行版:如 AlmaLinux、Rocky Linux、CentOS Stream。迁移到商业发行版:如 Red Hat Enterprise Linux、Oracle Linux。升级到 CentOS 9 Stream:滚动发行版,提供最新技术。选择其他 Linux 发行版:如 Ubuntu、Debian。评估容器、虚拟机或云平台等其他选项。

See all articles