]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-13-ENC-RAID-LVM/create-root.sh
test: use dd to write status to marker disk
[thirdparty/dracut.git] / test / TEST-13-ENC-RAID-LVM / create-root.sh
1 #!/bin/sh
2 # don't let udev and this script step on eachother's toes
3 set -x
4 for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
5 > "/etc/udev/rules.d/$x"
6 done
7 rm -f -- /etc/lvm/lvm.conf
8 udevadm control --reload
9 # save a partition at the beginning for future flagging purposes
10 sfdisk /dev/sda <<EOF
11 ,4M
12 ,43M
13 ,43M
14 ,43M
15 EOF
16 udevadm settle
17 printf test >keyfile
18 cryptsetup -q luksFormat /dev/sda2 /keyfile
19 cryptsetup -q luksFormat /dev/sda3 /keyfile
20 cryptsetup -q luksFormat /dev/sda4 /keyfile
21 cryptsetup luksOpen /dev/sda2 dracut_sda2 </keyfile
22 cryptsetup luksOpen /dev/sda3 dracut_sda3 </keyfile
23 cryptsetup luksOpen /dev/sda4 dracut_sda4 </keyfile
24 mdadm --create /dev/md0 --run --auto=yes --level=5 --raid-devices=3 /dev/mapper/dracut_sda2 /dev/mapper/dracut_sda3 /dev/mapper/dracut_sda4
25 # wait for the array to finish initailizing, otherwise this sometimes fails
26 # randomly.
27 mdadm -W /dev/md0
28 lvm pvcreate -ff -y /dev/md0 && \
29 lvm vgcreate dracut /dev/md0 && \
30 lvm lvcreate -l 100%FREE -n root dracut && \
31 lvm vgchange -ay && \
32 mke2fs /dev/dracut/root && \
33 mkdir -p /sysroot && \
34 mount /dev/dracut/root /sysroot && \
35 cp -a -t /sysroot /source/* && \
36 umount /sysroot && \
37 sleep 2 && \
38 lvm lvchange -a n /dev/dracut/root && \
39 sleep 2 && \
40 lvm vgchange -a n dracut && \
41 {
42 lvm vgdisplay && \
43 { mdadm -W /dev/md0 || :;} && \
44 mdadm --stop /dev/md0 && \
45 cryptsetup luksClose /dev/mapper/dracut_sda2 && \
46 cryptsetup luksClose /dev/mapper/dracut_sda3 && \
47 cryptsetup luksClose /dev/mapper/dracut_sda4 && \
48 :; :;} && \
49 {
50 echo "dracut-root-block-created"
51 for i in /dev/sda[234]; do
52 udevadm info --query=env --name=$i|grep -F 'ID_FS_UUID='
53 done
54 } | dd oflag=direct,dsync of=/dev/sda1
55 poweroff -f