In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what the disaster recovery technology of Linux system is, which is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
There are many distributions of Linux, and now it is more and more widely used. At the same time, it is also faced with the potential risk of system failure. This paper will take the release version of RHEL6 as an example to introduce several Linux disaster recovery technologies and methods in detail to ensure the safe recovery of Linux system.
Before introducing the Linux disaster recovery method, let's take a look at MBR, whose full name is Master Boot Record, that is, the master boot record of the hard disk. It consists of three parts, the main boot program, the hard disk partition table and the hard disk valid flag. The main boot program (Bootloader) occupies 446 bytes in the total 512 bytes of the main boot sector. the second part is the hard disk partition table, which accounts for 64 bytes, in which the number of partitions on the hard disk and the size of each partition are recorded. The third part is the effective logo of the hard disk, accounting for 2 bytes. As shown in the figure:
Figure 1. MBR
System hard disk partition table is damaged
The Linux server in the production environment may cause the hard disk partition table to be destroyed because of the virus or accidental power outage. Usually, we need to back up the partition table information before restoring the hard disk partition table. Generally, we use USB external devices to back up the partition table of the host hard disk.
After mounting the USB device on the host, we check the current disk device of the system:
[root@FCoE] # fdisk-l Disk / dev/sda: 43.0 GB, 429916000 bytes 255heads, 63 sectors/track 5226 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I size O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00032735 Device Boot Start End Blocks Id System / dev/sda1 * 1 17 131072 83 Linux Partition 1 does not end on cylinder boundary. / dev/sda2 17 147 1048576 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. / dev/sda3 5227 40803328 83 Linux Disk / dev/sdb: 2147 MB, 2147483648 bytes 255heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk / dev/sdb doesn't contain a valid partition table
Now let's create a new partition on the sdb device:
[root@FCoE] # 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 0xcdd48395. 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) 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-261, default 1): Using default value 1 Last cylinder, + cylinders or + size {K default G} (1-261, default 261): Using default value 261 Command (m for help): P Disk / dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I size O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xcdd48395 Device Boot Start End Blocks Id System / dev/sdb1 1261 2096451 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl () to re-read partition table. Syncing disks.
Create a file system on the new partition sdb1:
[root@FCoE] # mkfs.ext3 / dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131072 inodes, 524112 blocks 26205 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768,98304,163840,229376 294912 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 24 mounts or 180 days, whichever comes first. Use tune2fs-c or-i to override.
Mount the new file system:
[root@FCoE ~] # mount / dev/sdb1 / mnt/
Usually we back up the hard disk partition table by backing up the MBR of the hard disk:
[root@FCoE] # dd if=/dev/sda of=/mnt/sda.mbr bs=512 count=1 1'0 records in 1'0 records out 512 bytes (512 B) copied, 0.000777948 s, 658 kB/s
Now let's write zero hard disk partition table to achieve the result of similar partition table being corrupted:
[root@FCoE ~] # dd if=/dev/zero of=/dev/sda bs=1 count=64 skip=446 seek=446 64 bytes 0 records in 64 bytes 0 records out 64 bytes (64 B) copied, 0.00160668 s, 39.8 kB/s
Query the partition information on the hard drive sda and find that it no longer contains any partitions:
[root@FCoE] # fdisk-l Disk / dev/sda: 43.0 GB, 42991616000 bytes 255heads, 63 sectors/track, 5226 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I bytes Sector size O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00032735 Device Boot Start End Blocks Id System Disk / dev/sdb: 2147 MB, 2147483648 bytes 255heads, 63 sectors/track 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I use O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xcdd48395 Device Boot Start End Blocks Id System / dev/sdb1 1261 2096451 83 Linux
When the host hard disk partition table is lost, GRUB will enter command line mode because the configuration file cannot be found after rebooting:
Figure 2. Partition table missing
Next, we mount the RHEL6 installation disk, also connect to the USB device we backed up before, then restart the host, select CD-ROM as the first boot device, and select "Rescue installed system" after boot.
Figure 3. Choose to rescue
Following the prompts, we finally choose a shell.
Figure 4. Select shell
We queried the system disk information and found that the hard disk device sda did not contain any partitions.
Bash-4.1# fdik-l Disk / dev/sda: 43.0 GB, 429916000 bytes 255heads, 63 sectors/track, 5226 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I bytes O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00032735 Device Boot Start End Blocks Id System Disk / dev/sdb: 2147 MB, 2147483648 bytes 255heads, 63 sectors/track 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I use O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xcdd48395 Device Boot Start End Blocks Id System / dev/sdb1 1261 2096451 83 Linux
Let's restore its hard disk partition table, create a directory and mount the previously backed up USB device, and we see that its device name is / dev/sdb.
Bash-4.1# mount / dev/sdb1 / usb bash-4.1# ls / usb lost+found sda.mbr
Restore the hard disk partition table of the hard disk device sda from the original backed-up sda.mbr file:
Bash-4.1# dd if=/usb/sda.mbr of=/dev/sda bs=1 count=64 skip=446 seek=446 64 copied 0 records in 64 4 0 records out 64 bytes (64 B) copied, 0.038358 s, 4.6 kB/s
Query the system disk information again:
Bash-4.1# fdisk-l Disk / dev/sda: 43.0 GB, 429916000 bytes 255heads, 63 sectors/track, 5226 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I bytes O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00032735 Device Boot Start End Blocks Id System / dev/sda1 * 1 17 131072 83 Linux Partition 1 does not end on cylinder boundary. / dev/sda2 17 147 1048576 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. / dev/sda3 5227 40803328 83 Linux Disk / dev/sdb: 2147 MB, 2147483648 bytes 5227 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xcdd48395 Device Boot Start End Blocks Id System / dev/sdb1 1261 2096451 83 Linux
The partition table of the hard disk device sda has been restored and the system can boot normally after reboot.
System GRUB damage
Similarly, we can write zero Bootloader to achieve the result of GRUB being destroyed:
[root@FCoE grub] # dd if=/dev/zero of=/dev/sda bs=446 count=1 1'0 records in 1'0 records out 446 bytes (446 B) copied, 0.0017583 s, 254 kB/s
After reboot, the system will get stuck in "Booting from Hard Disk …" because the GRUB cannot be found.
Mount the system installation CD and select enter Rescue mode, then restore GRUB:
Bash-4.1# chroot / mnt/sysimage sh-4.1# grub grub > root hd (0) grub > setup (hd0) grub > quit
Figure 5. Restore GRUB
After rebooting the host, the system boots normally.
The system kernel file is missing
The system loses the kernel kernel file and will prompt that the file cannot be found after rebooting.
Figure 6. Kernel loss
Mount the system installation disk into rescue mode and check the / boot directory to find no kernel files.
Bash-4.1# chroot / mnt/sysimage bash-4.1# ls / boot ls config-2.6.32-71.el6.x86_64 lost+found efi symvers-2.6.32-71.el6.x86_64.gz grub System.map-2.6.32-71.el6.x86_64 initramfs-2.6.32-71.el6.x86_64.img
Force a reinstall of the kernel from the mounted system installation disk:
Sh-4.1# mount-o loop / dev/sr0 / media sh-4.1# cd / media/Server/Packages sh-4.1# rpm-ivh-- force kernel-2.6.32-71.el6.x86_64.rpm warning: kernel-2.6.32-71.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature,\ key ID fd431d51: NOKEY Preparing... # [100%] 1:kernel #
A new kernel file vmlinuz-2.6.32-71.el6.x86_64 has been generated in the / boot directory
Sh-4.1## ls / boot config-2.6.32-71.el6.x86_64 lost+found efi symvers-2.6.32-71.el6.x86_64.gz grub System.map-2.6.32-71.el6.x86_64 initramfs-2.6.32-71. El6.x86_64.img vmlinuz-2.6.32-71.el6.x86_64
After rebooting the host, the system boots normally.
The system image file is missing
The system loses the image file, and the host starts up with a black screen.
Figure 7. Image loss
Mount the system installation disk into rescue mode and check the / boot directory to find no image files.
Bash-4.1# chroot / mnt/sysimage sh-4.1# ls / boot config-2.6.32-71.el6.x86_64 symvers-2.6.32-71.el6.x86_64.gz efi System.map-2.6.32-71.el6.x86_64 grub vmlinuz-2.6.32-71.el6.x86_64 lost+found
Regenerate the image file initramfs-2.6.32-71.el6.x86_64.img.
Sh-4.1# cd / boot sh-4.1# mkinit sh-4.1# ls config-2.6.32-71.el6.x86_64 lost+found efi symvers-2.6.32-71.el6.x86_64.gz grub System.map-2.6.32-71.el6. X8664 initramfs-2.6.32-71.el6.x86_64.img vmlinuz-2.6.32-71.el6.x86_64
After rebooting the host, the system boots normally.
System / boot partition is damaged
Generally speaking, the system / boot partition is corrupted and we will try to repair the file system first. If the file system corruption cannot be repaired, then we can follow the above method to create a new / boot partition, reinstall the kernel and image, then install GURB and manually edit the boot menu to restore the system to boot normally. Usually we need to follow these steps to recover.
Create Partition
A more serious situation is that the / boot partition is completely corrupted and the boot device cannot be found at startup.
Figure 8. Boot partition is damaged
After mounting the installation disk, enter the rescue mode, check the partition situation, and find that the partition / dev/sda1 does not exist.
Bash-4.1# Disk / dev/sda: 43.0 GB, 429916000 bytes 255heads, 63 sectors/track, 5226 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System / dev/sda2 17 147 1048576 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. / dev/sda3 5227 40803328 83 Linux Disk / dev/sdb: 2147 MB, 2147483648 bytes 5227 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xcdd48395 Device Boot Start End Blocks Id System / dev/sdb1 1261 2096451 83 Linux
Create a new partition and set it as the boot partition.
Bash-4.1# fdisk / dev/sda 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-5226, default 1): Using default value 1 Last cylinder, + cylinders or + size {K default G} (1-16, default 16): Using default value 16 Command (m for help): a Partition number (1-4): 1 Command (m for help): P Disk / dev/sda: 43.0 GB, 429916000 bytes 255 heads 63 sectors/track, 5226 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I size O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System / dev/sda1 * 1 16 128488 + 83 Linux / dev/sda2 17147 1048576 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. / dev/sda3 1475227 40803328 83 Linux Command (m for help): w The partition table has been altered!
Restart the host to update the partition table, then enter rescue mode and create a file system on our newly created partition.
Bash-4.1# mkfs.ext4 / dev/sda1 Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 32128 inodes, 128488 blocks 6424 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 16 block groups 8192 blocks per group, 8192 fragments per group 2008 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 38 mounts or 73729 days, whichever comes first. Use tune2fs-c or-i to override.
Install the kernel image file
We install the kernel and image files through the aforementioned method.
Bash-4.1# chroot / mnt/sysimage sh-4.1# mount / dev/sda1 / boot sh-4.1# mount-o loop / dev/sr0 / media sh-4.1# cd / media/Server/Packages sh-4.1# rpm-ivh-- force kernel-2.6.32-71.el6.x86_64.rpm warning: kernel-2.6.32-71.el6.x86_64.rpm:\ Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... # [100%] 1:kernel #
Install GRUB
We install GRUB on the hard drive device sda.
Sh-4.1# grub-install / dev/sda Installation finished. No error reported. This is the contents of the device map / boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (fd0) / dev/fd0 (hd0) / dev/sda (hd1) / dev/sdb
Edit Boot menu
Because we have created a new partition, its corresponding UUID will change. You can query the partition's UUID by using the command blkid.
Bash-4.1# blkid / dev/loop0: TYPE= "squashfs" / dev/sda2: UUID= "7b1e0fac-ff06-492c-848d-497e2a38c54e" TYPE= "swap" / dev/sda3: UUID= "ef89764e-04ff-4f26-ae82-dcab267ecc66" TYPE= "ext4" / dev/sdb1: UUID= "2b824352-df2a-44c6-a547-838d46f526fa" SEC_TYPE= ext2 "TYPE=" ext3 "/ dev/loop1: LABEL=" RHEL_6.0 x8634 Disc 1 "TYPE=" iso9660 "/ dev/sda1: UUID=" Cec964af-1618-48ff-ac33-4ef71b9d3265 "TYPE=" ext4
The above sda3 is the root partition, edit the / boot/grub/grub.conf file to update its corresponding UUID, which is as follows.
Title Red Hat Enterprise Linux 6 root (hd0,0) kernel / vmlinuz-2.6.32-71.el6.x86_64\ root=UUID=ef89764e-04ff-4f26-ae82-dcab267ecc66 rhgb quiet initrd / initramfs-2.6.32-71.el6.x86_64.img
Update / etc/fstab
Similarly, we need to update the new UUID corresponding to the / boot partition in / etc/fstab, which is as follows.
# # / etc/fstab # Created by anaconda on Sun Mar 18 04:35:07 2012 # # 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=ef89764e-04ff-4f26-ae82-dcab267ecc66 / ext4 defaults 1 1 UUID=cec964af-1618-48ff-ac33-4ef71b9d3265 / boot ext4 defaults 1 2 UUID=7b1e0fac-ff06-492c-848d-497e2a38c54e swap swap defaults 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
Now that our recovery steps are complete, a list of our configured systems can be seen in the GRUB after rebooting the host.
Figure 9. GRUB menu
At this point, the / boot partition has been restored and the system can boot normally.
Figure 10. System startup
The above content is what is the disaster recovery technology of Linux system? have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.