-
Notifications
You must be signed in to change notification settings - Fork 2
/
x-build-image
executable file
·78 lines (65 loc) · 2.23 KB
/
x-build-image
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
#
# Build Fedora image
if [ "$#" -ne 1 ]; then
echo "Usage: x build-image <name>"
exit 1
fi
. $HOME/.x-tools
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $DIR/common
USER=$(whoami)
if [ "$USER" == "root" ]; then
echo "Please don't run this script as root, exiting ..."
exit
fi
VNAME=$1
if [ -f "$X_BI_DIR/$VNAME.img" ]; then
echo "$X_BI_DIR/$VNAME.img is already exist, exiting ..."
exit
fi
APP_LINE="/etc/fstab:host0 $X_BI_MOUNT 9p x-systemd.automount,x-systemd.device-timeout=10,trans=virtio,version=9p2000.L,rw 0 0"
PKG_TO_INSTAL="rdma-core-devel,libibverbs-utils,openssh,vim,pciutils,nfs-utils,infiniband-diags"
get_image_type $VNAME
IMAGE_TYPE=$REPLY
FIRSTBOOT_CMD=""
if [ "$IMAGE_TYPE" == "ib" ]; then
PKG_TO_INSTAL=$PKG_TO_INSTAL",opensm"
FIRSTBOOT_CMD="--firstboot-command 'systemctl enable opensm' --firstboot-command 'systemctl start opensm'"
fi
if [ -f "$HOME/.ssh/id_rsa.pub" ]; then
SSHDIR=$(mktemp -d)
cp $HOME/.ssh/id_rsa.pub $SSHDIR/
SSH_INJECT="root:file:$SSHDIR/id_rsa.pub"
else
if [ -f "$HOME/.ssh/id_dsa.pub" ]; then
SSHDIR=$(mktemp -d)
cp $HOME/.ssh/id_dsa.pub $SSHDIR/
SSH_INJECT="root:file:$SSHDIR/id_dsa.pub"
else
echo "No ssh keys for $USER, exiting ..."
exit
fi
fi
export LIBGUESTFS_BACKEND=direct
export LIBGUESTFS_BACKEND_SETTINGS=network_bridge=br0
sudo virt-builder fedora-27 -o $X_BI_DIR/$VNAME.img \
--root-password password:$X_BI_PASSWORD \
--hostname $VNAME --install $PKG_TO_INSTAL \
--cache $X_BI_VM_CACHE/ -m 8096 \
--selinux-relabel --size 6G \
--append-line "$APP_LINE" \
--mkdir $X_BI_MOUNT --ssh-inject "$SSH_INJECT" \
--ssh-inject root --update \
--copy-in $DIR/systemd/journald.conf:/etc/systemd/ \
--copy-in $DIR/systemd/system.conf:/etc/systemd/ \
$FIRSTBOOT_CMD
GROUP=$(groups | awk '{print $1}')
sudo chown $USER:$GROUP $X_BI_DIR/$VNAME.img
rm -rf $SSHDIR
qemu_location $VNAME
QEMU_BIN=$REPLY
# Start prepared image to execute firstboot directives
$QEMU_BIN -machine accel=kvm:tcg -cpu host -smp cpus=2 -m 8096 -drive file=$X_BI_DIR/$VNAME.img,format=raw,if=virtio \
-no-reboot -nographic -net bridge,br=br0 -net nic,model=virtio,macaddr=00:50:56:1b:c6:05 \
-virtfs local,path=$X_BI_MOUNT,mount_tag=host0,security_model=passthrough,id=host0