-
Notifications
You must be signed in to change notification settings - Fork 24
/
fedora30.sh
54 lines (46 loc) · 1.34 KB
/
fedora30.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
48
49
50
51
52
53
54
#!/bin/bash
# create vm - fixing selinux bug, then run a basic command
virt-builder fedora-30 \
--format raw \
--output ~/fedora30.img \
--root-password password \
--install rpmdevtools \
--selinux-relabel \
--edit '/usr/lib/systemd/system/selinux-autorelabel.service: $_ = "" if /StandardInput=tty/' \
--firstboot-command 'ls / > /var/tmp/ls.txt' \
--firstboot-command 'poweroff'
# boot vm
qemu-system-x86_64 \
-enable-kvm \
-display none \
-machine accel=kvm:tcg \
-cpu host \
-m 2048 \
-smp 4 \
-device virtio-scsi-pci,id=scsi \
-drive file=~/fedora30.img,cache=unsafe,format=raw,id=hd0,if=none \
-device scsi-hd,drive=hd0 \
-serial stdio \
-net nic,model=virtio -net bridge,br=br0
# fetch the file from the guest and delete the disk image
virt-copy-out -a ~/fedora30.img /var/tmp/ls.txt ~/
rm ~/fedora30.img
<<COMMENTS
instead of calling qemu directly, you could use libvirt:
virt-install \
--virt-type kvm \
--name=fedora30 \
--os-variant=fedora30 \
--cpu host-passthrough \
--vcpus 4 \
--memory 2048 \
--disk path=~/fedora30.img,format=raw,sparse=true,bus=scsi,discard=unmap \
--controller type=scsi,model=virtio-scsi \
--network bridge=br0,model=virtio \
--channel unix,target_type=virtio,name=org.qemu.guest_agent.0 \
--graphics none \
--video none \
--serial=pty \
--metadata title="Fedora 30" \
--import
COMMENTS