-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkimage.alpine
executable file
·70 lines (61 loc) · 2.34 KB
/
mkimage.alpine
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
#!/bin/sh
DST=$1
SIZE=$2
SRC=$3
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <destination_image> <size> <minirootfs_image_source> "
exit 1
fi
. $(dirname $0)/functions.sh
set -ev
download "$SRC" "$DST.orig.tar.gz"
virt-make-fs -s +50M -F qcow2 "$DST.orig.tar.gz" "$DST.orig"
rm -f "$DST.orig.tar.gz"
gf_listen
gf add-drive "$DST.orig"
gf disk-create "$DST" qcow2 "$SIZE"
gf add-drive "$DST"
gf run
gf part-disk /dev/sdb msdos
gf mkfs-opts ext4 /dev/sdb1 features:^64bit
gf set-e2label /dev/sdb1 cloudimg-rootfs
gf part-set-bootable /dev/sdb 1 true
gf mount /dev/sda /
gf command "apk add --no-cache alpine-conf"
gf mount /dev/sdb1 /mnt
gf rm-rf /mnt/lost+found
gf mkdir /mnt/boot
gf command "setup-disk -k virt /mnt"
gf command "apk add --root /mnt e2fsprogs openssh tzdata"
gf write /mnt/etc/network/interfaces "auto lo
iface lo inet loopback
"
gf write /mnt/etc/fstab "LABEL=cloudimg-rootfs / ext4 defaults,noatime,nodiratime 0 1
"
gf ln_s /etc/init.d/bootmisc /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/hostname /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/hwclock /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/modules /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/networking /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/swap /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/sysctl /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/syslog /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/urandom /mnt/etc/runlevels/boot/
gf ln_s /etc/init.d/killprocs /mnt/etc/runlevels/shutdown/
gf ln_s /etc/init.d/savecache /mnt/etc/runlevels/shutdown/
gf ln_s /etc/init.d/mount-ro /mnt/etc/runlevels/shutdown/
gf ln_s /etc/init.d/devfs /mnt/etc/runlevels/sysinit/
gf ln_s /etc/init.d/dmesg /mnt/etc/runlevels/sysinit/
gf ln_s /etc/init.d/hwdrivers /mnt/etc/runlevels/sysinit/
gf ln_s /etc/init.d/mdev /mnt/etc/runlevels/sysinit/
gf ln_s /etc/init.d/sshd /mnt/etc/runlevels/default/
gf command "wget https://github.com/OpenNebula/addon-context-linux/releases/download/v5.10.0/one-context-5.10.0-r1.apk -O /one-context.apk"
gf command "apk add --root /mnt --allow-untrusted /one-context.apk"
gf rm_f "/one-context.apk"
gf sh "rm -rf /mnt/var/cache/apk/*"
gf command "sed -i 's/#\\?PermitRootLogin.*/PermitRootLogin yes/' /mnt/etc/ssh/sshd_config"
gf command "sed -i 's/root:!:/root:x:/' /etc/passwd"
gf command "sed -i 's/root:!:/root:*:/' /etc/shadow"
gf umount-all
gf exit
rm -f "$DST.orig"