]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-13-ENC-RAID-LVM/create-root.sh
c4c7a179f50352eabbe4261bd44ef60dd75993eb
[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 /etc/lvm/lvm.conf
8 udevadm control --reload
9 # save a partition at the beginning for future flagging purposes
10 sfdisk -C 2560 -H 2 -S 32 -L /dev/sda <<EOF
11 ,16
12 ,800
13 ,800
14 ,800
15 EOF
16 echo -n test >keyfile
17 cryptsetup -q luksFormat /dev/sda2 /keyfile
18 cryptsetup -q luksFormat /dev/sda3 /keyfile
19 cryptsetup -q luksFormat /dev/sda4 /keyfile
20 cryptsetup luksOpen /dev/sda2 dracut_sda2 </keyfile
21 cryptsetup luksOpen /dev/sda3 dracut_sda3 </keyfile
22 cryptsetup luksOpen /dev/sda4 dracut_sda4 </keyfile
23 mdadm --create /dev/md0 --run --auto=yes --level=5 --raid-devices=3 /dev/mapper/dracut_sda2 /dev/mapper/dracut_sda3 /dev/mapper/dracut_sda4
24 # wait for the array to finish initailizing, otherwise this sometimes fails
25 # randomly.
26 mdadm -W /dev/md0
27 lvm pvcreate -ff -y /dev/md0 && \
28 lvm vgcreate dracut /dev/md0 && \
29 lvm lvcreate -l 100%FREE -n root dracut && \
30 lvm vgchange -ay && \
31 mke2fs /dev/dracut/root && \
32 mkdir -p /sysroot && \
33 mount /dev/dracut/root /sysroot && \
34 cp -a -t /sysroot /source/* && \
35 umount /sysroot && \
36 sleep 2 && \
37 lvm lvchange -a n /dev/dracut/root && \
38 sleep 2 && \
39 lvm vgchange -a n dracut && \
40 {
41 lvm vgdisplay && \
42 { mdadm -W /dev/md0 || :;} && \
43 mdadm --stop /dev/md0 && \
44 cryptsetup luksClose /dev/mapper/dracut_sda2 && \
45 cryptsetup luksClose /dev/mapper/dracut_sda3 && \
46 cryptsetup luksClose /dev/mapper/dracut_sda4 && \
47 :; :;} && \
48 {
49 echo "dracut-root-block-created"
50 for i in /dev/sda[234]; do
51 udevadm info --query=env --name=$i|grep -F 'ID_FS_UUID='
52 done
53 } >/dev/sda1
54 poweroff -f