磁盘管理之 raid 文件系统 分区

简介: 第1章 RAID 磁盘阵列 1.1 使用raid的目的 1)获得更大的容量 2)让数据更安全 3)读写速度更快 1.2 raid0、raid1、raid5、raid10对比 raid类型 数量 优点 缺点 使用类型 raid0 条带 至少1块硬盘。

第1章 RAID 磁盘阵列

1.1 使用raid的目的

1)获得更大的容量

2)让数据更安全

3)读写速度更快

1.2 raid0raid1raid5raid10对比

raid类型

数量

优点

缺点

使用类型

raid0 条带

至少1块硬盘。

把所有硬盘的容量加在一起,读写速度更快

一块硬盘损坏,整体都不能使用

数据不是很重要,追求性能

数据库的从库

集群的某个节点

raid1 镜像

只能是两块硬盘

安全,有100%的冗余

写入速度比较慢

读取还可以

成本较高

对数据安全要求比较高,不需要太多的性能

raid5

至少三块硬盘

有奇偶校验,有一定的冗余,最多损坏1块硬盘 损失一块硬盘的容量

读取性能可以

写入很慢

比较通用。

+spare

可以作为热备

raid10

最少4块硬盘

数量必须是偶数

读写的速度都很快,安全性较高冗余,最多可以损坏一半

成本高

容量浪费一半

数据库

重要的文件

第2章 磁盘分区

2.1 mbr是什么

mbr引导:主引导记录

2.1.1 mbr在哪里

磁盘的0磁头 0磁道 1扇区 446字节

一个扇区的大小为512字节

446字节    mbr

中间64字节   分区表

最后2字节    分区结束表示55AA

2.1.2 分区表

       在分区表的64字节里,划分为4个格子 16*4

       每个格子里存放的是分区的信息(主分区 扩展分区)

2.1.3 如何查看磁盘第一个扇区里的内容

拿出出来前512个字节

[root@znix ~]# dd if=/dev/sda of=/tmp/512.bin bs=512 count=1

1+0 records in

1+0 records out

512 bytes (512 B) copied, 0.000190527 s, 2.7 MB/s

看下文件的类型

[root@znix ~]# file /tmp/512.bin

/tmp/512.bin: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x6280, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 409600 sectors; partition 2: ID=0x82, starthead 159, startsector 411648, 1572864 sectors; partition 3: ID=0x83, starthead 135, startsector 1984512, 18987008 sectors, code offset 0x48

2.1.4 如何查看二进制文件的内容

od命令查看二进制文件的内容

[root@znix ~]#   od -xa /tmp/512.bin

……

0000760    0000    0000    0000    0000    0000    0000    0000    aa55   结束标识符

        nul nul nul nul nul nul nul nul nul nul nul nul nul nul   U   *

0001000

2.2 主分区、扩展分区、逻辑分区的关系

2.2.1 主分区

最多有4个主分区

2.2.2 扩展分区

没有办法直接使用 ,需要划分成逻辑分区才可以使用。

2.2.3 逻辑分区

必须要在扩展分区下面划分逻辑分区才可以使用。

逻辑分区

sas/sata/scsi/ 中为 sda  5-15

2.3 在系统中磁盘分区的命名

磁盘设备都放在/dev/目录下

sas/sata/scsi/接口     sd 开头

ide 接口               hd开头

2.3.1 磁盘名称示例

第一块硬盘 sda

第二块硬盘 sdb

第三块硬盘 sdc

2.3.2 第一块硬盘 sda

              主分区 1-4

              扩展分区 1-4 一般为4

              逻辑分区 5+开始

2.3.3 分区的命名规则

第一块硬盘的第一个主分区:sda1

第一块硬盘的第一个逻辑分区:sda5

第二块硬盘的第二个逻辑分区:sdb6

2.4 回顾分区方式

2.4.1 没有重要数据

/boot   200M    存放系统的引导信息 内核

swap   交换分区   防止内存用光了 临时的一个内存

      如果你的内存小于8G swap是内存的1.5   如果你的内存大于8G swap8G

/        根分区 剩余多少给多少

2.4.2 很多重要数据

/boot   200M    存放系统的引导信息 内核

