如何在Linux中配置RAID(6)

We can't see swap anywhere, though. So we need another utility to check it. We'll use swapon.

虽然我们看不到任何交换区。因此,我们需要另外工具来检查一下。我们将使用swapon。

swapon

swapon

swapon (and its sister swapoff) is used to start swap on files/devices, and display status of currently used swap areas. swapon -s will display all used swap areas, their type, size, usage, and priority.

swapon(它的同类swapoff)用于开启文件系统/设备上的交换分区,显示目前使用交换区的状态。swapon的命令-s显示所有已用交换区,它们的类型、大小、使用和优先级。

As you can se below, we have a 1GB swap device /dev/md1, which consists of two physical partitions (sda5 and sdb5) in a stripe configuration.

正如你在下面看到,我们在/dev/md1上有1GB的交换区,他们是由一个条带配置的两个物理分区组成。

RAID & GRUB

RAID & GRUB

Here comes the big question, how does GRUB fit into the RAID picture? Before we can answer that question, you need to read my GRUB tutorial. Once you understand how GRUB works, you'll be able to ponder the question raised here. I'm sorry, but it's a must.

这里有个大问题,GRUB如何适合RAID?在我们回答这个问题以前,你需要阅读我的GRUB的教程。一旦你了解了GRUB如何工作的,你就可以思考这里提出的问题。很抱歉,这是必须的。

Throughout this section, I will assume you have read the very long, thorough and detailed GRUB tutorial.

在本节中,我假设你已经阅读了很长,彻底的详细的GRUB教程。

Basically, GRUB is a bootloader that allows multiple operating systems to be run on the same system. GRUB works by placing a piece of its code into the Master Boot Record (MBR) and tells the system where to look for configuration files on which operating system to boot.

基本上,GRUB是引导程序,允许多个操作系统在同一系统上运行。GRUB通过放置其代码到主引导(MBR),告诉系统哪里找到操作系统启动的配置文件。

When you're using the conventional partitioning layout, the configuration is simple. GRUB is installed to the device sector 0 and that's it. For instance, GRUB is installed to sda. End of story.

当你使用传统分区设置,配置很简单的。GRUB安装在设备扇区0,仅此而已。例如,GRUB安装到sda。就此结束。

When you're using RAID for the root partition, there is more than one device involved. The question is, where does GRUB go? sda? sdb? Both?

当你在根分区使用RAID,包括了一个以上的设备。问题时,GRUB哪里去了?sda?sdb?两者兼而有之?

The answer depends on the type of RAID you want. I used mirror for the root partition, which means we have two identical copies of everything on the system, including the sector 0, which contains GRUB stage 1. Therefore, we elegantly avoid the question. GRUB is installed on both devices. Reading any which MBR on either disk provides us with the whole set of information required to boot the system.

问题取决于你想要的RAID类型。我在根分区使用镜像,这意味着我们在所有系统上有两个相同的副本,包括扇区0,包含了GRUB第一阶段。因此,我们很好地避免了这个问题。GRUB是在两个系统上都安装的。读任何磁盘上MBR给我们提供了所有启动系统的信息。

We can confirm this by looking for stage1 (using the find command in GRUB menu):

我们通过第一阶段确认了这一点(在GRUB菜单中使用find命令):

We'll talk about what happens if RAID 0 is used a little later on.

如果RAID0用了小会儿,我们讨论将会发生什么。

GRUB menu

GRUB菜单

The second question is, what about the GRUB menu?

Let's take at the GRUB menu. GRUB menu, part of GRUB stage2, is usually located on the /boot or / partition of the first boot device, inside grub directory.

As you can see, GRUB menu takes into consideration the higher hierarchy of RAID. The root is called from an MD device and not the underlying hd/sd devices. For all practical purposes, the setup is completely transparent when it comes to stage2. The only thing we need to concern ourselves is stage1 that goes into MBR.

