1. 查看系统中硬盘的设备

[root@centos6 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb

可以看出,系统有两块硬盘,sda 与 sdb,sda有是三个分区。

2. 查看系统分区

[root@centos6 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 % /
tmpfs % /dev/shm
/dev/sda1 % /boot 或者:
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G .0G 13G % /
tmpfs 503M 72K 503M % /dev/shm
/dev/sda1 477M 32M 420M % /boot
[root@centos6 ~]#

注解:

1. 显示的只有sda硬盘的分区,因为sdb硬盘并没有分区且没有挂载到目录下。

2. 第一个命令df 显示一个 1K-blocks列,意思是,这个分区有多少个block块,一个block块是 8 * 521B,对于硬盘而言,最小单位是扇区,一个扇区是512个字节。块属于操作系统级别,操作系统在存储数据时,是一个块一个块的去存储。这样存储数据时效率高。

3. 硬盘分区

第一步:

[root@centos6 ~]# 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 0x0b37e823.
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 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):

第二步:选择 n

Command (m for help): n
Command action
e extended # 扩展分区
p primary partition (-) # 主分区

第三步:选择 创建 主分区(p)

p
Partition number (-):

第四步:输入分区编号 1

Partition number (-):
First cylinder (-, default ):

第五步:输入柱面 起始位置,默认为1, 默认即可,点击回车

First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):

第六步:输入柱面 结束位置,可以输入柱面结束位置,也可以输入分区大小,因为柱面之间的位置就是你的分区大小

输入 +5G

First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G

第七步:第一个分区,分区完成,按p查看

Command (m for help): p

Disk /dev/sdb: 21.5 GB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x1b5d0db0 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux Command (m for help):

继续输入 n 新建分区

Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-): 2 # 输入分区编码
First cylinder (-, default ): # 输入柱面起始位置,不用输入,直接回车,会接着上一个区分的最后柱面位置,继续排,如上面结束时654,这次开始是655

 Using default value 655

Last cylinder, +cylinders or +size{K,M,G} (-, default ): +5G   # 输入分区大小

Command (m for help): P    # 分区完成,按p查看

Disk /dev/sdb: 21.5 GB,  bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x1b5d0db0
Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux Command (m for help):

继续输入 n 再分一个分区

Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +5G Command (m for help): P Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x1b5d0db0 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux
/dev/sdb3 Linux

上面已经分了3个主分区,下面分一个逻辑分区

Command (m for help): n
Command action
e extended
p primary partition (-)
e # 输入e 创建扩展分区
Selected partition
First cylinder (-, default ): # 这里直接回车 回车,表示将剩余的空间,全部分给扩展分区。
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ):
Using default value Command (m for help): p Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x1b5d0db0 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux
/dev/sdb3 Linux
/dev/sdb4 Extended # 扩展区分 Command (m for help):

以上扩展分区创建完成,扩展分区是不能使用,即不能就进行文件存储,需要在扩展区分的基础上创建逻辑分区。

继续...

Command (m for help): n
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +1G Command (m for help): P Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x1b5d0db0 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux
/dev/sdb3 Linux
/dev/sdb4 Extended
/dev/sdb5 + Linux Command (m for help):

这里看一下,/dev/sdb5 这个分区的起始位置 是扩展分区起始位置一致,都为1963,因为扩展分区就是一个逻辑概念,不占用空间。

继续创建扩展分区

Command (m for help): n
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +1G Command (m for help): P Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x1b5d0db0 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux
/dev/sdb3 Linux
/dev/sdb4 Extended
/dev/sdb5 + Linux
/dev/sdb6 + Linux Command (m for help): /dev/sdb5

继续...

Command (m for help): n
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): # 直接回车 回车 将剩余的空间全部分给这个分区
Using default value Command (m for help): p Disk /dev/sdb: 21.5 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk identifier: 0x1b5d0db0 Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Linux
/dev/sdb3 Linux
/dev/sdb4 Extended
/dev/sdb5 + Linux
/dev/sdb6 + Linux
/dev/sdb7 + Linux Command (m for help):

