]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-13-ENC-RAID-LVM/create-root.sh
use "rm --" to guard against filenames beginning with "-"
[thirdparty/dracut.git] / test / TEST-13-ENC-RAID-LVM / create-root.sh
CommitLineData
461ff22c
HH
1#!/bin/sh
2# don't let udev and this script step on eachother's toes
3set -x
4for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
5 > "/etc/udev/rules.d/$x"
6done
32bd2fbb 7rm -f -- /etc/lvm/lvm.conf
43cc4d84 8udevadm control --reload
461ff22c 9# save a partition at the beginning for future flagging purposes
a7ee1cd7 10sfdisk -C 2560 -H 2 -S 32 -L /dev/sda <<EOF
461ff22c 11,16
a7ee1cd7
HH
12,800
13,800
14,800
461ff22c
HH
15EOF
16echo -n test >keyfile
17cryptsetup -q luksFormat /dev/sda2 /keyfile
18cryptsetup -q luksFormat /dev/sda3 /keyfile
19cryptsetup -q luksFormat /dev/sda4 /keyfile
20cryptsetup luksOpen /dev/sda2 dracut_sda2 </keyfile
3b403b32 21cryptsetup luksOpen /dev/sda3 dracut_sda3 </keyfile
461ff22c
HH
22cryptsetup luksOpen /dev/sda4 dracut_sda4 </keyfile
23mdadm --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.
26mdadm -W /dev/md0
27lvm pvcreate -ff -y /dev/md0 && \
28lvm vgcreate dracut /dev/md0 && \
29lvm lvcreate -l 100%FREE -n root dracut && \
30lvm vgchange -ay && \
31mke2fs /dev/dracut/root && \
32mkdir -p /sysroot && \
33mount /dev/dracut/root /sysroot && \
34cp -a -t /sysroot /source/* && \
35umount /sysroot && \
1eb8e921 36sleep 2 && \
461ff22c 37lvm lvchange -a n /dev/dracut/root && \
1eb8e921 38sleep 2 && \
461ff22c
HH
39lvm vgchange -a n dracut && \
40{
41lvm vgdisplay && \
42{ mdadm -W /dev/md0 || :;} && \
43mdadm --stop /dev/md0 && \
44cryptsetup luksClose /dev/mapper/dracut_sda2 && \
45cryptsetup luksClose /dev/mapper/dracut_sda3 && \
46cryptsetup luksClose /dev/mapper/dracut_sda4 && \
47:; :;} && \
b8a2f174 48{
3b403b32 49 echo "dracut-root-block-created"
b8a2f174 50 for i in /dev/sda[234]; do
021b2fdd 51 udevadm info --query=env --name=$i|grep -F 'ID_FS_UUID='
b8a2f174
HH
52 done
53} >/dev/sda1
461ff22c 54poweroff -f