So, let's go back to the first question. Where does GRUB go? The best way for you to understand and solve this problem is to treat RAID devices as your partitions. GRUB needs to be in the MBR of the first boot disk. As simple as that.

This means that if you're using RAID1, there are no issues, as the sector exists "equally" on all RAID array devices. If you're using a configuration where only partial information exists on each device (like RAID0 or RAID5), the system will not be able to deduct the whole of information by reading the MBR on just one device.

So, the answer is: you will have to install GRUB on all RAID devices. If you're using a mirror configuration, this is done for you. If you're using stripe, you'll have to do it manually.

Install GRUB manually on RAID devices

You can do this in several ways: using a utility like Super Grub Disk (the easy way) or manually (the hard way) from a live CD utility. The best thing to do would be to do this after the installation is complete, before rebooting.

The sequence of steps required to accomplish the task is very simple. First, you'll have to find all available stage1. Then, you will have to setup GRUB into each one of them. That's all!

So, let's look for stage1. This needs to be done from a live CD environment or during a GRUB boot:

find /boot/grub/stage1

We've seen what the answer looks like above:

If all the devices included in the array get listed, you're ok. If not, you will have to install GRUB on each one.

For each device listed above, perform the following steps:

root (hdX,Y)

setup (hdX)

The values X and Y take the disk number and partition number where the root is installed. For example, in our case, we have the root partition on sda1 and sdb1. This means that we have to run the commands for (hd0,0) and (hd1,0).

Do not be tempted to look for menu.lst, because this one is deceiving. You might get a "right" answer that it is located on both partitions, but stage1 might not be installed properly.

You can also "brute-force" your way with grub-install command, if you know where the root is expected to be. For more details how to do this, please refer to the GRUB tutorial.

Summary

So, what do we have here?

If you're installing RAID 1 (mirror), GRUB setup will be transparent to you.

If you're installing RAID 0 (stripe), you will have to manually installed GRUB as demonstrated above.

Alternatively, you may also want to setup a small (~100-200MB) boot partitions in the classic way, then use RAID for other partitions. This is similar to what Fedora does with its LVM. A small sda1 boot is used and LVM is spread on sda2.

Which brings us to GParted ...

GParted & RAID

In the GParted tutorial, we've seen that GParted can see RAID devices, but it cannot manipulate them. Here's a screenshot of our current setup:

Notice the raid flag. Furthermore, notice the unknown filesystem on sda6. This is because we're using stripe and the information contained on the partition is only half the picture. The other half is located on sdb6. Therefore, GParted is unable to identify the filesystem properly.

GParted is a powerful tool, but it is unsuitable for handling RAID.

Advanced configurations

We've seen a lot of work done, but we did not see any commands executed. Which is OK. For most people, for most practical purposes, RAID should be transparent. However, if you want to be able to control your RAID at all times, you will have to muck your hands a bit in the command line hocus pocus.

mdadm

mdadm is a powerful command-line utility to managing RAID devices. It has seven modes of operation, which include assemble, build, create, monitor, grow, manage, and misc.

So let's see how we can use mdadm to achieve what we did above.

Create MD device

Remember the wizard we ran through when we created our mirror array on md0? Well, here it is, in text form:

Let's disassemble the command and see what it means:

mdadm --create --verbose /dev/md0 --level=raid1 ->

-> --raid-devices=2 /dev/sda1 /dev/sdb1

We are creating a new device called /dev/md0. It is a RAID 1 device with 2 devices in it, sda1 and sdb1. Simple eh?

After you hit Enter, you'll see the device created and then synced. The synchronization is the process that takes after the RAID devices are created. Effectively, it creates the required data structure on all RAID devices.

If we check mdstat, we see the old familiar picture:

Similarly, we can stop RAID devices, fail them, assemble them, and so forth. Mastering the mdadm utility takes time, but it gives you a lot of power and freedom when it comes to using Linux software RAID.

Fail/remove device

If you want to break apart a RAID, you will first have to fail its members and then remove them. On active partitions used by the operating systems, this may not be possible in-vivo and will require a reboot.

