磁盘管理之分区管理

                 磁盘管理之分区管理


 磁盘一般指的是计算的硬盘,它是计算机五大部件之一,主要用来存储数据。所有它是计算机不可或缺的部件之一。


常见的硬盘分为固态和机械二种:

    固态: 固态硬盘是用固态电子存储芯片阵列而制成的硬盘,由控制单元和存储单元(FLASH芯片、DRAM芯片)组成。但是造价较高。

    优势:读写性能好 低功率、无噪音、防震性能好等、

    缺点:售价较高、容量小

    

    机械:机械硬盘其实是许多的盘片、机械手臂、磁头与主轴马达所组成。在主轴马达的转动下由可伸展机械臂的磁头在盘片进行读写操作。


    转速:转速的快慢是标示硬盘档次的重要参数之一,硬盘的转速越快,硬盘寻找文件的速度也就越快,相对的硬盘的传输速度也就得到了提高。单位表示为RPM,RPM是Revolutions Per minute的缩写,是转/每分钟。RPM值越大,内部传输率就越快,访问时间就越短,硬盘的整体性能也就越好。


     扇区(Sector):每个机械硬盘的每个扇区大小都为512bytes。


     磁道(Track):当磁盘旋转时,磁头若保持在一个位置上,则每个磁头都会在磁盘表              面划出一个圆形轨迹,这些圆形轨迹就叫做磁道。


    柱面(Cylinkder):盘片上的同一磁道组成的面

    


 当你拿到一个全新的硬盘你要先对它进行分区,为什么要分区?可能有些人会问这个问题。因为一块大容量硬盘好如一个大柜子,要在这个柜子里存放各种文件,有很多种方法,但为了便于管理和使用,一般都会把大柜子分成一个一个的相对独立的“隔间”或“抽屉”,绝不会就把大柜子当做一个大抽屉来使用。分区还可以有利于病毒的防治和数据的安全等等。。。


无论是windows还是linux,目前支持的分区结构只有两种,一种是基于blos检查启动的mbr结构,另一种是基于uefi(统一扩展固件接口)的opt分区结构。当然,目前广泛的还是使用的mbr结构。   


MBR,全称为Master Boot Record,即硬盘的主引导记录。盘的0柱面、0磁头、1扇区称为主引导扇区(也叫主引导记录MBR)。它由三个部分组成,主引导程序、硬盘分区表DPT(Disk Partition table)和分区有效标志。在总共512字节的主引导扇区里主引导程序(boot loader)占446个字节,第二部分是Partition table区(分区表),即DPT,占64个字节,硬盘中分区有多少以及每一分区的大小都记在其中。第三部分是magic number,占2个字节,固定为0xAA55或0x55AA。

    


   
磁盘分区

     

查看磁盘分区: lsblk

[root@Cloud /]#lsblk   #显示磁盘分区信息
NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                  11:0    1  3.7G  0 rom  /media
sda                   8:0    0  200G  0 disk 
├─sda1                8:1    0  200M  0 part /boot
└─sda2                8:2    0   60G  0 part 
  ├─vg0-root (dm-0) 253:0    0   20G  0 lvm  /
  ├─vg0-swap (dm-1) 253:1    0    2G  0 lvm  [SWAP]
  ├─vg0-usr (dm-2)  253:2    0   10G  0 lvm  /usr
  └─vg0-var (dm-3)  253:3    0   20G  0 lvm  /var
sdb                   8:16   0   15G  0 disk /mnt/one
sdc                   8:32   0   20G  0 disk 
lsblk列出的信息NAME   设备名
MAJ:MIN 主版本号 :次版本号
RM 是否为可移动设备 显示1位移动设备
SIZE  大小
RO  只读
TYPE  磁盘、分区类型
MOUNTPOINT 挂载点

磁盘分区工具 fdisk

[root@Cloud ~]#fdisk -l /dev/sdb #x -l 列出/dev/sdb的分区信息 不加参数为所有磁盘
Disk /dev/sdb: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@Cloud ~]#fdisk /dev/sdb #对/dev/sdb进去分区等管理
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#MBR分区如果你分区不想使用它可以做到类型格式化的作用
   p   print the partition table #显示分区列表
   q   quit without saving changes #退出不保存
   s   create a new empty Sun disklabel 
   t   change a partition's system id #分区类型,常用82,83 8e 等
   u   change display/entry units 
   v   verify the partition table
   w   write table to disk and exit #保存并退出
   x   extra functionality (experts only)

