1之剧、破壞mbr表并修復(fù)
#第一步,需要事先備份好MBR分區(qū)表砍聊,或者從其他服務(wù)器獲取MBR分區(qū)表
#總共是512bytes背稼,前446bytes是 boot loader;后64bytes是分區(qū)表
#使用dd工具玻蝌,備份64bytes的分區(qū)表蟹肘,通過scp將備份數(shù)據(jù)傳輸?shù)狡渌?wù)器
[root@centos8 ~]#dd if=/dev/sda of=/data/dpt.img bs=1 count=64 skip=446
[root@Centos7 data]# hexdump -C dpt.img
00000000 80 20 21 00 83 35 70 05 00 08 00 00 00 00 40 00 |. !..5p.......@.|
00000010 00 35 71 05 83 fe ff ff 00 08 40 00 00 00 40 06 |.5q.......@...@.|
00000020 00 fe ff ff 82 fe ff ff 00 08 80 06 00 00 40 00 |..............@.|
00000030 00 fe ff ff 05 fe ff ff 00 08 c0 06 00 f8 3f 12 |..............?.|
00000040
[root@Centos7 ~]#scp /data/dpt.img 10.154.119.134:
root@10.154.119.134's password:
dpt.img 100% 64 44.2KB/s 00:00
#破壞MBR分區(qū)表
#skip是跳過讀取文件的位數(shù),seek是跳過寫入文件的位數(shù)
[root@centos8 ~]#dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446
[root@centos8 ~]#reboot
#用光盤啟動,進入rescue mode,選第3項skip to shell
#啟動之后俯树,發(fā)現(xiàn)沒有網(wǎng)絡(luò)帘腹,需要配置臨時網(wǎng)絡(luò)
#從遠(yuǎn)程服務(wù)器獲取到分區(qū)表的備份
sh-4.4#ifconfig ens33 10.154.119.140/24
sh-4.4#scp 10.154.119.134:/root/dpt.img .
#恢復(fù)MBR分區(qū)表
sh-4.4#dd if=dpt.img of=/dev/sda bs=1 seek=446
sh-4.4#exit
2、總結(jié)RAID的各個級別及其組合方式和性能的不同许饿。
1??RAID概念:獨立磁盤冗余陣列阳欲。多個磁盤合成一個陣列,以此來提供更好的性能、冗余球化。
常見raid級別統(tǒng)計:
raid級別 | 組合方式 | 性能 | 冗余 |
---|---|---|---|
raid-0 | 最少2塊磁盤 | 讀寫性能提升 | 無 |
raid-1 | 2N塊磁盤 | 讀性能提升秽晚、寫性能下降 | 另一塊磁盤為復(fù)制作用 |
raid-5 | 最少3塊磁盤 | 讀寫性能提升 | 最多一塊磁盤損壞 |
raid-10 | 最少4塊磁盤 | 讀寫性能提升 | 每組鏡像只能壞一塊磁盤 |
raid-01 | 最少4塊磁盤 | 讀寫性能提升 | 安全性差,不建議使用 |
3筒愚、創(chuàng)建一個2G的文件系統(tǒng)赴蝇,塊大小為2048byte,預(yù)留1%可用空間,文件系統(tǒng) ext4巢掺,卷標(biāo)為TEST句伶,要求此分區(qū)開機后自動掛載至/test目錄,且默認(rèn)有acl掛載選項
#創(chuàng)建2G的分區(qū)
[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 0xdd10be81.
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): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +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.
[root@Centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 50G 0 part /data
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 100G 0 part /
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 2G 0 part
sr0 11:0 1 4.4G 0 rom
#新建文件系統(tǒng)并添加屬性
[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
#查看文件系統(tǒng)的屬性
[root@Centos7 ~]# blkid
/dev/sda1: UUID="71afae2d-2416-4c68-8375-e27437e32fa3" TYPE="xfs"
/dev/sda2: UUID="bb537f14-b824-402e-81c3-63b87a82052a" TYPE="xfs"
/dev/sda3: UUID="bb38c0b6-b4b3-41b8-96f9-30af2315226c" TYPE="swap"
/dev/sda5: UUID="3089f417-1bba-4347-8f21-a4581fce760a" TYPE="xfs"
/dev/sdb1: LABEL="test" UUID="328b2c3a-065f-4ef6-8523-af102f02afd3" TYPE="ext4"
/dev/sr0: UUID="2020-11-04-11-36-43-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
[root@Centos7 ~]# mkdir /test
[root@Centos7 ~]# mount -a
mount: /etc/fstab: parse error: ignore entry at line 3.
mount: /etc/fstab: parse error: ignore entry at line 4.
mount: /etc/fstab: parse error: ignore entry at line 6.
mount: /etc/fstab: parse error: ignore entry at line 7.
#將分區(qū)掛載到指定文件夾
[root@Centos7 ~]# vim /etc/fstab
/etc/fstab
Created by anaconda on Wed Nov 25 10:31:24 2020
#
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=3089f417-1bba-4347-8f21-a4581fce760a / xfs defaults 0 0
UUID=71afae2d-2416-4c68-8375-e27437e32fa3 /boot xfs defaults 0 0
UUID=bb537f14-b824-402e-81c3-63b87a82052a /data xfs defaults 0 0
UUID=bb38c0b6-b4b3-41b8-96f9-30af2315226c swap swap defaults 0 0
UUID=328b2c3a-065f-4ef6-8523-af102f02afd3 /test ext4 acl 0 0
[root@Centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 50G 0 part /data
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 100G 0 part /
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sr0 11:0 1 4.4G 0 rom
4陆淀、創(chuàng)建一個至少有兩個PV組成的大小為20G的名為testvg的VG;要求PE大小為16MB, 而后在卷組中創(chuàng)建大小為5G的邏輯卷testlv;掛載至/users目錄
#第一步:創(chuàng)建分區(qū)考余,屬性為邏輯卷
[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.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (4196352-41943039, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +10G
Partition 2 of type Linux and of size 10 GiB is set
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
[root@Centos7 ~]# fdisk /dev/sdc
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.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (4196352-41943039, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +10G
Partition 2 of type Linux and of size 10 GiB is set
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
[root@Centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 50G 0 part /data
├─sda3 8:3 0 2G 0 part [SWAP]
├─sda4 8:4 0 512B 0 part
└─sda5 8:5 0 100G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 2G 0 part /test
└─sdb2 8:18 0 10G 0 part
sdc 8:32 0 30G 0 disk
└─sdc1 8:33 0 10G 0 part
sr0 11:0 1 4.4G 0 rom
#第二步:創(chuàng)建物理卷(pv)
[root@Centos7 ~]# pvcreate /dev/sd{b2,c1}
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdc1" successfully created.
[root@Centos7 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb2 lvm2 --- 10.00g 10.00g
/dev/sdc1 lvm2 --- 10.00g 10.00g
#第三步:創(chuàng)建物理卷組 (vg)
[root@Centos7 ~]# vgcreate -s 16M testvg /dev/sd{b2,c1}
Volume group "testvg" successfully created
[root@Centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
testvg 2 0 0 wz--n- <19.97g <19.97g
#第四步:創(chuàng)建邏輯卷
[root@Centos7 ~]# lvcreate -n testlv -L 5G testvg
Logical volume "testlv" created.
[root@Centos7 ~]# blkid
/dev/sr0: UUID="2020-11-04-11-36-43-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdb1: LABEL="test" UUID="328b2c3a-065f-4ef6-8523-af102f02afd3" TYPE="ext4"
/dev/sdb2: UUID="jSJtTC-YIss-VkXv-FNjH-n62y-3OhT-9pBFMN" TYPE="LVM2_member"
/dev/sdc1: UUID="FMqJay-13AP-zKVy-NNLg-oTEZ-ecln-VvmE6b" TYPE="LVM2_member"
/dev/sda1: UUID="71afae2d-2416-4c68-8375-e27437e32fa3" TYPE="xfs"
/dev/sda2: UUID="bb537f14-b824-402e-81c3-63b87a82052a" TYPE="xfs"
/dev/sda3: UUID="bb38c0b6-b4b3-41b8-96f9-30af2315226c" TYPE="swap"
/dev/sda5: UUID="3089f417-1bba-4347-8f21-a4581fce760a" TYPE="xfs"
#第五步:創(chuàng)建文件系統(tǒng)
[root@Centos7 ~]# mkfs.xfs /dev/testvg/testlv
meta-data=/dev/testvg/testlv isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@Centos7 ~]# blkid
/dev/sr0: UUID="2020-11-04-11-36-43-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdb1: LABEL="test" UUID="328b2c3a-065f-4ef6-8523-af102f02afd3" TYPE="ext4"
/dev/sdb2: UUID="jSJtTC-YIss-VkXv-FNjH-n62y-3OhT-9pBFMN" TYPE="LVM2_member"
/dev/sdc1: UUID="FMqJay-13AP-zKVy-NNLg-oTEZ-ecln-VvmE6b" TYPE="LVM2_member"
/dev/sda1: UUID="71afae2d-2416-4c68-8375-e27437e32fa3" TYPE="xfs"
/dev/sda2: UUID="bb537f14-b824-402e-81c3-63b87a82052a" TYPE="xfs"
/dev/sda3: UUID="bb38c0b6-b4b3-41b8-96f9-30af2315226c" TYPE="swap"
/dev/sda5: UUID="3089f417-1bba-4347-8f21-a4581fce760a" TYPE="xfs"
/dev/mapper/testvg-testlv: UUID="b093f68c-f893-48e8-8b53-191a98ffa106" TYPE="xfs"
[root@Centos7 ~]# mkdir /users
[root@Centos7 ~]# vim /etc/fstab
#
/etc/fstab
Created by anaconda on Wed Nov 25 10:31:24 2020
#
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=3089f417-1bba-4347-8f21-a4581fce760a / xfs defaults 0 0
UUID=71afae2d-2416-4c68-8375-e27437e32fa3 /boot xfs defaults 0 0
UUID=bb537f14-b824-402e-81c3-63b87a82052a /data xfs defaults 0 0
UUID=bb38c0b6-b4b3-41b8-96f9-30af2315226c swap swap defaults 0 0
UUID=328b2c3a-065f-4ef6-8523-af102f02afd3 /test ext4 acl 0 0
UUID=b093f68c-f893-48e8-8b53-191a98ffa106 /users xfs defaults 0 0
[root@Centos7 ~]# mount -a
mount: /etc/fstab: parse error: ignore entry at line 3.
mount: /etc/fstab: parse error: ignore entry at line 4.
mount: /etc/fstab: parse error: ignore entry at line 6.
mount: /etc/fstab: parse error: ignore entry at line 7.
[root@Centos7 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 487084 0 487084 0% /dev
tmpfs 497852 0 497852 0% /dev/shm
tmpfs 497852 7836 490016 2% /run
tmpfs 497852 0 497852 0% /sys/fs/cgroup
/dev/sda5 104806400 1840400 102966000 2% /
/dev/sda2 52403200 33000 52370200 1% /data
/dev/sdb1 1998538 9236 1960140 1% /test
/dev/sda1 2086912 134324 1952588 7% /boot
tmpfs 99572 0 99572 0% /run/user/0
/dev/mapper/testvg-testlv 5232640 32992 5199648 1% /users