swap   交换分区   防止内存用光了 临时的一个内存

      如果你的内存小于8G swap是内存的1.5   如果你的内存大于8G swap8G

/         根分区              20G-200G

/data  存放重要的数据 剩余多少给多少

2.4.3 不知道数据是否重要

/boot   200M    存放系统的引导信息 内核

swap   交换分区   防止内存用光了 临时的一个内存

      如果你的内存小于8G swap是内存的1.5   如果你的内存大于8G swap8G

/         根分区              20G-200G

剩余空间不分 放着谁使用这台服务器谁来分区

2.5 ps 命令内容详解--每列的含义

2.5.1 ps aux 中的vszrss

[root@znix shm]# ps aux

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root          1  0.0  0.2  19352  1300 ?        Ss   Sep14   0:01 /sbin/ini

用户     进程号  CPU  内存   

VSZ 进程所占用的虚拟内存的大小(物理内存+swap

RSS 进程所占用的内存(物理内存) 

2.5.2 ps -ef 列含义系简介

[root@znix shm]# ps -ef

UID         PID   PPID    C STIME TTY        TIME   CMD

root          1      0    0 Sep14 ?      00:00:01   /sbin/init

用户名    进程号 子进程号                          运行了什么命令 

第3章 磁盘分区

3.1 linux里面的分区工具

       fdisk   主要是给磁盘小于2T(只能出来分区表是mbr的)

       parted  主要是给磁盘大于2Tgpt

3.2 通过fdisk给磁盘进行分区(创建一个10M主分区和一个40M逻辑分区)

3.2.1 使用fdisk会提示一个错误

[root@znix ~]# 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 0x31dcd35a.

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 4 will be corrected by w(rite)

警告 可以关闭dos的兼容模式,使用扇区作为分区的默认单位  -cu

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):

3.2.2 fdisk添加上了 -cu 参数

-cu 参数是在分区的时候,能够以扇区的方式进行。

[root@znix ~]# fdisk -cu /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0xb9f506a4.

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 4 will be corrected by w(rite)

 

Command (m for help):

3.2.3 查看fdisk的帮助信息

Command (m for help): m                      

Command action

 

   d   delete a partition            删除一个分区

   m   print this menu               显示帮助菜单

   n   add a new partition           创建一个分区

   p   print the partition table     显示分区表

   q   quit without saving changes   退出不保存

   w   write table to disk and exit  保存并退出

3.2.4 创建一个主分区

Command (m for help): n

Command action 

   e   extended       扩展分区

   p   primary partition (1-4)  主分区

p

Partition number (1-4): 1    第一个分区

First sector (2048-208895, default 2048): 直接回车为默认

Using default value 2048  默认选择第一个扇区

Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): +10M

3.2.5 显示一下分出来的分区

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83

3.2.6 创建一个扩展分区

扩展分区的分区原则是:剩多少给多少

Command (m for help): n

Command action

   e   extended  扩展分区

   p   primary partition (1-4)

e

Partition number (1-4): 2

First sector (22528-208895, default 22528):

Using default value 22528

Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895):

Using default value 208895

3.2.7 显示现在的分区表信息

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528      208895       93184    5  Extended

3.2.8 在拓展分区下创建逻辑分区

Command (m for help): n

Command action

   l   logical (5 or over)  逻辑分区,创建完扩展分区后只能创建逻辑分区

   p   primary partition (1-4)

l

First sector (24576-208895, default 24576):

Using default value 24576

Last sector, +sectors or +size{K,M,G} (24576-208895, default 208895): +40M

3.2.9 显示一下当前的分区表

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528      208895       93184    5  Extended

/dev/sdb5           24576      106495       40960   83  Linux

3.2.10 保存并退出

fdisk 必须保存以后才能生效,w为保存并退出

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

3.3 【示例】添加一块硬盘sdb 100m划分一个分区 ,挂载到/mnt目录

3.3.1 第一步 创建一个主分区

[root@znix ~]# fdisk -cu /dev/sdb

 

Command (m for help): n  

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First sector (2048-208895, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):

Using default value 208895

都选择默认就是使用整块盘的空间创建一个分区

