Create Linux software RAID 1 on running centos 5.3

Source: Internet
Author: User

I wanted to write one by myself, but I was shameless to repost it when I saw someone on the Internet who had already written it.

I marked my remarks in red letters.

I also need to add several mdadm commands. In case of any loss, I will try again.

1. Remove a partition from raid

Mdadm-manage/dev/md1-Remove/dev/sda1

2. Disable an MD device.

Mdadm-Stop/dev/md1

See: http://hi.baidu.com/enjoyunix/blog/item/4f152e3d820dfc0abba167ca.html

FT is increasingly fond of Using Soft Raid, because the cheap performance is not much different from hard raid. The most important function is to monitor the disk status. Haha ~~
This articleArticleThis section describes how to install Soft Raid on the centos 5.3 operating system. Start now:

Look at our disk structure

    • /Dev/sda1:/BootPartition, ext3;
    • /Dev/sda2: Swap;
    • /Dev/sda3:/Partition, ext3

The partition structure is exactly the same as mine.

I want to convert the above disks to md0, md1, and md2

    • /dev/md0 (made up of /dev/sda1 and /dev/sdb1 ): /boot partition, ext3;
    • /dev/md1 (made up of /dev/sda2 and /dev/sdb2 ): swap;
    • /dev/md2 (made up of /dev/sda3 and /dev/sdb3 ): / partition, ext3

# DF-H
Filesystem size used avail use % mounted on
/Dev/sda3 9.1 GB 1.1G 7.6g 12%/
/Dev/sda1 190 m 12 m 169 m 7%/boot
Tmpfs 252 m 0 252 m 0%/dev/SHM

# Fdisk-l

Disk/dev/SDA: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes

device boot start end blocks ID system
/dev/sda1*1 25 200781 83 Linux
/dev/sda2 26 90 522112 + 82 Linux swap/Solaris
/dev/sda3 91 1305 9759487 + 83 Linux

Disk/dev/SDB: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Disk/dev/SDB doesn' t contain a valid Partition Table

Install the required software

# Yum install mkinitrd mdadm

Mount modules to the core

# Modprobe linear
# Modprobe multipath
# Modprobe raid0
# Modprobe raid1
# Modprobe RAID5
# Modprobe raid6
# Modprobe raid10

All preparations in the early stage! Start now

1. Mount the disk and partition it.

# Sfdisk-D/dev/SDA | sfdisk/dev/SDB

Attach the/dev/SDA partition to/dev/sdb.

The first time you see sfdisk, remember

# Sfdisk-D/dev/SDA | sfdisk/dev/SDB
Checking that no-one is using this disk right now...
OK

Disk/dev/SDB: 1305 cylinders, 255 heads, 63 sectors/track

Sfdisk: Error: Sector 0 does not have an msdos Signature
/Dev/SDB: unrecognized partition table Type
Old situation:
No partitions found
New Situation:
Units = sectors of 512 bytes, counting from 0

device boot start end # sectors ID system
/dev/sdb1*63 401624 401562 83 Linux
/dev/sdb2 401625 1445849 1044225 82 Linux swap/Solaris
/dev/sdb3 1445850 20964824 19518975 83 Linux
/dev/sdb4 0-0 0 empty
successfully wrote the new Partition Table

Re-reading the partition table...

If you created or changed a DOS partition,/dev/foo7, say, then use dd (1)
To zero the first 512 bytes: dd If =/dev/Zero of =/dev/foo7 BS = 512 COUNT = 1
(See fdisk (8 ).)

Then, change the ID of the three/dev/SDB partitions to fd [RAID device].

# Fdisk/dev/SDB

Press T and 1 then FD
Press T and 2 then FD
Press T and FD
Last W

For the sake of security, the RAID device on/dev/SDB is first converted

# Mdadm-Zero-superblock/dev/sdb1
# Mdadm-Zero-superblock/dev/sdb2
# Mdadm-Zero-superblock/dev/sdb3

I skipped the RAID device initialization step.
2. Create software RAID 1

# Mdadm-create/dev/md0-level = 1-raid-Disks = 2 missing/dev/sdb1
# Mdadm-create/dev/md1-level = 1-raid-Disks = 2 missing/dev/sdb2
# Mdadm-create/dev/md2-level = 1-raid-Disks = 2 missing/dev/sdb3

