美文网首页
磁盘管理和文件系统的实际应用

磁盘管理和文件系统的实际应用

作者: 沐熙一叶_Leaf | 来源:发表于2021-01-10 20:21 被阅读0次

1、破坏mbr表并修复

#1、 备份MBR分区表到另外一台机器
[root@localhost ~]# mkdir /data
[root@localhost ~]# dd if=/dev/nvme0n1 of=/data/dpt.img bs=1 count=64 skip=446
64+0 records in
64+0 records out
64 bytes copied, 8.9457e-05 s, 715 kB/s
[root@localhost ~]# scp /data/dpt.img 10.0.0.203:
The authenticity of host '10.0.0.203 (10.0.0.203)' can't be established.
RSA key fingerprint is SHA256:eXT6e/Ovz9uGAIh3HTmQRqHTGyQp8woQl3OXYLPdtCQ.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.0.203' (RSA) to the list of known hosts.
root@10.0.0.203's password: 
dpt.img                                                                                                   100%   64   178.3KB/s   00:00

#2、破坏MBR分区表
[root@localhost ~]# dd if=/dev/zero of=/dev/nvme0n1 bs=1 count=64 seek=446
64+0 records in
64+0 records out
64 bytes copied, 9.0814e-05 s, 705 kB/s

#3、重启后无法进入系统
[root@localhost ~]# reboot

#4、用光盘启动,进入rescue mode,选第3项skip to shell
#进去后配置本机IP与备份那台做连接
#ifconfig ens160 10.0.0.201/24

#5、拷贝备份的MBR表
#scp 10.0.0.203:/root/dpt.img .

#6、恢复MBR分区表,重启正常进入系统
#dd if=dpt.img of=/dev/sda bs=1 seek=446
#exit

2、总结RAID的各个级别及其组合方式和性能的不同。
下面是常用的RAID
RAID0特性:

  1. 读写性能提升;
  2. 可用空间,N*min
  3. 无容错能力;
  4. 最小磁盘数2,2+

RAID1特性:

  1. 读性能提升,写性能略有下降,同一份数据要存两份;
  2. 可用空间,1*min,磁盘总空间的一半;
  3. 有冗余能力;
  4. 最少磁盘数,2,2+;

RAID5特性:

  1. 读写性能提升;
  2. 可用空间,N-1*min;
  3. 有冗余能力;
  4. 最少磁盘数,3,3+;

RAID10特性:

  1. 读写性能提升;
  2. 可用空间,N*min/2;
  3. 有冗余能力,每组镜像最多只能坏一块;
  4. 最少磁盘数,4,4+;

3、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项

