Linux RAID1 with only One disk

5

3

I have a hypothetical situation in which I installed my operating system using a RAID1 mirror. At some point I decided that this setup was overkill, my machine isn't system critical, I value doubling my storage space more than speedy recovery, I'm doing routine backups, etc...

Short of backing up my system volume and repartitioning, or otherwise starting over, is there a way I can reconfigure my RAID1 array to only expect one disk so that mdadm no longer reports a Degraded state?

andyortlieb

Posted 2010-10-27T14:40:54.693

Reputation: 342

Answers

6

You can set the number of disks in a RAID-1 array to whatever you want (well, any positive integer), including 1. Simply remove all but the one component you want to keep with mdadm --remove, then set the number of components to 1:

mdadm /dev/md999 --grow --force -n 1

By the way, conversely, if you think you might want to make a mirror of a disk or partition, it is a good idea to set it up as a single-component RAID-1 array from the start. (You can do it later by shrinking the filesystem by 128kB and creating a superblock, but it's a lot easier to create the array first and then put a filesystem on it.)


It's possible to turn the single remaining component into a standalone volume: stop the array with mdadm --stop, then use mdadm --zero-superblock on the component volume. Since the md superblock is at the end of the component volume, whatever filesystem that was on the RAID-1 volume is also directly accessible on each component volume. If you do this, you'll even be able to enlarge the filesystem by 64kB to 128kB (depending on alignment). All in all, it's possible, but hardly worth the trouble. I recommend keeping the mirror with a single component — who knows, maybe you'll want to replicate it again one day (if nothing else, RAID-1 reconstruction is a very fast way of copying the contents of a disk to another disk, and it doesn't mind that the disk is mounted at the time).

Note that with mdadm 1, the default location for the superblock is at the beginning of the device, so the filesystem doesn't start at the same location as the RAID device. Choose version 1.0 superblock instead of the default 1.2 (or 0.9 for backward compatibility) to put the superblock at the end of the device. If you have a 1.1 or 1.2 superblock, you can't easily convert the volume into a non-mdraid volume.

Gilles 'SO- stop being evil'

Posted 2010-10-27T14:40:54.693

Reputation: 58 319

1"if you think you might want to make a mirror of a disk or partition, it is a good idea to set it up as a single-component RAID-1 array from the start." This is actually one intention, to be able to optionally add a disk to be mirrored at a later time. Thanks much! – andyortlieb – 2010-10-27T19:46:23.987

5I found this answer useful in a situation where I started with one RAID1 partition and later added another partition. This is how you create a single-component RAID1: mdadm --create /dev/md0 --level=1 --force --raid-devices=1 --metadata 1.2 /dev/sdd1 – Antti Kissaniemi – 2011-03-01T06:45:38.820

0

If that were my machine, I'd just pull one of the disks and try to boot it up, it should work just fine. You've got backups so you could take this as a learning experience should something go awry. The next step would be disabling the RAID without clearing any data, which I've got zero experience doing with a Linux software RAID, so I'd be of no help there, but it should be possible AFAIK.

Psychoholic

Posted 2010-10-27T14:40:54.693

Reputation: 411

If it were mine, I would probably do the same to be honest. But as I said I need mdadm to not report a Degraded state as I'll be doing certain reporting on that. Thanks for your input though. – andyortlieb – 2010-10-27T19:50:30.477