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