Linux系统磁盘管理

#Linux系统磁盘管理
###1.什么是raid0 raid1 raid5 raid10磁盘阵列?

Raid0:
优点:raid0技术吧多块物理硬盘设备(至少俩块)通过硬件或软件的方式串联在一起,组成一个大的卷组,并将数据依次写入到各个物理硬盘中。这样一来,在最理想的状态下,硬盘设备的读写性能会提升数倍
缺点:但若任意一块硬盘发生故障将导致整个系统的数据都受到破坏
总体:raid0技术能够有效地提升硬盘数据的吞吐速度,但是不具备数据备份和错误修复能力。

Raid1:
优点:如果是raid0有较强的读写性能,那么对于数据安全来讲就需要用到raid1了,是通过吧两块以上的硬盘设备进行绑定,在写入数据时,是将数据同时写入到多块硬盘上(可以将其视为数据的镜像或备份)。当其中某一个硬盘发生故障后,一般会立刻自动以热交换的方式来恢复数据的正常使用
缺点:raid1技术虽然十分注重数据的安全性,但是因为是在多块硬盘设备中写入了相同的数据,因此硬盘设备的利用率得以下降,从理论上来说,只有两块硬盘组成的硬盘空间真实可用率只有50%,而三块的可用率也只有33%

Raid5:
优点:raid5技术是吧硬盘设备的数据去奇偶性信息保存到其他硬盘设备中。Raid5磁盘阵列组中数据的奇偶校验信息并不是单独保存到某一块硬盘设备中,而是存储到除自身以外的其他每一块硬盘设备上,这样的好处是其中任何一设备损坏后不至于出现致命缺陷。图中的parity存放的就是数据的奇偶信息,换句话说,就是raid5技术实际上没有备份硬盘中的真实数据信息,而是当硬盘设备出现问题后通过奇偶校验信息来尝试重建损坏的数据。Raid这样的技术特性“妥协”地兼顾了硬盘设备的读写速度、数据安全性与存储成本问题。
缺点:数据本身使用价值不高

Raid10:
优点:raid10技术是raid1+raid0技术的一个“组合体”。Raid10技术需要至少四块硬盘来组建,其中先分别两两制作成raid1磁盘阵列,以保障数据的安全性;然后再对两个raid1磁盘阵列实施raid0技术,进一步提高硬盘设备的读写速度。这样从理论上来讲,只要坏的不是同一组中的所有硬盘,那么最多可以损坏50%的硬盘设备而不丢失数据。由于raid10技术继承了raid0的高读写速度和raid1的数据安全性,在不考虑成本的情况下raid10的性能都超过了raid5,因此当前成为了广泛使用的一种存储技术

###2.1P+1E(3L)

[root@localhost ~]# lsblk 
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0   300G  0 disk 
|-sda1        8:1    0     1G  0 part /boot
`-sda2        8:2    0   299G  0 part 
  |-cs-root 253:0    0    70G  0 lvm  /
  |-cs-swap 253:1    0     4G  0 lvm  [SWAP]
  `-cs-home 253:2    0 225.1G  0 lvm  /home
