forked from cleverca22/not-os
-
Notifications
You must be signed in to change notification settings - Fork 2
/
make-qcow2.sh
executable file
·47 lines (35 loc) · 1.31 KB
/
make-qcow2.sh
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
#! /usr/bin/env bash
# Script to create a qcow2 image.
#
# The main difference with the raw and qcow2 attributes in default.nix, is that
# here we only use a single ext4 partition (which thus contain the /boot
# files).
#
# This is necessary for instance to use the Digital Ocean custom image feature
# (which only supports EXT3 and EXT4).
#
# This doesn't use the same mechanism than nix-exp/exp03 because it relies on
# too much NixOS-specific things. Currently, this means than Nix is not
# installed in the vm.
# Warning: the losetup | grep doesn't work if the same filename is listed more
# than once.
# Mmm. It seems sudo losetup results in having loop0p1 but without sudo, nope.
# This require the syslinux package, e.g. with nix-shell -p.
EMBED_SITE="${EMBED_SITE:-_site}"
nix-build --option substitute false --attr images
cp result/image.raw .
sudo losetup --show -f -P image.raw
export DEV=`losetup | grep image.raw | awk '{print $1}'`
export DEV1="${DEV}p1"
echo "Device is ${DEV}."
if [ "${DEV}" != "/dev/loop0" ] ; then
echo "Resulting device is not what I expected."
losetup -d ${DEV}
exit 1
fi
mkdir -p rootfs-mnt
sudo mount "${DEV1}" rootfs-mnt
sudo rsync -a "${EMBED_SITE}/" rootfs-mnt/var/www/noteed.com/
sudo umount rootfs-mnt
losetup -d ${DEV}
qemu-img convert -f raw -O qcow2 image.raw image.qcow2