显示所有分区

[root@Cloud ~]#fdisk -l  #显示所有分区
Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000efd6b
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560   8e  Linux LVM
/dev/sda3            7859        7990     1059291   83  Linux
Disk /dev/sdb: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x8e7a48c2
   Device Boot      Start         End      Blocks   Id  System
Disk /dev/sdc: 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
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb3173c06
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         393     3156741   83  Linux
Disk /dev/mapper/vg0-root: 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
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg0-swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg0-usr: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg0-var: 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
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

支持的分区

Command (m for help): l
 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT- #swap分区
 2  XENIX root      3c  PartitionMagic  83  Linux #常用分区        c4  DRDOS/sec (FAT-
 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         
 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data    
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM #逻辑卷    df  BootIt         
 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT

1e  Hidden W95 FAT1

           

新增为逻辑分区

Command (m for help): n
First cylinder (7991-8122, default 7991): 
Using default value 7991
Last cylinder, +cylinders or +size{K,M,G} (7991-8122, default 8122): +1G
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000efd6b
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560   8e  Linux LVM
/dev/sda3            7859        7990     1059291   83  Linux
/dev/sda4            7991        8122     1060290    5  Extended
/dev/sda5            7991        8122     1060258+  83  Linux

删除分区

Command (m for help): d
Partition number (1-5): 1
Command (m for help): d
Partition number (1-5): 2
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000efd6b
   Device Boot      Start         End      Blocks   Id  System
/dev/sda3            7859        7990     1059291   83  Linux
/dev/sda4            7991        8122     1060290    5  Extended
/dev/sda5            7991        8122     1060258+  83  Linux

有些时候对硬盘分区的时候如果硬盘已经被挂载使用了,再对它进行分区的话,有时内核会识别不到我们新建的分区 所有要用命令

内核识别新增分区:  

partx-a -n M:N /dev/DEVICE

kpartx-a /dev/DEVICE -f: force

内核识别删除分区:

partx -d /dev/DEVICE

    

CentOS 5,7: 使用partprobe

partprobe[/dev/DEVICE]

原创文章,作者:ladsdm,如若转载,请注明出处:http://www.178linux.com/43720

(0)
ladsdmladsdm
上一篇 2016-09-06 08:50
下一篇 2016-09-06 08:51

相关推荐

  • 马哥网络21-第5周作业

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@localhost proc]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2…

    Linux干货 2016-08-08
  • sed初步认识

     ◆ sed基础概念 ◆ sed用法 一.sed 基础概念: Stream EDitor (流/行编辑器) sed是一种流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕…

    2017-03-16
  • 压缩、解压缩及归档工具

    压缩、解压缩及归档工具 缩文件的基本原理是查找文件内的重复字节,并建立一个相同字节的"词典"文件,并用一个代码表示,比如在文件里有几处有一个相同的词"中华人民共和国"用一个代码表示并写入"词典"文件,这样就可以达到缩小文件的目的。         &#8212…

    Linux干货 2016-08-18
  • 编程真难啊

    上周,在Sun的Java论坛上出现了一个这样的帖子,这个贴子的链接如下:http://forums.sun.com/thread.jspa?threadID=5404590&start=0&tstart=0 LZ的贴子翻译如下: 大家好,我是一个Java的新手,我有一个简单的问题:请问我怎么才能反转一个整数的符号啊。比如把-12转成+12。是…

    Linux干货 2015-04-03
  • N25-第18周博客作业

    1、为LNMP架构添加memcached支持,并完成对缓存效果的测试报告; LNMP的安装过程不再赘述. # yum install -y memcached # cat /etc/sysconfig/memcached  PORT=”11211″   &nb…

    2017-05-21
  • Linux基础指令(2)

    4.文件的元数据信息有哪些,分别表示什么含义,如何查看?如何修改文件的时间戳信息?  元数据定义:      数据(Metadata),又称中介数据、中继数据,为描述 数据的数据(data about data),主要是描述数据属性(property)的信息,用来支持如…

    Linux干货 2016-11-09