sdb           8:16   0    20G  0 disk 
sdc           8:32   0    20G  0 disk 
sdd           8:48   0    20G  0 disk 
sr0          11:0    1  10.3G  0 rom  /run/media/roo/CentOS-Stream-8-x86_64-dvd
[root@localhost ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xee3e1fb5.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 
First sector (4196352-41943039, default 4196352): 
Last sector, +sectors or +size{K,M,G,T,P} (4196352-41943039, default 41943039): +
Last sector, +sectors or +size{K,M,G,T,P} (4196352-41943039, default 41943039): 

Created a new partition 2 of type 'Extended' and of size 18 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xee3e1fb5

Device     Boot   Start      End  Sectors Size Id Type
/dev/sdb1          2048  4196351  4194304   2G 83 Linux
/dev/sdb2       4196352 41943039 37746688  18G  5 Extended

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (4198400-41943039, default 4198400): 
Last sector, +sectors or +size{K,M,G,T,P} (4198400-41943039, default 41943039): +3G

Created a new partition 5 of type 'Linux' and of size 3 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xee3e1fb5

Device     Boot   Start      End  Sectors Size Id Type
/dev/sdb1          2048  4196351  4194304   2G 83 Linux
/dev/sdb2       4196352 41943039 37746688  18G  5 Extended
/dev/sdb5       4198400 10489855  6291456   3G 83 Linux

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 6
First sector (10491904-41943039, default 10491904): 
Last sector, +sectors or +size{K,M,G,T,P} (10491904-41943039, default 41943039): +3G

Created a new partition 6 of type 'Linux' and of size 3 GiB.

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 7
First sector (16785408-41943039, default 16785408): 
Last sector, +sectors or +size{K,M,G,T,P} (16785408-41943039, default 41943039): +2G

Created a new partition 7 of type 'Linux' and of size 2 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xee3e1fb5

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048  4196351  4194304   2G 83 Linux
/dev/sdb2        4196352 41943039 37746688  18G  5 Extended
/dev/sdb5        4198400 10489855  6291456   3G 83 Linux
/dev/sdb6       10491904 16783359  6291456   3G 83 Linux
/dev/sdb7       16785408 20979711  4194304   2G 83 Linux

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

[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]# lsblk 
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0   300G  0 disk 
|-sda1        8:1    0     1G  0 part /boot
`-sda2        8:2    0   299G  0 part 
  |-cs-root 253:0    0    70G  0 lvm  /
  |-cs-swap 253:1    0     4G  0 lvm  [SWAP]
  `-cs-home 253:2    0 225.1G  0 lvm  /home
sdb           8:16   0    20G  0 disk 
|-sdb1        8:17   0     2G  0 part 
|-sdb2        8:18   0   512B  0 part 
|-sdb5        8:21   0     3G  0 part 
|-sdb6        8:22   0     3G  0 part 
`-sdb7        8:23   0     2G  0 part 
sdc           8:32   0    20G  0 disk 
sdd           8:48   0    20G  0 disk 
sr0          11:0    1  10.3G  0 rom  /run/media/roo/CentOS-Stream-8-x86_64-dvd
[root@localhost ~]# 

2P+1E(2L)

[root@localhost ~]# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xdbdf0fa5.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (2-4, default 2): 
First sector (4196352-41943039, default 4196352): 
Last sector, +sectors or +size{K,M,G,T,P} (4196352-41943039, default 41943039): +2G

Created a new partition 2 of type 'Linux' and of size 2 GiB.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (3,4, default 3): 
First sector (8390656-41943039, default 8390656): 
Last sector, +sectors or +size{K,M,G,T,P} (8390656-41943039, default 41943039): 

Created a new partition 3 of type 'Extended' and of size 16 GiB.

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (8392704-41943039, default 8392704): 
Last sector, +sectors or +size{K,M,G,T,P} (8392704-41943039, default 41943039): +3G

Created a new partition 5 of type 'Linux' and of size 3 GiB.

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 6
First sector (14686208-41943039, default 14686208): 
Last sector, +sectors or +size{K,M,G,T,P} (14686208-41943039, default 41943039): +3G

Created a new partition 6 of type 'Linux' and of size 3 GiB.

Command (m for help): p
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xdbdf0fa5

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdc1           2048  4196351  4194304   2G 83 Linux
/dev/sdc2        4196352  8390655  4194304   2G 83 Linux
/dev/sdc3        8390656 41943039 33552384  16G  5 Extended
/dev/sdc5        8392704 14684159  6291456   3G 83 Linux
/dev/sdc6       14686208 20977663  6291456   3G 83 Linux

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

[root@localhost ~]# partprobe /dev/sdc
[root@localhost ~]# 

3P+1E(1L)

[root@localhost ~]# fdisk /dev/sdd

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x292ae59f.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +3G

Created a new partition 1 of type 'Linux' and of size 3 GiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (2-4, default 2): 
First sector (6293504-41943039, default 6293504): 
Last sector, +sectors or +size{K,M,G,T,P} (6293504-41943039, default 41943039): +3G

Created a new partition 2 of type 'Linux' and of size 3 GiB.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (3,4, default 3): 
First sector (12584960-41943039, default 12584960): 
Last sector, +sectors or +size{K,M,G,T,P} (12584960-41943039, default 41943039): +3G

Created a new partition 3 of type 'Linux' and of size 3 GiB.

Command (m for help): n
Partition type
   p   primary (3 primary, 0 extended, 1 free)
   e   extended (container for logical partitions)
Select (default e): e

Selected partition 4
First sector (18876416-41943039, default 18876416): 
Last sector, +sectors or +size{K,M,G,T,P} (18876416-41943039, default 41943039): 

Created a new partition 4 of type 'Extended' and of size 11 GiB.

Command (m for help): n
All primary partitions are in use.
Adding logical partition 5
First sector (18878464-41943039, default 18878464): 
Last sector, +sectors or +size{K,M,G,T,P} (18878464-41943039, default 41943039): +5G

Created a new partition 5 of type 'Linux' and of size 5 GiB.

Command (m for help): p
Disk /dev/sdd: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x292ae59f

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdd1           2048  6293503  6291456   3G 83 Linux
/dev/sdd2        6293504 12584959  6291456   3G 83 Linux
/dev/sdd3       12584960 18876415  6291456   3G 83 Linux
/dev/sdd4       18876416 41943039 23066624  11G  5 Extended
/dev/sdd5       18878464 29364223 10485760   5G 83 Linux

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

[root@localhost ~]# partprobe /dev/sdd
[root@localhost ~]# 

###3、swap分区
两种方法
一:

[root@localhost ~]# dd if=/dev/zero of=/opt/newdisk bs=2M count=1024
1024+0 records in
1024+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 16.6138 s, 129 MB/s
[root@localhost ~]# mkswap -f /opt/newdisk
mkswap: /opt/newdisk: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=b4a6363d-604a-408b-9d14-02f0e89331d6
[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3704        1173         111          13        2419        2278
Swap:          4027          17        4010
[root@localhost ~]# swapon /opt/newdisk
swapon: /opt/newdisk: insecure permissions 0644, 0600 suggested.
[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3704        1174         110          13        2419        2277
Swap:          6075          17        6058
[root@localhost ~]# 

二:

[root@localhost ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xb62f71c1.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xb62f71c1

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 4196351 4194304   2G 83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xb62f71c1

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 4196351 4194304   2G 82 Linux swap / Solaris

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

[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=2c3edca9-bf84-4106-a460-977d8717d644
[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="2c3edca9-bf84-4106-a460-977d8717d644" TYPE="swap" PARTUUID="b62f71c1-01"
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# vim /etc/fstab
UUID="2c3edca9-bf84-4106-a460-977d8717d644" swap swap defaults 0 0
[root@localhost ~]# swapon -a
[root@localhost ~]# lsblk 
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0   300G  0 disk 
|-sda1        8:1    0     1G  0 part /boot
`-sda2        8:2    0   299G  0 part 
  |-cs-root 253:0    0    70G  0 lvm  /
  |-cs-swap 253:1    0     4G  0 lvm  [SWAP]
  `-cs-home 253:2    0 225.1G  0 lvm  /home
sdb           8:16   0    20G  0 disk 
`-sdb1        8:17   0     2G  0 part [SWAP]
sdc           8:32   0    20G  0 disk 
sdd           8:48   0    20G  0 disk 
sr0          11:0    1  10.3G  0 rom  /run/media/roo/CentOS-Stream-8-x86_64-dvd
[root@localhost ~]# 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值