3.3.2 显示当前的分区表

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048      208895      103424   83  Linux

3.3.3 保存并退出

fdisk 必须保存以后才能生效,w为保存并退出

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

3.3.4 第二步 格式化创建文件系统

mkfs ==make filesystem即创建文件系统。

[root@znix ~]# mkfs.ext4 /dev/sdb1

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)  #block的大小

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

25896 inodes, 103424 blocks   #inodeblock的数量

5171 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67371008

13 block groups

8192 blocks per group, 8192 fragments per group

1992 inodes per group

Superblock backups stored on blocks:

    8193, 24577, 40961, 57345, 73729

 

Writing inode tables: done                           

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

3.3.5 第三步 关闭分区的自我检查

tune2fs 命令

-c 挂载多少次 0 为关闭

-i 隔多长时间 0 为关闭

[root@znix ~]# tune2fs -c 0 -i 0 /dev/sdb1

tune2fs 1.41.12 (17-May-2010)

Setting maximal mount count to -1

Setting interval between checks to 0 seconds

3.3.6 第四步 挂载磁盘

[root@znix ~]# mount /dev/sdb1 /mnt/

[root@znix ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       8.8G  1.9G  6.5G  23% /

tmpfs           238M     0  238M   0% /dev/shm

/dev/sda1       190M   40M  141M  22% /boot

/dev/sdb1        94M  1.6M   88M   2% /mnt

3.3.7 第五步 让磁盘永久挂载 开机自动挂载

两个文件可以实现:

    /etc/rc.local

    /etc/fstab

/etc/rc.local文件中,写入什么命令都可以执行。

3.3.8 /etc/fstab 文件的内容

[root@znix ~]# cat /etc/fstab

#

# /etc/fstab

# Created by anaconda on Thu Aug 10 18:33:48 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=49bad9e9-cf33-4a15-ba84-4fd28e70bd29 /                       ext4    defaults        1 1

UUID=7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8 /boot                   ext4    defaults        1 2

UUID=46bc0a52-b13f-4845-8baa-90207849d5c5 swap                    swap    defaults        0 0

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

磁盘分区设备    挂载点      文件系统的类型   挂载参数   是否进行dump备份 是否进行fsk磁盘检查

3.3.9 将挂载信息写入配置文件

[root@znix ~]# tail -1 /etc/fstab

/dev/sdb1              /mnt                    ext4    defaults        0 0

3.3.10 显示系统中的uuid

使用blkid 命令可以查看系统磁盘的uuid

[root@znix ~]# blkid

/dev/sda3: UUID="49bad9e9-cf33-4a15-ba84-4fd28e70bd29" TYPE="ext4"

/dev/sda1: UUID="7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8" TYPE="ext4"

/dev/sda2: UUID="46bc0a52-b13f-4845-8baa-90207849d5c5" TYPE="swap"

/dev/sdb1: UUID="7101630b-b325-49d1-92b9-0a500c2a07f6" TYPE="ext4"

3.4 在挂载磁盘的时候出现未格式化错误

对磁盘进行一些操作的时候可能会提示没有格式化磁盘,需要格式化。

[root@znix ~]# tune2fs -c0 -i0 /dev/sdc

tune2fs 1.41.12 (17-May-2010)

tune2fs: Bad magic number in super-block while trying to open /dev/sdc

Couldn't find valid filesystem superblock.

没有找到可用的文件系统

相关文章
|
8月前
|
Unix Linux
|
8月前
|
IDE 安全 Linux
2.2磁盘分区
2.2磁盘分区
65 0
|
10月前
|
存储 运维 Oracle
Linux系统管理--硬盘、卷组、逻辑卷和文件系统
增加两个20GB的硬盘,注意新增加的硬盘不能取代原来安装了操作系统的0号硬盘,不然无法启动。
|
存储 安全 Linux
RAID磁盘管理
RAID磁盘管理
79 0
RAID磁盘管理
|
存储 IDE Linux
|
存储 安全 Linux
磁盘文件系统三
磁盘文件系统三
磁盘文件系统三
|
存储 Linux 索引
磁盘文件系统二
磁盘文件系统二
磁盘文件系统二

热门文章

最新文章