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

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 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容