mirror of
https://github.com/GNS3/gns3-registry.git
synced 2024-12-19 04:47:54 +00:00
Merge pull request #692 from Max13/master
Alpine Linux (Virt) packer script
This commit is contained in:
commit
57ded83559
2
packer/alpine-linux-virt/.gitignore
vendored
Normal file
2
packer/alpine-linux-virt/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
output-qemu
|
||||
packer_cache
|
22
packer/alpine-linux-virt/README.md
Normal file
22
packer/alpine-linux-virt/README.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Packer for Alpine (Virt) GNS3 appliance
|
||||
|
||||
This is the bare version of `Alpine Linux` installed from iso, no extra package added.
|
||||
|
||||
Build in 1m12s on `macOS Monterey`.
|
||||
|
||||
### Linux (untested)
|
||||
|
||||
```bash
|
||||
packer build alpine.json
|
||||
```
|
||||
|
||||
> :information_source: Uses `tcg` QEMU accelerator.
|
||||
|
||||
|
||||
### macOS (tested)
|
||||
|
||||
```bash
|
||||
packer build -var-file macos.json alpine.json
|
||||
```
|
||||
|
||||
> :information_source: Uses `hvf` QEMU accelerator. Actually much much faster than the default one, `packer` will fail on `macOS` without `hvf` (timing issue).
|
35
packer/alpine-linux-virt/alpine.json
Normal file
35
packer/alpine-linux-virt/alpine.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"variables": {
|
||||
"accelerator": "tcg"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"communicator": "none",
|
||||
"type": "qemu",
|
||||
"accelerator": "{{ user `accelerator` }}",
|
||||
"use_default_display": true,
|
||||
"iso_url": "https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/x86_64/alpine-virt-3.16.2-x86_64.iso",
|
||||
"iso_checksum": "6c7cb998ec2c8925d5a1239410a4d224b771203f916a18f8015f31169dd767a2",
|
||||
"http_directory": "./files",
|
||||
"vm_name": "alpine-virt-3.16.img",
|
||||
"disk_size": "92M",
|
||||
"format": "raw",
|
||||
"qemu_img_args": {
|
||||
"create": ["-o", "preallocation=off"]
|
||||
},
|
||||
"disk_interface": "virtio",
|
||||
"disk_discard": "unmap",
|
||||
"boot_wait": "15s",
|
||||
"boot_key_interval": "20ms",
|
||||
"boot_keygroup_interval": "100ms",
|
||||
"boot_command": [
|
||||
"root<enter>",
|
||||
"ifconfig lo up<enter>",
|
||||
"ifconfig eth0 up && udhcpc -i eth0<enter><wait5>",
|
||||
"wget -q http://{{ .HTTPIP }}:{{ .HTTPPort }}/alpine.conf && setup-alpine -e -f alpine.conf<enter><wait><enter><wait500ms><enter><wait5><enter><wait500ms><enter><wait500ms>",
|
||||
"wget -q http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.sh && chmod +x install.sh && ./install.sh<enter><wait30s>",
|
||||
"poweroff<enter>"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
24
packer/alpine-linux-virt/files/alpine.conf
Normal file
24
packer/alpine-linux-virt/files/alpine.conf
Normal file
@ -0,0 +1,24 @@
|
||||
KEYMAPOPTS=none
|
||||
HOSTNAMEOPTS=alpine
|
||||
DEVDOPTS=mdev
|
||||
INTERFACESOPTS="auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet manual
|
||||
# DHCP
|
||||
#iface eth0 inet dhcp
|
||||
# Static
|
||||
#iface eth0 inet static
|
||||
# address IP_ADDRESS/MASK
|
||||
# gateway GW_IP_ADDRESS
|
||||
# dns-nameserver DNS_IP_ADDRESS
|
||||
"
|
||||
TIMEZONEOPTS=UTC
|
||||
PROXYOPTS=none
|
||||
APKREPOSOPTS=-1
|
||||
SSHDOPTS=none
|
||||
NTPOPTS=none
|
||||
DISKOPTS=none
|
||||
#LBUOPTS=none
|
||||
APKCACHEOPTS=none
|
66
packer/alpine-linux-virt/files/install.sh
Normal file
66
packer/alpine-linux-virt/files/install.sh
Normal file
@ -0,0 +1,66 @@
|
||||
#!/bin/ash
|
||||
|
||||
DRIVE="/dev/vda"
|
||||
|
||||
# Format drive, from sector 2048 to end, bootable
|
||||
fdisk $DRIVE << EOS
|
||||
o
|
||||
n
|
||||
p
|
||||
1
|
||||
2048
|
||||
|
||||
a
|
||||
1
|
||||
w
|
||||
EOS
|
||||
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Error while partitioning device" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Format partition without "64bit" and "has_journal" flags
|
||||
apk add e2fsprogs && mkfs.ext4 -O \^64bit,\^has_journal ${DRIVE}1 && mount ${DRIVE}1 /mnt -t ext4 && mkdir /mnt/boot && apk del e2fsprogs
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Error somewhere while making filesystem or mounting partition" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Actually install Alpine Linux in mounted directory
|
||||
BOOT_SIZE=0 setup-disk -k virt -s 0 /mnt
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Error while installing Alpine" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install the MBR
|
||||
dd if=/mnt/usr/share/syslinux/mbr.bin of=/dev/vda
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Error while fixing kernel path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Fix kernel and initrd path, enable console on ttyS0
|
||||
sed -i.bkp 's_LINUX vmlinuz_LINUX /boot/vmlinuz_; s_INITRD initram_INITRD /boot/initram_; /APPEND/s/$/ console=ttyS0,115200/' /mnt/boot/extlinux.conf
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Error while fixing kernel path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Enable autologin on ttyS0
|
||||
sed -i.bkp 's/^ttyS0/#ttyS0/g' /mnt/etc/inittab && echo "ttyS0::respawn:/bin/login -f root" >> /mnt/etc/inittab
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Error while enabling autologin on ttyS0" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Write 0
|
||||
dd if=/dev/zero bs=1M of=/mnt/zero ; rm -f /mnt/zero
|
||||
|
||||
# fsck
|
||||
umount ${DRIVE}1 && apk add e2fsprogs && fsck.ext4 ${DRIVE}1
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "Couldn't fsck partition" >&2
|
||||
exit 1
|
||||
fi
|
3
packer/alpine-linux-virt/macos.json
Normal file
3
packer/alpine-linux-virt/macos.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"accelerator": "hvf"
|
||||
}
|
Loading…
Reference in New Issue
Block a user