#1、查看硬盘信息,一下将sdb作为操作目标
[root@centos7 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   27G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk 
sr0              11:0    1 1024M  0 rom  

#2、在sdb磁盘上创建大小为2G的分区
[root@centos7 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0xd6ff8485.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-10485759, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#3、在sdb1分区上创建文件系统
[root@centos7 ~]# mkfs.ext4 -b 2048 -m 1 -L TEST /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
10485 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=269484032
64 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
    16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 
#文件系统已经创建
[root@centos7 ~]# blkid
/dev/sda1: UUID="fd757a87-91b3-4517-8bc5-72466f0878a4" TYPE="xfs" 
/dev/sda2: UUID="pwwTHd-Lszj-rYEP-f6Qu-Px2f-4i3e-347wHt" TYPE="LVM2_member" 
/dev/sdb1: LABEL="TEST" UUID="79450cbb-b1c7-447a-ab06-129afa93eb02" TYPE="ext4" 
/dev/mapper/centos-root: UUID="6f24832e-127f-4e86-9fbf-279a7efe326d" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="319099b9-55cc-4839-9788-a53cf6866f0a" TYPE="swap" 

#4、将分区挂载在/test目录中
# 在/etc/fstab文件末尾添加以下内容
[root@centos7 ~]# vim /etc/fstab 
UUID=79450cbb-b1c7-447a-ab06-129afa93eb02 /test ext4    acl             0 0

#5、创建目标文件夹使配置生效
[root@centos7 ~]#mkdir /test
[root@centos7 ~]# mount -a 

#6、挂载完毕,查看磁盘
[root@centos7 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   27G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk 
└─sdb1            8:17   0    2G  0 part 
sr0              11:0    1 1024M  0 rom  

4、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

#1、查看磁盘信息,以下操作将以sdc、sdd作为操作目标
[root@centos7 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   27G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk 
└─sdb1            8:17   0    2G  0 part /test
sdc               8:32   0   10G  0 disk 
sdd               8:48   0   10G  0 disk 
sr0              11:0    1 1024M  0 rom  

#2、创建PV
[root@centos7 ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.
[root@centos7 ~]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created.
[root@centos7 ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  <29.00g  4.00m
  /dev/sdc          lvm2 ---   10.00g 10.00g
  /dev/sdd          lvm2 ---   10.00g 10.00g

#3、创建名为testvg的VG,PE大小为16M
[root@centos7 ~]# vgcreate testvg -s 16M /dev/sdc /dev/sdd 
  Volume group "testvg" successfully created
[root@centos7 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  centos   1   2   0 wz--n- <29.00g   4.00m
  testvg   2   0   0 wz--n- <19.97g <19.97g
[root@centos7 ~]# vgdisplay testvg 
  --- Volume group ---
  VG Name               testvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <19.97 GiB
  PE Size               16.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / <19.97 GiB
  VG UUID               4kLfLX-ufLc-TH1k-eknK-rjF1-jdR4-5KvBtO

#4、创建大小为5G的逻辑卷testlv,并建立文件系统
[root@centos7 ~]# lvcreate -L 5G -n testlv testvg 
  Logical volume "testlv" created.
[root@centos7 ~]# lvs
  LV     VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   centos -wi-ao---- 26.99g                                                    
  swap   centos -wi-ao----  2.00g                                                    
  testlv testvg -wi-a-----  5.00g       
[root@centos7 ~]# lvdisplay /dev/testvg/testlv 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                jrgEC8-0Jbj-rCpA-bLPy-RY1S-ELME-M4v8cf
  LV Write Access        read/write
  LV Creation host, time centos7, 2021-01-08 04:06:32 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
#建立文件系统
[root@centos7 ~]# mkfs.ext4 /dev/testvg/testlv 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

#5、创建/users,并挂载
[root@centos7 ~]# mkdir /users
[root@centos7 ~]# mount /dev/testvg/testlv /us
users/ usr/   
[root@centos7 ~]# mount /dev/testvg/testlv /users/
[root@centos7 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   27G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk 
└─sdb1            8:17   0    2G  0 part /test
sdc               8:32   0   10G  0 disk 
└─testvg-testlv 253:2    0    5G  0 lvm  /users
sdd               8:48   0   10G  0 disk 
sr0              11:0    1 1024M  0 rom 

相关文章

  • 磁盘管理和文件系统的实际应用

    1、破坏mbr表并修复 2、总结RAID的各个级别及其组合方式和性能的不同。下面是常用的RAIDRAID0特性: ...

  • Linux 常用命令

    文件系统 磁盘管理 用户管理 系统及其他 网络配置管理

  • I/O优化

    I/O基本知识 整个I/O操作由应用程序、文件系统和磁盘共同完成,应用程序将I/O命令发送到文件系统,文件系统在合...

  • Linux磁盘挂载(分区、格式化、挂载)

    Linux磁盘管理常用三个命令为df、du和fdisk。 df:列出文件系统的整体磁盘使用量。 du:检查磁盘空间...

  • Linux磁盘与文件系统管理

    Linux磁盘与文件系统管理 Linux磁盘与文件管理系统 2017-06-12 09:41:28 ...

  • 磁盘管理和文件系统

    磁盘管理和文件系统 机械硬盘和固态硬盘: 设备文件: 分区: MBR分区结构: 管理分区 parted 命令 gf...

  • I/O优化(上)

    你可以看到整个文件 I/O 操作由应用程序、文件系统和磁盘共同完成。首先应用程序将 I/O 命令发送给文件系统,然...

  • note_8.3_linux格式化文件系统

    磁盘和文件系统管理 文件系统管理工具: 创建文件系统的工具mkfs  mkfs.ext2, mkfs.ext3, ...

  • 20170804 磁盘管理

    目录磁盘结构磁盘分区磁盘分区管理文件系统管理挂载 一、磁盘结构 (一)设备文件 设备文件:linux系统下一切皆文...

  • 系统管理

    一 磁盘管理 1 )磁盘空间检测命令: df df 命令显示当前系统中,各个逻辑磁盘(文件系统)中空闲磁盘块(51...

网友评论

      本文标题:磁盘管理和文件系统的实际应用

      本文链接:https://www.haomeiwen.com/subject/txrtaktx.html