Jump to content
Sign in to follow this  
fajw

Replacing an HDD as part of RAID in Linux

Recommended Posts

How do I replace an HDD as part of RAID (levels 1 and 5) in Linux? The state is "removed".

 

[root@server ~]# mdadm --query --detail /dev/md0
/dev/md0:
		Version : 1.0
  Creation Time : Tue Dec 25 17:33:44 2012
	 Raid Level : raid1
	 Array Size : 204788 (200.02 MiB 209.70 MB)
  Used Dev Size : 204788 (200.02 MiB 209.70 MB)
   Raid Devices : 5
  Total Devices : 4
	Persistence : Superblock is persistent

	Update Time : Sat Apr 27 14:11:04 2013
		  State : clean, degraded
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

		   Name : server.workgroup:0  (local to host server.workgroup)
		   UUID : 70234d6d:553332d3:1b3e2387:757a6c21
		 Events : 1138

	Number   Major   Minor   RaidDevice State
	   0	   8		2		0	  active sync   /dev/sda2
	   1	   8	   18		1	  active sync   /dev/sdb2
	   2	   0		0		2	  removed
	   3	   8	   50		3	  active sync   /dev/sdd2
	   4	   8	   66		4	  active sync   /dev/sde2
[root@server ~]# mdadm --query --detail /dev/md1
/dev/md1:
		Version : 1.1
  Creation Time : Tue Dec 25 17:33:45 2012
	 Raid Level : raid5
	 Array Size : 11686680576 (11145.29 GiB 11967.16 GB)
  Used Dev Size : 2921670144 (2786.32 GiB 2991.79 GB)
   Raid Devices : 5
  Total Devices : 4
	Persistence : Superblock is persistent

  Intent Bitmap : Internal

	Update Time : Sat Apr 27 14:34:39 2013
		  State : active, degraded
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

		 Layout : left-symmetric
	 Chunk Size : 512K

		   Name : server.workgroup:1  (local to host server.workgroup)
		   UUID : cf67453c:b02d17bb:0940660f:c0508565
		 Events : 3337664

	Number   Major   Minor   RaidDevice State
	   0	   8		3		0	  active sync   /dev/sda3
	   1	   8	   19		1	  active sync   /dev/sdb3
	   2	   0		0		2	  removed
	   3	   8	   51		3	  active sync   /dev/sdd3
	   5	   8	   67		4	  active sync   /dev/sde3

I physically replaced the HDD but how to I put it back in the RAID?

 

Thanks.

Share this post


Link to post
Share on other sites