Format

# Mkfs. ext3/dev/md0
# Mkswap/dev/md1
# Mkfs. ext3/dev/md2

Write/etc/mdadm. conf
# Mdadm-examine-scan>/etc/mdadm. conf

Create a temporary directory

# Mkdir/mnt/md0
# Mkdir/mnt/md2

Mount

# Mount/dev/md0/mnt/md0
# Mount/dev/md2/mnt/md2

Modify/etc/fstab

# Vim/etc/fstab

/Dev/md2/ext3 defaults 1 1/dev/md0/boot ext3 defaults 1 2 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 defaults 0 0/dev/md1 swap defaults 0 0
 
The/partition is automatically mounted to/dev/md2 at startup. The/boot partition is automatically mounted to/dev/md0 at startup.
 
In fact, the change to/etc/fstab is for the next mkinitrd step, and for the future upgrade of the kernel, you can write root =/dev/md2 to grub. conf.
Modify/etc/mtab # Vim/etc/mtab/dev/md2/ext3 RW 0 0 0 proc/proc RW 0 0 0 sysfs/sys sysfs RW 0 0 devpts/dev/PTS devpts RW, gid = 5, mode = 620 0 0/dev/md0/boot ext3 RW 0 0 tmpfs/dev/SHM tmpfs RW 0 0 NONE/proc/sys/fs/binfmt_misc RW 0 0 SunRPC/var /lib/nfs/rpc_pipefs RW 0 0
 
Is it Mao to change/etc/mtab? Don't understand, just do it!
 
Mount/partition to/dev/md2 automatically mount/boot partition to/dev/md0 during startup Modify/boot/GRUB/menu. LST [...] # Add # title centos (2.6.18-128. EL5) # Add # root (hd1, 0) # Add # kernel/vmlinuz-2.6.18-128.el5 Ro root =/dev/md2 # Add # initrd/initrd-2.6.18-128.el5.img # original # title centos (2.6.18-128. EL5) # original # root (hd0, 0) # original # kernel/vmlinuz-2.6.18-128.el5 Ro root = label =/# original # initrd/initrd-2.6.18-128.el5.img
 
Tell grub the root location when the server is enabled. adjust the current partition status of ramdisk # mv/boot/initrd-'uname-R '. IMG/boot/initrd-'uname-R '. img_orig # mkinitrd/boot/initrd-'uname-R '. IMG 'uname-R'
Copy Data # cp-dprx // MNT/md2 # cp-dprx/boot // MNT/md0
 
Is CP required for Mao, can't I directly perform sorting at the end?
 
Is there any concern about this parameter of CP?
 
3. Tell GRUB boot sector location # grubroot (hd0, 0) setup (hd0) Root (hd1, 0) setup (hd1) completed: restart
 
# Reboot
 
4. Add/dev/SDA to software RAID 1 # Press fdisk/dev/SDA to T, 1 then FD to T, 2 then FD to T, and Fd to the last W
 
Add to software RAID 1 # mdadm -- add/dev/md0/dev/sda1 # mdadm -- add/dev/md1/dev/sda2 # mdadm -- add/dev/md2/dev/ sda3
View the reconstruction of software RAID 1 # Cat/proc/mdstatpersonalities: [raid1] md0: Active raid1 sda1 [0] sdb1 [1] 200704 blocks [2/2] [UU] md1: active raid1 sda2 [0] sdb2 [1] 522048 blocks [2/2] [UU] md2: active raid1 sda3 [2] sdb3 [1] 9759360 blocks [2/1] [_ u] [===> ............... .] recovery = 22.8% (2232576/9759360) finish = 2.4 min speed = 50816 K/secunused devices: <none>
 
Write the software RAID 1 status to/etc/mdadm. conf # mdadm -- examine -- Scan>/etc/mdadm. conf after synchronization.
 5. better Modify/boot/GRUB/menu. listtitle centos (2.6.18-128. EL5) Root (hd1, 0) kernel/vmlinuz-2.6.18-128.el5 Ro root =/dev/md2 initrd/initrd-2.6.18-128.el5.imgtitle centos (2.6.18-128. EL5) Root (hd0, 0) kernel/vmlinuz-2.6.18-128.el5 Ro root =/dev/md2 initrd/initrd-2.6.18-128.el5.img tells grub that both disks can be started at any time. 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.