如果你想要拆开一个RAID,你必须首先失效它的成员,然后移除它们。操作系统已用的有效分区上这是不可能的,并且要求重启。

Here's an example where we fail a device:

这是我们使设备失效的例子:

And when we print /proc/mdstat, we can now see that our targeted RAID device no longer uses both its members. The information in square brackets has changed. We only have one used device, with the other set as faulty. [2/2] now shows [2/1] and [UU] now shows [U_], indicating the second device (listed on the right) is no longer being used, as it has been set as faulty.

当我们打印/proc/mdstat,我们可以看到我们目标RAID设备不再使用它的成员。方括号中的信息已经更改。我们仅有一个已用设备,另一套发生故障。[2/2]变成了[2/1],并且[UU]变成了[U_],指示第二块设备(在右边列出)不再使用,因为它已被错误设置。

In reality, this might happen should the disk die or a partition get corrupted for some reason.

事实上,这可能会发生磁盘死亡或分区因为某种原因损坏。

After that we can remove it ... and then, for fun, re-add it. Here's a screenshot showing the recovery progress after sdb1 was re-added. The RAID device is being rebuilt, with the data from sda1 being cloned over to sdb1.

这之后我们可以移除它了。。。然后,好玩,重新添加。这是显示重新添加sdb1之后恢复进度的截图。RAID设备被重新安装,sda1的数据被克隆到了sdb1。

For more details, please read the man page for mdadm.

更多详细信息,请阅读mdadm的帮助页面。

Other

其他

In general, there are several things you should consider before deploying RAID. These concern the cost, safety, performance, but also software compatibility.

一般来说,在部署RAID之前有几件事情你应该考虑。这些考虑到了成本、安全、性能,但也包括软件的兼容性。

You may need to check whether your imaging software, if you're using one, that is, is compatible with RAID devices. Just like when we configured partitions with GParted, we had to manually change the Inode size for our Ubuntu installation to make the partitions compatible with Acronis True Image software, which requires Inode size of 128 bytes.

你可能需要检查是否有镜像工具,如果你使用了一个,那就是,要与RAID设备兼容。就像我们的GParted分区配置一样,我们必须手动更改Ubuntu安装的节点大小,使得分区与Acronis True Image软件兼容,这要求节点大小为128字节大小。

With RAID, similar adjustments may be required.

使用RAID,要求做类似的调整。

Plan ahead, make sure your setup will be flexible enough to suit your needs years ahead. Make sure you can use your backup and rescue tools effectively and reliably on systems deployed on RAID devices. Make sure you do not create impossible setups where you have no ability to change things save for a complete reinstall.

提前计划,确保你的安装足够灵活以适应未来几年的需要。确保你可以有效地使用备份和恢复工具,和在RAID设备上部署系统的可靠性。确保你没有创建不可用的安装,因为你没有能力更改为完整的重新安装保存相应的东西。

That said, this concludes the tutorial.

尽管如此,本教程到此结束。

Conclusion

总结

Working with RAID is an advanced task, but it can be managed. Hopefully, this tutorial cleared up things a bit.

使用RAID工作是一种先进的任务,但它是可以管理的。希望,本教程可以清理一点点东西。

Alongside the knowledge you have gained on working with the GRUB bootloader and GParted partitioning software, the RAID tutorial should give you the skills needed required to safely and with confidence wade into the waters of Linux system administration.

除了你已有的GRUB引导程序和GParted分区软件的知识,RAID教程应该给你需要的技能,涉及Linux系统管理领域的技能。

In the future, we'll tackle more great stuff, including LVM, the iptables firewall and many other exciting projects. And if you have suggestions, feel free to email me.

将来,我们将处理更加巨大的东西,包括LVM,iptables防火墙和其他许多令人激动的项目。如果你有什么建议,随时给我发电子邮件。

Have fun.

玩得开心!

本文如何在Linux中配置RAID-教程英文版教程下载在

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywzpd.html