Make sure you get the devices correct (I've made a guess based on your output) and assumed the new disk will have the same device ID. I take no responsibility for loss of data if you get this wrong! ;)

 

First remove the old disk from the array(s):

mdadm --manage /dev/md0 --remove /dev/sdc2
mdadm --manage /dev/md1 --remove /dev/sdc3

Second ensure the new disk/partition is the same size as the existing partitions (Linux MD arrays are across partitions rather than disks).

sfdisk -d /dev/sda | sfdisk /dev/sdc

Next add the new disk to each array

mdadm --manage /dev/md0 --add /dev/sdc2
mdadm --manage /dev/md1 --add /dev/sdc3

Finally you will need to wait for the new partitions to synchronise with the rest of the array.

Edited by SledgY

Share this post


Link to post
Share on other sites

Thanks, SledgY.

 

Just one more thing:

[root@server ~]# sfdisk -d /dev/sda | sfdisk /dev/sdc
Checking that no-one is using this disk right now ...

WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util sfdisk doesn't support GPT. Use GNU Parted.

OK

Disk /dev/sdc: 364801 cylinders, 255 heads, 63 sectors/track
 /dev/sdc: 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/sdc1			 1 4294967295 4294967295  ee  GPT
/dev/sdc2			 0		 -		  0   0  Empty
/dev/sdc3			 0		 -		  0   0  Empty
/dev/sdc4			 0		 -		  0   0  Empty
Warning: partition 1 does not end at a cylinder boundary

sfdisk: I don't like these partitions - nothing changed.
(If you really want this, use the --force option.)
Is it okay for me to just proceed with the last step?

Share this post


Link to post
Share on other sites

Unfortunately sgisk isn't installed and I don't know how to install it.

Share this post


Link to post
Share on other sites

Unfortunately sgisk isn't installed and I don't know how to install it.

sgdisk is contained in the gdisk package.

Share this post


Link to post
Share on other sites

I installed the rpm file apparently (rpm -ivh gptfdisk-0.8.6-1.src.rpm) but I can't run sgdisk ("command not found").

Share this post


Link to post
Share on other sites

I installed the rpm file apparently (rpm -ivh gptfdisk-0.8.6-1.src.rpm) but I can't run sgdisk ("command not found").

Yeah that is strange.

 

I've installed the RPM you mentioned and sgdisk is not installing, also installing gdisk from the repository is also not install sgdisk.

 

NB: Please don't use RPM's on Debian / Ubuntu it can dirty up the system to no end.

Use the package manager to install instead.

 

You are just copying an entire disks partition table to another disk right?

 

If the disks are the same size why not try dd?

 

http://linux.die.net/man/1/dd

Share this post


Link to post
Share on other sites

The DD method should work although the GUID refresh would be required.

 

Can't offer any more for rpm based systems, not familiar with Redhat packages.

Share this post


Link to post
Share on other sites

Sorry guys; I'm lost. I've been looking at man pages and stuff but I don't understand it. How would I go about using dd to do what I want?

Share this post


Link to post
Share on other sites

The DD method should work although the GUID refresh would be required.

 

Can't offer any more for rpm based systems, not familiar with Redhat packages.

Debian based system, so shouldn't be using RPM at all.

 

Sorry guys; I'm lost. I've been looking at man pages and stuff but I don't understand it. How would I go about using dd to do what I want?

Ok Fajw,

 

DD is a seriously useful command that let's you copy a block device block by block.

 

Let's start with the assumption you have two block devices:

 

/dev/sda

/dev/sdb

 

You want to copy the entire partition table of SDA to SDB.

 

So let's look at the below command:

 

dd if=/dev/sda of=/dev/sdb bs=32M

 

"if" is your source, "of" is the destination.

 

bs is the block size, won't go into to much detail here but if your disks are newish you can get away with a block size of 32M, 16M is safer and lower is safer than that (i.e 8M, 6M, 4M, 1M)

 

As DD copies the entire block device it will copy everything.... partition tables, free space... even erroneous data.

 

I just realised.

 

You can simply do:

 

sfdisk -d /dev/sda | sfdisk /dev/sdb

 

to copy your data rather than using DD.

 

and then re-add it via madm.

 

Just to let you know fajw:

 

if you run the same command for dd but replace the target for of to /<directory name>/<name>.iso

 

You have an iso file... very useful and you can specify a cd/dvd drive as the source :)

Share this post


Link to post
Share on other sites

You can simply do:

 

sfdisk -d /dev/sda | sfdisk /dev/sdb

That was my initial suggestion, unfortunately sfdisk does not support GPT (GUID Partion Table) hence the suggestion of using sgdisk which does.

 

Back to the op, you need to install the the gdisk package the command is:

sudo apt-get install gdisk

You can then complete the instructions I posted earlier.

Share this post


Link to post
Share on other sites

You can simply do:

 

sfdisk -d /dev/sda | sfdisk /dev/sdb

That was my initial suggestion, unfortunately sfdisk does not support GPT (GUID Partion Table) hence the suggestion of using sgdisk which does.

 

Back to the op, you need to install the the gdisk package the command is:

sudo apt-get install gdisk

You can then complete the instructions I posted earlier.

 

Yeah, he installed gdisk.

 

For some reason it has not installed sgdisk on his system.

 

I've tested it and had the same issue on a test system at work using both the apt package and the rpm he was referring to.

 

sfdisk is available on the install i ran so he can use that.

Share this post


Link to post
Share on other sites

Thanks for the help, guys. I'm currently running

dd if=/dev/sdb of=/dev/sdc bs=32M
.

Share this post


Link to post
Share on other sites

Thanks for the help, guys. I'm currently running

dd if=/dev/sdb of=/dev/sdc bs=32M
.

