Ubuntu Server 12.04, MDADM device number suddenly changes?
I'm facing a really annoying bug, I have set up a Software RAID1 with mdadm, and the setup went just ok with this results
/dev/md/lucas.mgscreativa.com.ar:0
I have also configured mdadm.conf like this
DEVICE /dev/sda /dev/sdb
# auto-create devices with Debian standard permissions CREATE owner=root group=disk mode=0660 auto=yes
# automatically tag new arrays as belonging to the local system HOMEHOST <system>
# instruct the monitoring daemon where to send mail alerts MAILADDR root
# definitions of existing MD arrays ARRAY /dev/md/lucas.mgscreativa.com.ar:0 metadata=1.2
name=lucas.mgscreativa.com.ar:0
UUID=c913486a:e62c7ea1:cfb98b6b:253d1f62
And fstab configured like this
/dev/md/lucas.mgscreativa.com.ar:0 /media/data ext4
defaults,noatime 0 0
But, some day, my array name suddenly changed from /dev/md/lucas.mgscreativa.com.ar:0 to /dev/md0, so I have done some changes in fstab and mdadm.conf (of course, after hours and hours of tryal and error) and everything went just ok, but today, AGAIN, the MD number changed from /dev/md0 to /dev/md127!!!
What's going on here? is this a bug I guess.
Is there any way to fix the MD number so my server can work as it shhould, without flaws?
Thanks!
Solution 1:
First: you are probably having errors in your array. You need to check its status, immediately.
Example:
root@locutus:~# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Jun 1 15:30:31 2012
Raid Level : raid10
Array Size : 1953119232 (1862.64 GiB 1999.99 GB)
Used Dev Size : 976559616 (931.32 GiB 1000.00 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Nov 25 21:39:44 2012
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Name : locutus:0 (local to host locutus)
UUID : b81ac63a:51a9b01c:c01812ec:86c534c4
Events : 182
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 49 1 active sync /dev/sdd1
2 8 17 2 active sync /dev/sdb1
3 8 33 3 active sync /dev/sdc1
You will very likely find that you have errors... those will need to get addressed.
Moving on, you should change the way your fstab is set up, to use UUID instead of using devicename. Use the blkid
command on your array (or a partition under your array) to get its UUID, then use that UUID to mount it in /etc/fstab.
Example:
root@locutus:~# blkid /dev/mapper/vg0-root
/dev/mapper/vg0-root: UUID="61998221-7b39-49cd-83f7-62fda973218c" TYPE="ext4"
With this information, I would set my /etc/fstab entry for root to look like this:
UUID=61998221-7b39-49cd-83f7-62fda973218c / ext4 defaults,errors=remount-ro 0 1
Once you've done this, your system will find your partitions no matter whether their device names change or not (for example, if drive cables get swapped around).
You should also set up your /etc/mdadm/mdadm.conf
to find things automatically without needing any particular drive to be in any particular location:
# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#
# by default (built-in), scan all partitions (/proc/partitions) and all
# containers for MD superblocks. alternatively, specify devices to scan, using
# wildcards if desired.
#DEVICE partitions containers
# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes
# automatically tag new arrays as belonging to the local system
HOMEHOST <system>
# instruct the monitoring daemon where to send mail alerts
MAILADDR root
# definitions of existing MD arrays
ARRAY /dev/md/0 metadata=1.2 UUID=c913486a:e62c7ea1:cfb98b6b:253d1f62 name=lucas.mgscreativa.com.ar:0
NOTE THAT THERE ARE NO DEVICES SPECIFIED IN THIS CONF FILE. This is a feature, not a bug. With mdadm.conf set up this way, your system will automatically scan all attached drives looking for anything that belongs to your array, and will assemble them all as /dev/md0.
Solution 2:
For this answer I am assuming that the array is intact - no failed disks, not other error conditions, just the changing "device number".
What should normally work is to stop the array:
# mdadm --verbose --misc --stop /dev/md127
... fix the line referring to the array in /etc/mdadm/mdadm.conf
(i.e. adjust the name of the device). Then assemble it as follows:
# mdadm --verbose --assemble --update=super-minor --run /dev/md0 /dev/sdaX /dev/sdbX
(adjust the references to the physical devices to your case).
You should see an output like this:
mdadm: looking for devices for /dev/md0
mdadm: updating superblock of /dev/sdaX with minor number 0
mdadm: /dev/sdaX is identified as a member of /dev/md0, slot 0.
mdadm: updating superblock of /dev/sdbX with minor number 0
mdadm: /dev/sdbX is identified as a member of /dev/md0, slot 1.
mdadm: added /dev/sdbX to /dev/md0 as 1
mdadm: added /dev/sdaX to /dev/md0 as 0
mdadm: /dev/md0 has been started with 2 drives.
And if you query the details you should see an updated "Preferred Minor" field. Check with:
# mdadm -Q -D /dev/md0|grep "Preferred"
Preferred Minor : 0
Caveats: also, make sure that you mount the device and write to it. Otherwise the change may not take effect. Also, super-minor
appears to be specific to the old metadata format.
NB: I do not know whether you can affect the "name" in the original sense with this. I know you can affect the X
in the created /dev/mdX
names, however.