Skip to content

Commit c444fa8

Browse files
committed
initramfs: use thin-pool on volatile.img instead of static partitions (WIP)
This allows much more flexibility in space usage. The most important use case if DispVM in Qubes 4.0, where both root and private images should have CoW layer applied. This will also ease having completely encrypted volatile.img (QubesOS/qubes-issues#904). This is only partial implementation, missing parts: - fstab adjustments (swap now on /dev/mapper/dmswap instead of /dev/xvdc1) - private.img mounting adjustments (possibly /dev/mapper/dmprivate instead of directly /dev/xvdb) - only "simple" implementation for dracut modified, others (full dracut module and debian initramfs) not touched Also this new approach takes longer to setup - 0.6s vs 0.3s (on some arbitrary hardware). QubesOS/qubes-issues#2253
1 parent 6c9e31c commit c444fa8

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

dracut/simple/init.sh

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,62 @@ mount -t proc proc /proc
66
mount -t sysfs sysfs /sys
77
mount -t devtmpfs devtmpfs /dev
88

9-
if [ -e /dev/mapper/dmroot ] ; then
9+
if [ -e /dev/mapper/dmroot ] ; then
1010
echo "Qubes: FATAL error: /dev/mapper/dmroot already exists?!"
1111
fi
1212

13+
set -e
14+
1315
modprobe xenblk || modprobe xen-blkfront || echo "Qubes: Cannot load Xen Block Frontend..."
16+
modprobe dm-thin-pool
1417

18+
initialize_pool() {
19+
if [ -n "$pool_dev" ]; then
20+
return
21+
fi
22+
while ! [ -e /dev/xvdc ]; do sleep 0.1; done
23+
VOLATILE_SIZE=$(cat /sys/block/xvdc/size) # sectors
24+
meta_size=$(( $VOLATILE_SIZE / 512 ))
25+
data_size=$(( $VOLATILE_SIZE - $meta_size ))
26+
dmsetup create volatile-tmeta \
27+
--table "0 $meta_size linear /dev/xvdc 0"
28+
dmsetup create volatile-tdata \
29+
--table "0 $data_size linear /dev/xvdc $meta_size"
30+
meta_dev=$(dmsetup info -c --noheadings volatile-tmeta | cut -d : -f 2,3)
31+
data_dev=$(dmsetup info -c --noheadings volatile-tdata | cut -d : -f 2,3)
32+
dmsetup create volatile --addnodeoncreate --table \
33+
"0 $data_size thin-pool $meta_dev $data_dev 256 0"
34+
pool_dev=$(dmsetup info -c --noheadings volatile | cut -d : -f 2,3)
35+
}
1536

1637
echo "Waiting for /dev/xvda* devices..."
1738
while ! [ -e /dev/xvda ]; do sleep 0.1; done
1839

1940
SWAP_SIZE=$(( 1024 * 1024 * 2 )) # sectors, 1GB
2041

42+
initialize_pool
43+
44+
ROOT_SIZE=$(cat /sys/block/xvda/size) # sectors
2145
if [ `cat /sys/block/xvda/ro` = 1 ] ; then
2246
echo "Qubes: Doing COW setup for AppVM..."
2347

24-
while ! [ -e /dev/xvdc ]; do sleep 0.1; done
25-
VOLATILE_SIZE=$(cat /sys/block/xvdc/size) # sectors
26-
ROOT_SIZE=$(cat /sys/block/xvda/size) # sectors
27-
if [ $VOLATILE_SIZE -lt $SWAP_SIZE ]; then
28-
die "volatile.img smaller than 1GB, cannot continue"
29-
fi
30-
sfdisk -q --unit S /dev/xvdc >/dev/null <<EOF
31-
1,$SWAP_SIZE,S
32-
,,L
33-
EOF
34-
if [ $? -ne 0 ]; then
35-
echo "Qubes: failed to setup partitions on volatile device"
36-
exit 1
37-
fi
38-
while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done
39-
mkswap /dev/xvdc1
40-
while ! [ -e /dev/xvdc2 ]; do sleep 0.1; done
41-
42-
echo "0 `cat /sys/block/xvda/size` snapshot /dev/xvda /dev/xvdc2 N 16" | \
43-
dmsetup create dmroot || { echo "Qubes: FATAL: cannot create dmroot!"; exit 1; }
44-
echo Qubes: done.
48+
dmsetup message volatile 0 "create_thin 0"
49+
dmsetup create dmroot \
50+
--table "0 $ROOT_SIZE thin $pool_dev 0 /dev/xvda"
4551
else
4652
echo "Qubes: Doing R/W setup for TemplateVM..."
47-
while ! [ -e /dev/xvdc ]; do sleep 0.1; done
48-
sfdisk -q --unit S /dev/xvdc >/dev/null <<EOF
49-
1,$SWAP_SIZE,S
50-
EOF
51-
if [ $? -ne 0 ]; then
52-
die "Qubes: failed to setup partitions on volatile device"
53-
fi
54-
while ! [ -e /dev/xvdc1 ]; do sleep 0.1; done
55-
mkswap /dev/xvdc1
56-
echo "0 `cat /sys/block/xvda/size` linear /dev/xvda 0" | \
57-
dmsetup create dmroot || { echo "Qubes: FATAL: cannot create dmroot!"; exit 1; }
58-
echo Qubes: done.
53+
dmsetup create dmroot \
54+
--table "0 $ROOT_SIZE linear /dev/xvda 0"
5955
fi
60-
dmsetup mknodes dmroot
56+
dmsetup message volatile 0 "create_thin 16"
57+
dmsetup create dmswap \
58+
--table "0 $SWAP_SIZE thin $pool_dev 16"
59+
dmsetup mknodes dmroot dmswap
60+
mkswap /dev/mapper/dmswap
61+
62+
echo Qubes: done.
6163

62-
modprobe ext4
64+
modprobe ext4 || :
6365

6466
mkdir -p /sysroot
6567
mount /dev/mapper/dmroot /sysroot -o ro

dracut/simple/module-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ install() {
1414
inst_multiple \
1515
sfdisk \
1616
mkswap
17+
hostonly='' instmods dm-thin-pool
1718
}

0 commit comments

Comments
 (0)