0

0

linux 系统分区 格式化及挂载磁盘

WBOY

WBOY

发布时间:2024-07-24 18:34:22

|

337人浏览过

|

来源于Linux就该这么学

转载

服务器安装centos的时候,通常linux系统分区默认为3个分区,主分区最多4个,其他可根据自己的需要挂载。

linux 系统分区 格式化及挂载磁盘

/ 根分区,通常10-100G左右(根据总磁盘大小情况)

/boot 系统操作分区 (100-500MB 足矣)

/swap 虚拟内存暂存分区(通常是内存的2倍)

如果有剩下的磁盘就保留,后期再挂载。安装完系统后就开始格式化剩下的分区,并挂载指派出来。

1、首先查看未指派的分区名称,有的不一样,我的分别是/dev/sda和/dev/sdb,sda是系统分区,sdb是存储数据分区。

# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x00043041

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

2、可以看到红色标注的是10G的数据磁盘,我们现在执行分区,代码如下:

koly.club
koly.club

一站式社群管理工具

下载
# fdisk -S 56 /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x52d681d6.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help):【输入n回车,添加新分区,如果需要更多,请输入m回车看帮助】

Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):【输入p回车,P的意思是主分区】
Partition number (1-4, default 1):【输入数字1回车,分区数量】
First sector (2048-20971519, default 2048):【默认回车】
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):【默认回车】
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help):【输入wq保存】

The partition table has been altered!

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

3、分区完成。输入fdisk -l查看信息

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x00043041

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x52d681d6

Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 83 Linux

Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

4、可以查看/dev/sdb1已经被默认分区,现在开始格式化此分区。

注意:以下有几种常用磁盘格式,如果你想格式化ext3格式,代码如下;

# mkfs.ext3 /dev/sdb1

格式化ext4格式,代码如下;

# mkfs.ext4 /dev/sdb1

我这里采用的是xfs磁盘格式;代码如下;

# mkfs.xfs -f /dev/sdb1

meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655296 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

5、已经格式化成功。将磁盘挂载信息写入到系统配置文件中,不然开机不会自动挂载,代码如下;

# echo ‘/dev/sdb1 /www xfs defaults 0 0’ >> /etc/fstab
# mkdir /www //新建挂载目录
# mount -a //挂载磁盘
# df -h //查看挂载是否成功

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 8.0G 3.1G 5.0G 39% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 916M 0 916M 0% /dev/shm
tmpfs 916M 8.3M 908M 1% /run
tmpfs 916M 0 916M 0% /sys/fs/cgroup
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 184M 0 184M 0% /run/user/0
/dev/sdb1 10G 33M 10G 1% /www

6、可以看到www目录已经挂载成功。

扩展阅读,fdisk -S 56 /dev/sdb的时候输入m有帮助信息,下面就列举说明:

a、toggle a bootable flag //切换一个可启动的标志
b、 edit bsd disklabel //编辑bsd disklabel
c、 toggle the dos compatibility flag //切换dos兼容性模式
d、 delete a partition //删除一个分区
g、 create a new empty GPT partition table //创建一个新的空GPT分区表
G 、create an IRIX (SGI) partition table //创建一个IRIX(SGI)分区表
l 、list known partition types //列出已知的分区类型
m、 print this menu //打印此菜单
n、 add a new partition //添加一个新的分区
o、 create a new empty DOS partition table //创建一个新的空DOS分区表
p、 print the partition table //打印分区表
q、 quit without saving changes //退出而不保存更改
s、 create a new empty Sun disklabel //创建一个新的空的Sun磁盘标签
t、 change a partition’s system id //更改分区的系统ID
u、 change display/entry units //更改显示/输入单位
v、 verify the partition table //验证分区表
w、 write table to disk and exit //将表写入磁盘保存并退出
x、extra functionality (experts only) //高级功能(仅限专家)

相关专题

更多
磁盘配额是什么
磁盘配额是什么

磁盘配额是计算机中指定磁盘的储存限制,就是管理员可以为用户所能使用的磁盘空间进行配额限制,每一用户只能使用最大配额范围内的磁盘空间。php中文网为大家提供各种磁盘配额相关的内容,教程,供大家免费下载安装。

1353

2023.06.21

如何安装LINUX
如何安装LINUX

本站专题提供如何安装LINUX的相关教程文章,还有相关的下载、课程,大家可以免费体验。

704

2023.06.29

linux find
linux find

find是linux命令,它将档案系统内符合 expression 的档案列出来。可以指要档案的名称、类别、时间、大小、权限等不同资讯的组合,只有完全相符的才会被列出来。find根据下列规则判断 path 和 expression,在命令列上第一个 - ( ) , ! 之前的部分为 path,之后的是 expression。还有指DOS 命令 find,Excel 函数 find等。本站专题提供linux find相关教程文章,还有相关

294

2023.06.30

linux修改文件名
linux修改文件名

本专题为大家提供linux修改文件名相关的文章,这些文章可以帮助用户快速轻松地完成文件名的修改工作,大家可以免费体验。

777

2023.07.05

linux系统安装教程
linux系统安装教程

linux系统是一种可以免费使用,自由传播,多用户、多任务、多线程、多CPU的操作系统。本专题提供linux系统安装教程相关的文章,大家可以免费体验。

573

2023.07.06

linux查看文件夹大小
linux查看文件夹大小

Linux是一种自由和开放源码的类Unix操作系统,存在着许多不同的Linux版本,但它们都使用了Linux内核。Linux可安装在各种计算机硬件设备中,比如手机、平板电脑、路由器、视频游戏控制台、台式计算机、大型机和超级计算机。linux怎么查看文件夹大小呢?php中文网给大家带来了相关的教程以及文章,欢迎大家前来学习阅读。

547

2023.07.20

linux查看ip命令
linux查看ip命令

本专题为大家提供linux查看ip命令相关文章内容,感兴趣的朋友可以免费下载体验试试。

300

2023.07.20

linux查看cpu使用率
linux查看cpu使用率

在linux的系统维护中,可能需要经常查看cpu使用率,分析系统整体的运行情况。本专题为大家带来了linux查看cpu使用率的相关文章,感兴趣的朋友千万不要错过了。

381

2023.07.25

c++空格相关教程合集
c++空格相关教程合集

本专题整合了c++空格相关教程,阅读专题下面的文章了解更多详细内容。

0

2026.01.23

热门下载

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

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
PostgreSQL 教程
PostgreSQL 教程

共48课时 | 7.7万人学习

Git 教程
Git 教程

共21课时 | 2.9万人学习

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

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