第八步:分区完成之后 按 w 保存

Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

最后 输入命令:partprobe 跟新分区列表

[root@centos6 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (设备或资源忙). As a result, it may not reflect all of your changes until after reboot.
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
Error: 无效的分区表 - /dev/sr0 出现递归分区。
[root@centos6 ~]#

最后查看你的分区情况

如果不显示,重启系统

[root@centos6 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 /dev/sdb5 /dev/sdb6 /dev/sdb7

4. 格式化分区,制作文件系统

磁盘分区之后,并不能使用,需要将分区格式化,格式化的过程是为分区写入文件系统。

[root@centos6 ~]# mkfs.ext4 /dev/sdb3
mke2fs 1.41. (-May-)
文件系统标签=
操作系统:Linux
块大小= (log=)
分块大小= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
第一个数据块=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , 正在写入inode表: 完成
Creating journal ( blocks): 完成
Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@centos6 ~]#

将建的分区一 一格式化,扩展分区不需要格式化

5. 挂载

将格式化的分区挂载的目录下,分区才能被真正使用,进行文件读写。

挂载定义: 建立分区与目录映射关系的过程。

[root@centos6 /]# mount /dev/sdb2 /s2
[root@centos6 /]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 % /
tmpfs % /dev/shm
/dev/sda1 % /boot
/dev/sdb2 % /s2

卸载:

[root@centos6 /]# umount /s2
[root@centos6 /]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 % /
tmpfs % /dev/shm
/dev/sda1 % /boot
 umount -l /s2    # 强制卸载

6. 设置开始自动挂载

上面分区挂载到对应的目录下之后,如果系统重启,系统就会将挂载取消,因此可以设计开始时,自动挂载

vim /etc/fstab
在/etc/fstab 增加一行 /dev/sdb1 /test ext4 defaults

7. 思考

例如,

[root@centos6 /]# cd /opt
[root@centos6 opt]# ls
rh
[root@centos6 opt]# touch a.txt
[root@centos6 opt]# ls /opt
a.txt rh

touch a.txt 的过程,文件到底存放到哪去了?

系统会找其父目录opt有没有映射原设备,如果没有找opt的上一级目录 / 有没有源设备,而 / 挂载的 /dev/sda3 分区下,那么a.txt 就存放到 /dev/sda3 这个源设备下(分区)。看样子文件都存放在目录下,其实都是存放在目录对应的源设备下。

如果opt有源设备,那么文件就存放在opt对应的源设备下。

那么 ls /opt 显示的就是 optt对应的源设备下 或者 / 对应的源设备下的内容

linux 分区管理的更多相关文章

  1. 免费的 Linux 分区管理器使用介绍

    下面的列表没有特定的排名顺序.大多数分区工具应该存在于 Linux 发行版的仓库中. GParted 这可能是 Linux 发行版中最流行的基于 GUI 的分区管理器.你可能已在某些发行版中预装它.如 ...

  2. Linux 分区管理器

    下面的列表没有特定的排名顺序.大多数分区工具应该存在于 Linux 发行版的仓库中. GParted 这可能是 Linux 发行版中最流行的基于 GUI 的分区管理器.你可能已在某些发行版中预装它.如 ...

  3. Linux fdisk命令参数及用法详解---Linux磁盘分区管理命令fdisk

    fdisk 命令 linux磁盘分区管理 用途:观察硬盘之实体使用情形与分割硬盘用. 使用方法: 一.在 console 上输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形. 二.在 ...

  4. linux下fdisk分区管理、文件系统管理、挂载文件系统等

    分区管理工具有:fdisk, parted, sfdisk fdisk:对于一块硬盘来讲,最多只能管理15分区: # fdisk -l [-u] [device...]  查看硬盘设备分区信息 # f ...

  5. Linux 磁盘分区管理

    Linux 磁盘管理进阶 磁盘分区介绍 基本分区(primary partion) 基本分区也称主分区,引导分区.每块磁盘分区主分区与扩展分区加起来不能大于四个. 基本分区创建后可以立即使用,但是有分 ...

  6. linux磁盘管理与分区 转载

    原文:http://zhengjianglong.leanote.com/post/linux%E7%A3%81%E7%9B%98%E5%88%86%E5%8C%BA 一.基础知识 一块磁盘可以分为多 ...

  7. Linux 磁盘管理及分区

    硬盘结构和基础知识  扇区(Sector)为最小的物理储存单位,每个扇区为512 bytes,将扇区组成一个圆就是磁道(track),不同磁盘的相同磁道组成磁柱(Cylinder),磁柱是分区(par ...

  8. 3.Linux如何管理分区

    上一次谈完了硬盘与分区的基础知识,下面谈一下Linux如何管理分区. Linux管理硬件和windows完全不同.任何东西(包括硬件)在Linux看来都是文件设备,有字符和二进制形式的设备.如打印机. ...

  9. Linux磁盘分区管理

    1.分区步骤          fdisk -l                                  查看系统中的磁盘 fdisk /dev/vdb                   ...

随机推荐

  1. ubuntu 网卡名称重命名

    ubuntu 网卡名称重命名 参考:https://blog.csdn.net/hzj_001/article/details/81587824 biosdevname 和 net.ifnames 两 ...

  2. Windows+Nginx+Tomcat整合的安装与配置学习笔记

    以下全部是nginx在window7下运行的: nginx学习总结: 我的是放在F盘 1.启动:F:\nginx-1.10.2\nginx-1.10.2>start nginx.exe(找到相应 ...

  3. vue的使用与安装 npm -v报错

    1.先将node从官方文档下载下来,然后进行安装. 安装成功后,在dos命令中node -v.npm -v来测试,如果成功就可以安装cnpm(国内淘宝镜像比较快).这里我遇到一个bug,npm -v压 ...

  4. EBS常用表_Dictionary

    EBS常用表:转载于 https://blog.csdn.net/xiariqingcao/article/details/8775827 . OU.库存组织 SELECT hou.organizat ...

  5. Hive的日志操作

    想要看hive的日志,我们查看/home/hadoop/hive/conf/hive-log4j2.properties # list of properties property.hive.log. ...

  6. 【5】Zookeeper的ZAB协议

    一.ZAB协议(原子消息广播协议)   ZAB(Zookeeper Atomic Broadcast)协议是Zookeeper用来保证其数据一致性的核心算法,是一种支持崩溃恢复的原子广播协议.基于此协 ...

  7. 蓝牙App漏洞系列分析之二CVE-2017-0639

    蓝牙App漏洞系列分析之二CVE-2017-0639 0x01 漏洞简介 Android本月的安全公告,修复了我们发现的另一个蓝牙App信息泄露漏洞,该漏洞允许攻击者获取 bluetooth用户所拥有 ...

  8. Oracle【多表查询操作(SQL92&SQL99)】

    多表联合查询:需要获取的数据分布在多张表中 SQL92: --笛卡尔积:将多个表的数据进行一一对应,所得的结果为多表的笛卡尔积 select * from emp; select * from dep ...

  9. Hive压缩和存储(十二)

    压缩和存储 1. Hadoop压缩配置 1) MR支持的压缩编码 压缩格式 工具 算法 文件扩展名 是否可切分 DEFAULT 无 DEFAULT .deflate 否 Gzip gzip DEFAU ...

  10. 编译TensorFlow-serving GPU版本

    编译TensorFlow-serving GPU版本 TensorFlow Serving 介绍 编译GPU版本 下载源码 git clone https://github.com/tensorflo ...