关于硬盘分区,这里先只讨论硬盘分区的方法在linux环境下,其他知识以后也会陆续说到

首先我们通过 df 命令查看一下硬盘的使用情况,在安装硬盘分区后做比较用

[root@bogon ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 16G .2G 13G % /
tmpfs 1012M 444K 1012M % /dev/shm
/dev/sda1 291M 29M 248M % /boot
/dev/sr1 .8G .8G % /media/RHEL_6. i386 Disc
/dev/sr0 45M 45M % /media/CDROM

我们再通过fdisk命令 查看一下硬盘的分区情况

[root@bogon ~]# fdisk -l

Disk /dev/sda: 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: 0x0008a5e5 Device Boot Start End Blocks Id System
/dev/sda1 * Linux
Partition does not end on cylinder boundary.
/dev/sda2 Linux
/dev/sda3 Linux swap / Solaris Disk /dev/sdb: 16.1 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: 0x00000000 Disk /dev/sdb doesn't contain a valid partition table

sda 表示已经完成分区并在使用,sdb表示尚未分区,也就是我们下边要进行的操作对象,dev表示硬盘

我们使用 fdisk 命令来对 的 sdb来进行分区

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

下面介绍一下 command (m for help): 常用的参数

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 /*保存退出,分区完成后一定要输入w,否则一切为空,回到解放前*/
x extra functionality (experts only)

我们先创建一个新的分区

Command (m for help): n
Command action
e extended /*代表扩展分区,但扩展分区不可以直接使用,需要分为逻辑分区后方可使用,逻辑分区从5开始*/
p primary partition (-) /*代表主分区,硬盘只能有四个主分区,从1-4 扩展分区也算一个主分区,主分区可以直接使用*/

先进行创建主分区

   p   primary partition (-)
p
Partition number (-): 1 /*表示盘符编码,1-4任意都可以,我们符合习惯从1开始*/
First cylinder (-, default ): 1 /*此处表示此分区的开始位置,我们假设a,a属于(1-1958) 可以直接回车,默认为1,我们同样从1开始,符合习惯*/
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +5G /*此处表示此分区的结束位置,我们假设为b b属于 (a+1 - 1958),此硬盘大小则为 b-a 或者更加便捷直接输入我们想要的硬盘大小,前加上 "+" 即可*/

到此处第一个主分区已经完成,我们可以通过 参数 p 来查看一下

Command (m for help): p

Disk /dev/sdb: 16.1 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: 0xe3b900aa Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
开始位置 结束位置 分区大小,单位是byte,小数点向前移动,三位,可以获得大致大小

可以看到,第一个分区已经完成,下边我们来分一个扩展分区,同样 先通过参数 n 创建一个新的分区

Command (m for help): n
Command action
e extended
p primary partition (-)

此时我们要进行的扩展分区,所以我们输入 参数  e

Command (m for help): n
Command action
e extended
p primary partition (-)
e
Partition number (-):
First cylinder (-, default ): 655 /*因为我们第一个分区占用了 (1- 654) ,所以此时默认从655开始 */
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +6G

此时扩展分区已经分区完成,同样的我们通过 参数 p来查看一下

Command (m for help): p

Disk /dev/sdb: 16.1 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: 0xe3b900aa Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Extended /*表示这是一个逻辑分区*/

扩展分区是不能直接使用的,我们必须把扩展分区分成逻辑分区后才可以使用,同样的我们 采用参数 n 创建一个新的分区

Command (m for help): n
Command action
l logical ( or over) /*此时可以发现,此处有Extended 变成了 logical 因为扩展分区只能存在一个,logical表示逻辑分区*/
p primary partition (-)

我们选择参数 l 分出逻辑分区

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

此时逻辑分区已经完成 ,同样的我们使用参数 p 来查看一下

Command (m for help): p

Disk /dev/sdb: 16.1 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: 0xe3b900aa Device Boot Start End Blocks Id System
/dev/sdb1 + Linux
/dev/sdb2 Extended
/dev/sdb5 Linux /*逻辑分区从5开始,1-4只能是主分区*/

这是分区已经完成,最后一步,参数 w 保存退出

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

硬盘完成分区之后,并不能直接使用,需要进行格式化以及挂载才能使用

格式化 我们采用 mkfs命令,简单介绍一下mkfs命令

    mkfs命令用于在设备上(通常为硬盘)创建Linux文件系统。mkfs本身并不执行建立文件系统的工作,而是去调用相关的程序来执行
mkfs (选项) (参数) mkfs:指定建立文件系统时的参数;
-t<文件系统类型>:指定要建立何种文件系统;
-v:显示版本信息与详细的使用方法;
-V:显示简要的使用方法;
-c:在制做档案系统前,检查该partition是否有坏轨

下面我们来进行格式化

[root@bogon ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@bogon ~]# mkfs -t ext4 /dev/sdb2
mke2fs 1.41. (-May-)
mkfs.ext4: inode_size () * inodes_count () too big for a
filesystem with blocks, specify higher inode_ratio (-i)
or lower inode count (-N). [root@bogon ~]# mkfs -t ext4 /dev/sdb5
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.

[root@bogon ~]# mkfs -t ext4 /dev/sdb2

格式化完成之后我们来进行硬盘的挂载

[root@bogon ~]# mkdir /tmp1
[root@bogon ~]# mkdir /tmp2
[root@bogon ~]# mount /dev/sdb1 /tmp1
[root@bogon ~]# mount /dev/sdb5 /tmp2

此时挂载完毕,我们来通过 df 命令来查看一下我们是否成功

[root@bogon ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 16G .2G 13G % /
tmpfs 1012M 444K 1012M % /dev/shm
/dev/sda1 291M 29M 248M % /boot
/dev/sr1 .8G .8G % /media/RHEL_6. i386 Disc
/dev/sr0 45M 45M % /media/CDROM
/dev/sdb1 .0G 139M .6G % /tmp1
/dev/sdb5 .0G 69M .8G % /tmp2

可以看到,我们已经完成了硬盘的分区以及格式化和挂载,但是由于linux的特殊性,若我们不把此分区写入配置文件,我们下次重启是,此分区是消失的

下面我们通过vim 将其写入配置文件

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

/dev/sdb1 /part1 ext4 defaults 0 0
/dev/sdb5 /part1 ext4 defaults 0 0
#
# /etc/fstab
# Created by anaconda on Wed Mar ::
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(), findfs(), mount() and/or blkid() for more info
#
UUID=93de9377-f280-4fad-959e-bfc88b5ffeff / ext4 defaults
UUID=d303ecd7-a97e-4dbe-a543-01b8db0362cc /boot ext4 defaults
UUID=5cb80a30-6c26-47d2-b82d-cef4de688119 swap swap defaults
tmpfs /dev/shm tmpfs defaults
devpts /dev/pts devpts gid=,mode=
sysfs /sys sysfs defaults
proc /proc proc defaults
~
~
~
~
~
~
~
"/etc/fstab" 17L, 842C , All

此时代表完成,输入wq保存退出即可

到此关于硬盘分区的操作到此结束,其他方面自己学习之后会再进行分享,谢谢大家

文中如有错误不足,希望大家多多包涵指正

Linux的硬盘分区的更多相关文章

  1. Linux下硬盘分区

    1  fdisk -l查看硬盘及分区信息 我的系统(Archlinux)下的命令效果如下: 由上面的图片可以得知该系统只挂载了1个硬盘,命名为sda,其有2个主分区,sda1和sda2,至于为什么这么 ...

  2. linux添加硬盘分区挂载教程

    基本步骤:分区--格式化--挂载--写入文件 1.首先用fdisk -l命令查看添加的硬盘名称,可以看到sdb为新增的硬盘 [root@oracle ~]# fdisk -l Disk /dev/sd ...

  3. linux挂载硬盘分区

    [转]https://www.jb51.net/article/138204.htm 基本步骤:分区——格式化——挂载——写入文件 1.使用fdisk    -l命令查看添加的硬盘名称,可以看到sdb ...

  4. Linux基础——硬盘分区、格式化及文件系统的管理

    1. 硬件设备与文件名的对应关系 掌握在Linux系统中,每个设备都被当初一个文件来对待. 设备 设备在Linux内的文件名 IDE硬盘 /dev/hd[a-d] SCSI硬盘 /dev/sd[a-p ...

  5. Linux常用硬盘分区工具简介

    1.fdisk 查看当前硬盘分区: [root@yqtrack-zabbix /]# fdisk -l 2.cfdisk 查看当前硬盘分区: 3.sfdisk 查看当前分区: 4.parted 查看当 ...

  6. linux中硬盘分区、格式化、挂载

    已经接触了小半年的linux,基本命令用的还行,就是涉及到深入操作,就显得不够看了,比如linux中的硬盘操作,于是整理了这篇博客. 1. 主分区,扩展分区,逻辑分区的联系和区别 ​ 一个硬盘可以有1 ...

  7. linux下硬盘分区、格式化以及文件管理系统

    1.添加虚拟硬盘 (1)点击编辑虚拟机位置,然后点击添加   (2)点击添加硬盘 (3)点击下一步 (4)创建新虚拟磁盘并点击下一步 (5)指定磁盘容量并且点击下一步 (6)点击完成 2.系统分区 当 ...

  8. linux系统安装硬盘分区建议

      一.常见挂载点的情况说明一般来说,在linux系统中都有最少两个挂载点,分别是/ (根目录)及 swap(交换分区),其中,/ 是必须的: 详细内容见下文: 安装系统时选择creat custom ...

  9. 【linux】硬盘分区

    fdisk -l fdisk /dev/sda d--删除分区 n-新建分区 p--主分区 e--扩展分区 t--改变分区格式 82为swap分区 w--保存退出 http://www.blogjav ...

随机推荐

  1. Chapter 2 User Authentication, Authorization, and Security(1):选择Windows和SQL 身份验证

    原文出处:http://blog.csdn.net/dba_huangzj/article/details/38657111,专题目录:http://blog.csdn.net/dba_huangzj ...

  2. mysql聚集索引

    转自http://www.cnblogs.com/tuyile006/archive/2009/08/28/1555615.html 微软的SQL SERVER提供了两种索引:聚集索引(cluster ...

  3. (NO.00002)iOS游戏精灵战争雏形(八)

    子弹的初始化工作前2篇基本做好了,下面就是如何射出子弹. 通常来说,子弹射向目标对象,需要走一条直线.直线由2点定位,分别为发射点和目标点. 发射点就是开枪精灵自身的位置,目标点则为敌方精灵的位置,大 ...

  4. Hibernate与Spring的事务管理

    什么是事务 这个问题比较大,按照我的理解就是,一个事务内的n个操作,要么全部完成,一旦有一个操作有问题,那么所有的操作都全部回滚. Jdbc的事务 首先,大家已经知道了,事务说白了就是一个词----统 ...

  5. [TCP] 网络协议流程图

    之前在跟别人讲协议的时候总是找不到类似的图,这次再看python网络编程书籍的时候找到了一个,留存一份. 清晰的看到不同协议在不同层的传输过程!

  6. C++对象模型(一):The Semantics of Constructors The Default Constructor (默认构造函数什么时候会被创建出来)

    本文是 Inside The C++ Object Model, Chapter 2的部分读书笔记. C++ Annotated Reference Manual中明确告诉我们: default co ...

  7. linux的string操作(字符串截取,长度计算)

    按指定的字符串截取 1.第一种方法: ${varible##*string} 从左向右截取最后一个string后的字符串 ${varible#*string}从左向右截取第一个string后的字符串 ...

  8. TortoiseGit安装过程

     运行TortoiseGit-1.7.7.0-32bit.msi,如下图 点击Next, 下一步 点击Next, 下一步 选择ssh客户端, 使用默认, 点击Next, 下一步 选择安装路径, 点 ...

  9. LeetCode之“链表”:Sort List

    题目链接 题目要求: Sort a linked list in O(n log n) time using constant space complexity. 满足O(n log n)时间复杂度的 ...

  10. Android Widget小组件开发(一)——Android实现时钟Widget组件的步骤开发,这些知识也是必不可少的!

    Android Widget小组件开发(一)--Android实现时钟Widget组件的步骤开发,这些知识也是必不可少的! PS:学习自某网站(不打广告) 这个小组件相信大家都很熟悉吧,以前的墨迹天气 ...