0

0

详解:Linux 硬盘,格式化,分区 详解

碧海醫心

碧海醫心

发布时间:2025-02-22 17:30:10

|

893人浏览过

|

来源于Linux就该这么学

转载

disk是linux自带的硬盘分区工具,可以对硬盘进行分区,或者对硬盘分区进行调整。

首先选择要进行操作的磁盘

[root@linuxidc ~]# fdisk /dev/sdb

输入m,列出可以执行的命令

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)

输入p,列出磁盘目前的分区情况

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
 255 heads, 63 sectors/track, 391 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
 /dev/sdb1 1 1 8001 8e Linux LVM
 /dev/sdb2 2 26 200812+ 83 Linux

输入d,然后选择分区,删除现有分区

Command (m for help): d
 Partition number (1-4): 1

Command (m for help): d
 Selected partition 2

查看分区情况,确认分区已经删除

Command (m for help): print

Disk /dev/sdb: 3221 MB, 3221225472 bytes
 255 heads, 63 sectors/track, 391 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help):

输入n,建立新的磁盘分区,首先建立两个主磁盘分区

Command (m for help): n
 Command action
 e extended
 p primary partition (1-4)
 p //建立主分区
Partition number (1-4): 1 //分区号
First cylinder (1-391, default 1): //分区起始位置
Using default value 1
 Last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区

Command (m for help): n //再建立一个分区
Command action
 e extended
 p primary partition (1-4)
 p 
 Partition number (1-4): 2 //分区号为2
 First cylinder (101-391, default 101): 
 Using default value 101
 Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M

确认分区建立成功

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
 255 heads, 63 sectors/track, 391 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
 /dev/sdb1 1 100 803218+ 83 Linux
 /dev/sdb2 101 125 200812+ 83 Linux

再建立一个逻辑分区

Command (m for help): n
 Command action
 e extended
 p primary partition (1-4)
 e //选择扩展分区
Partition number (1-4): 3
 First cylinder (126-391, default 126): 
 Using default value 126
 Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): 
 Using default value 391

确认扩展分区建立成功

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
 255 heads, 63 sectors/track, 391 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
 /dev/sdb1 1 100 803218+ 83 Linux
 /dev/sdb2 101 125 200812+ 83 Linux
/dev/sdb3 126 391 2136645 5 Extended

在扩展分区上建立两个逻辑分区

Command (m for help): n
 Command action
 l logical (5 or over)
 p primary partition (1-4)
 l //选择逻辑分区
First cylinder (126-391, default 126): 
 Using default value 126
 Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M

Command (m for help): n
 Command action
 l logical (5 or over)
 p primary partition (1-4)
 l
 First cylinder (176-391, default 176): 
 Using default value 176
 Last cylinder or +size or +sizeM or +sizeK (176-391, default 391): 
 Using default value 391

确认逻辑分区建立成功

Win32 API函数手册 chm版
Win32 API函数手册 chm版

Win32_API_函数详解查询手册 chm格式,分为限制程序功能函数、注册表处理函数、对话框函数、时间处理函数、磁盘处理函数、进程函数、文件处理函数、断点设置列表等相关内容。

下载
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
 255 heads, 63 sectors/track, 391 cylinders
 Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
 /dev/sdb1 1 100 803218+ 83 Linux
 /dev/sdb2 101 125 200812+ 83 Linux
 /dev/sdb3 126 391 2136645 5 Extended
 /dev/sdb5 126 175 401593+ 83 Linux
 /dev/sdb6 176 391 1734988+ 83 Linux

Command (m for help):

从上面的结果我们可以看到,在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6)

注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。

最后对分区操作进行保存

Command (m for help): w
 The partition table has been altered!

Calling ioctl() to re-read partition table.
 Syncing disks.

建立好分区之后我们还需要对分区进行格式化才能在系统中使用磁盘。

在sdb1上建立ext2分区

[root@linuxidc ~]# mkfs.ext2 /dev/sdb1
mke2fs 1.39 (29-May-2006)
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 100576 inodes, 200804 blocks
 10040 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem blocks=209715200
 7 block groups
 32768 blocks per group, 32768 fragments per group
 14368 inodes per group
 Superblock backups stored on blocks: 
 32768, 98304, 163840

Writing inode tables: done 
 Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
 180 days, whichever comes first. Use tune2fs -c or -i to override.

在sdb6上建立ext3分区

[root@linuxidc ~]# mkfs.ext3 /dev/sdb6
 mke2fs 1.39 (29-May-2006)
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 217280 inodes, 433747 blocks
 21687 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem blocks=444596224
 14 block groups
 32768 blocks per group, 32768 fragments per group
 15520 inodes per group
 Superblock backups stored on blocks: 
 32768, 98304, 163840, 229376, 294912

