]> git.ipfire.org Git - thirdparty/mdadm.git/blame - README.initramfs
mdadm: load default sysfs attributes after assemblation
[thirdparty/mdadm.git] / README.initramfs
CommitLineData
0ff1a185
NB
1Assembling md arrays at boot time.
2---------------------------------
3December 2005
4
5These notes apply to 2.6 kernels only and, in some cases,
6to 2.6.15 or later.
7
8Md arrays can be assembled at boot time using the 'autodetect' functionality
9which is triggered by storing components of an array in partitions of type
10'fd' - Linux Raid Autodetect.
11They can also be assembled by specifying the component devices in a
12kernel parameter such as
13 md=0,/dev/sda,/dev/sdb
14In this case, /dev/md0 will be assembled (because of the 0) from the listed
15devices.
16
17These mechanisms, while useful, do not provide complete functionality
18and are unlikely to be extended. The preferred way to assemble md
93579539
JS
19arrays at boot time is using 'mdadm'. To assemble an array which
20contains the root filesystem, mdadm needs to be run before that
21filesystem is mounted, and so needs to be run from an initial-ram-fs.
22It is how this can work that is the primary focus of this document.
0ff1a185
NB
23
24It should be noted up front that only the array containing the root
25filesystem should be assembled from the initramfs. Any other arrays
26should be assembled under the control of files on the main filesystem
27as this enhanced flexibility and maintainability.
28
29A minimal initramfs for assembling md arrays can be created using 3
30files and one directory. These are:
31
32/bin Directory
33/bin/mdadm statically linked mdadm binary
34/bin/busybox statically linked busybox binary
35/bin/sh hard link to /bin/busybox
36/init a shell script which call mdadm appropriately.
37
38An example init script is:
39
40==============================================
41#!/bin/sh
42
43echo 'Auto-assembling boot md array'
44mkdir /proc
45mount -t proc proc /proc
46if [ -n "$rootuuid" ]
47then arg=--uuid=$rootuuid
48elif [ -n "$mdminor" ]
49then arg=--super-minor=$mdminor
50else arg=--super-minor=0
51fi
52echo "Using $arg"
53mdadm -Acpartitions $arg --auto=part /dev/mda
54cd /
55mount /dev/mda1 /root || mount /dev/mda /root
56umount /proc
57cd /root
58exec chroot . /sbin/init < /dev/console > /dev/console 2>&1
59=============================================
60
61This could certainly be extended, or merged into a larger init script.
62Though tested and in production use, it is not presented here as
63"The Right Way" to do it, but as a useful example.
64Some key points are:
65
66 /proc needs to be mounted so that /proc/partitions can be accessed
67 by mdadm, and so that /proc/filesystems can be accessed by mount.
68
69 The uuid of the array can be passed in as a kernel parameter
70 (rootuuid). As the kernel doesn't use this value, it is made available
71 in the environment for /init
72
73 If no uuid is given, we default to md0, (--super-minor=0) which is a
74 commonly used to store the root filesystem. This may not work in
75 all situations.
76
77 We assemble the array as a partitionable array (/dev/mda) even if we
78 end up using the whole array. There is no cost in using the partitionable
79 interface, and in this context it is simpler.
80
81 We try mounting both /dev/mda1 and /dev/mda as they are the most like
82 part of the array to contain the root filesystem.
83
84 The --auto flag is given to mdadm so that it will create /dev/md*
85 files automatically. This is needed as /dev will not contain
86 and md files, and udev will not create them (as udev only created device
87 files after the device exists, and mdadm need the device file to create
88 the device). Note that the created md files may not exist in /dev
89 of the mounted root filesystem. This needs to be deal with separately
90 from mdadm - possibly using udev.
91
92 We do not need to create device files for the components which will
93 be assembled into /dev/mda. mdadm finds the major/minor numbers from
94 /proc/partitions and creates a temporary /dev file if one doesn't already
95 exist.
96
97The script "mkinitramfs" which is included with the mdadm distribution
98can be used to create a minimal initramfs. It creates a file called
99'init.cpio.gz' which can be specified as an 'initrd' to lilo or grub
100(or whatever boot loader is being used).
101
102
103
104
105Resume from an md array
106-----------------------
107
108If you want to make use of the suspend-to-disk/resume functionality in Linux,
109and want to have swap on an md array, you will need to assemble the array
110before resume is possible.
111However, because the array is active in the resumed image, you do not want
112anything written to any drives during the resume process, such as superblock
113updates or array resync.
114
115This can be achieved in 2.6.15-rc1 and later kernels using the
116'start_readonly' module parameter.
117Simply include the command
118 echo 1 > /sys/module/md_mod/parameters/start_ro
119before assembling the array with 'mdadm'.
120You can then echo
121 9:0
122or whatever is appropriate to /sys/power/resume to trigger the resume.