Let us know how it goes.

Share this post


Link to post
Share on other sites

You can simply do:

 

sfdisk -d /dev/sda | sfdisk /dev/sdb

That was my initial suggestion, unfortunately sfdisk does not support GPT (GUID Partion Table) hence the suggestion of using sgdisk which does.

 

Back to the op, you need to install the the gdisk package the command is:

sudo apt-get install gdisk

You can then complete the instructions I posted earlier.

 

Yeah, he installed gdisk.

 

For some reason it has not installed sgdisk on his system.

 

I've tested it and had the same issue on a test system at work using both the apt package and the rpm he was referring to.

 

sfdisk is available on the install i ran so he can use that.

 

Might be an older package? I just tried the same on Ubuntu 12.04 and the sgdisk app was included.

 

Could also be that /sbin is not in your path (common on older debian systems unless you are root) check that you can't run this tool with /sbin/sgdisk

 

Either way you are going to have problems with multiple drives in the same machine with partitions with matching GUIDs, the second step of the partition clone is to generate new GUIDs for the cloned drive. Unfortunately the command to do this uses sgdisk.

sgdisk -G /dev/sdc

Share this post


Link to post
Share on other sites

You can simply do:

 

sfdisk -d /dev/sda | sfdisk /dev/sdb

That was my initial suggestion, unfortunately sfdisk does not support GPT (GUID Partion Table) hence the suggestion of using sgdisk which does.

 

Back to the op, you need to install the the gdisk package the command is:

sudo apt-get install gdisk

You can then complete the instructions I posted earlier.

 

Yeah, he installed gdisk.

 

For some reason it has not installed sgdisk on his system.

 

I've tested it and had the same issue on a test system at work using both the apt package and the rpm he was referring to.

 

sfdisk is available on the install i ran so he can use that.

 

Might be an older package? I just tried the same on Ubuntu 12.04 and the sgdisk app was included.

 

Could also be that /sbin is not in your path (common on older debian systems unless you are root) check that you can't run this tool with /sbin/sgdisk

 

Either way you are going to have problems with multiple drives in the same machine with partitions with matching GUIDs, the second step of the partition clone is to generate new GUIDs for the cloned drive. Unfortunately the command to do this uses sgdisk.

sgdisk -G /dev/sdc

Could be, the Ubuntu machine here is a little bit old but the package installed was the latest.

 

I looked at it yesterday in terms of compiling sgdisk but ran into some dependency hell.

Share this post


Link to post
Share on other sites

So should I cancel the command:

dd if=/dev/sdb of=/dev/sdc bs=32M
?

Share this post


Link to post
Share on other sites

So should I cancel the command:

dd if=/dev/sdb of=/dev/sdc bs=32M
?

No keep going.

 

You can still use gdisk to change the GUID.

 

Check the man page for gdisk... search for random

Share this post


Link to post
Share on other sites

Sorry, guys; another complication: I had to restart the PC I was using Putty on and I'm not sure what to do now. I don't know where it was up to. What should I do? I really appreciate the help.

Share this post


Link to post
Share on other sites

It would have stopped part way through, you can just start the process again, no harm done.

 

For long running operation I'd suggest using nohup or screen.

 

nohup (or no hangup) basically runs the process in the background and dump the output into file, the advantage is that if you disconnect it keeps running. Basically put nohup before any command you wish to run.

 

By default the output is written to nohup.out in your home directory. For more info:

man nohup

Share this post


Link to post
Share on other sites

It would have stopped part way through, you can just start the process again, no harm done.

 

For long running operation I'd suggest using nohup or screen.

 

nohup (or no hangup) basically runs the process in the background and dump the output into file, the advantage is that if you disconnect it keeps running. Basically put nohup before any command you wish to run.

 

By default the output is written to nohup.out in your home directory. For more info:

man nohup

^^ Agreed.

 

Local console would be preferred as well.

Share this post


Link to post
Share on other sites

Okay; it looks like dd finished. What now? I tried sudo apt-get install gdisk but it wouldn't work. Perhaps there is some confusion; I am using a Red Hat based distribution.

 

Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×