blob: d82fd78411d2a11a5a356d624ac60afdcfd7c413 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/bin/sh
# args
qcow="${1-testimage.qcow2}"
name="${2-testimage}"
size="${3-1G}"
function msg() {
local txt="$1"
local bold="\x1b[1m"
local normal="\x1b[0m"
echo -e "${bold}### ${txt}${normal}"
}
######################################################################
# guestfish script helpers
function fish() {
echo "#" "$@"
guestfish --remote -- "$@" || exit 1
}
function fish_init() {
local format
case "$qcow" in
*.raw) format="raw" ;;
*) format="qcow2";;
esac
msg "creating and adding disk image"
fish disk-create $qcow $format $size
fish add $qcow
fish run
}
function fish_format() {
local label="$1"
msg "creating partition"
fish part-init /dev/sda mbr
fish part-add /dev/sda p 2048 -2048
fish part-set-mbr-id /dev/sda 1 0x0c
msg "creating filesystem"
fish mkfs fat /dev/sda1 "label:$label"
}
function fish_fini() {
fish umount-all
fish exit
}
######################################################################
# go!
#export LIBGUESTFS_BACKEND=direct
eval $(guestfish --listen)
if test "$GUESTFISH_PID" = ""; then
echo "ERROR: starting guestfish failed"
exit 1
fi
rm -f "$qcow"
fish_init
fish_format "$name"
fish_fini
msg "all done."
|