Writing inode tables: done 
 Creating journal (8192 blocks): done
 Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
 180 days, whichever comes first. Use tune2fs -c or -i to override.
 [root@linuxidc ~]#

建立两个目录/Oracle和/web,将新建好的两个分区挂载到系统

[root@linuxidc ~]# mkdir /oracle
 [root@linuxidc ~]# mkdir /web
 [root@linuxidc ~]# mount /dev/sdb1 /oracle
 [root@linuxidc ~]# mount /dev/sdb6 /web

查看分区挂载情况

[root@linuxidc ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
 6.7G 2.8G 3.6G 44% /
 /dev/sda1 99M 12M 82M 13% /boot
 tmpfs 125M 0 125M 0% /dev/shm
/dev/sdb1 773M 808K 733M 1% /oracle
 /dev/sdb6 1.7G 35M 1.6G 3% /web

如果需要每次开机自动挂载则需要修改/etc/fstab文件,加入两行配置

[root@linuxidc ~]# vim /etc/fstab

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
 LABEL=/boot /boot ext3 defaults 1 2
 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
 /dev/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/sdb1 /oracle ext2 defaults 0 0
 /dev/sdb6 /web ext3 defaults 0 0

相关专题

更多
oracle清空表数据
oracle清空表数据

当表中的数据不需要时,则应该删除该数据并释放所占用的空间。本专题为大家提供oracle清空表数据的相关文章,帮助大家解决该问题。

263

2023.08.16

Oracle中declare的使用
Oracle中declare的使用

Oracle DECLARE语句是PL/SQL编程语言中用于声明变量、常量、游标或异常的关键字。它的主要作用是在程序中定义这些对象,以便在后续的代码中使用。DECLARE语句的语法简单明了,可以根据需要声明多个对象。通过使用这些声明的对象,可以进行各种操作,如计算、查询数据库、处理异常等 。

200

2023.09.15

oracle怎么分页
oracle怎么分页

实现分页的步骤:1、使用ROWNUM进行分页查询;2、在执行查询之前进行设置分页参数;3、使用"COUNT(*)"函数来获取总行数,并使用"CEIL"函数来向上取整计算总页数;4、在外部查询中使用"WHERE"子句来筛选出特定的行号范围,以实现分页查询。想了解更多oracle怎么分页的文章,可以来阅读本专题先的文章。

233

2023.09.18

Oracle查看表操作历史记录
Oracle查看表操作历史记录

查看操作历史记录的方法:1、使用Oracle内置的审计功能,可以记录数据库中发生的各种操作,包括登录、DDL语句、DML语句等;2、使用Oracle日志文件,其中包含了数据库中发生的各种操作,可以通过查看日志文件来获取操作历史记录;3、使用Oracle的Flashback功能,可以查看数据库在某个时间点的操作历史记录;4、使用第三方工具等。本专题还提供其他查看表操作的文章,大家可以免费阅读。

445

2023.09.19

Oracle中RAC的用法
Oracle中RAC的用法

Oracle中RAC的用法:1、通过在多个服务器上运行数据库实例来提供高可用性;2、允许在需要时增加或减少节点数量;3、通过将工作负载分布到多个节点上来实现负载均衡;4、使用共享存储来实现多个节点之间的数据共享;5、允许多个节点同时处理数据库请求,从而实现并行处理;6、提供了透明故障切换功能;7、使用了一些技术来确保数据的一致性;8、提供了管理工具来简化RAC环境的管理和维护。本专题还提供RAC相关的其他文章,大家可以免费阅读。

436

2023.09.19

oracle imp
oracle imp

imp是Oracle数据库中的一个命令行工具,用于将导出的数据和对象从一个数据库实例导入到另一个数据库实例。imp命令的一般语法为“imp username/password@connect_string file=file_name [options]”。

312

2023.09.19

常用的数据库软件
常用的数据库软件

常用的数据库软件有MySQL、Oracle、SQL Server、PostgreSQL、MongoDB、Redis、Cassandra、Hadoop、Spark和Amazon DynamoDB。更多关于数据库软件的内容详情请看本专题下面的文章。php中文网欢迎大家前来学习。

957

2023.11.02

oracle通配符有哪些
oracle通配符有哪些

oracle通配符有“%”、“_”、“[]”和“[^]"。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

162

2023.11.08

php源码安装教程大全
php源码安装教程大全

本专题整合了php源码安装教程,阅读专题下面的文章了解更多详细内容。

194

2025.12.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
jQuery  红蓝两方投票功能实战教程
jQuery 红蓝两方投票功能实战教程

共8课时 | 2.3万人学习

传智播客Swift基础视频教程
传智播客Swift基础视频教程

共40课时 | 7.8万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号