Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrelamberty committed Sep 25, 2022
0 parents commit a4504a4
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Builds directories
build
.packer.d
102 changes: 102 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Xraspios

Extended Raspberry Pi OS Lite Image based on Raspios and packaged with Packer.

This operating system is installed on my Raspberry Pi 4 and serve as a home lab
server. It mainly run IaaS and APIs with Docker.

## Features

- [ ] Docker
- [ ] Portainer
- [ ] Git
- [ ] Tmux
- [ ] Vim
- [ ] Security
- [ ] SSH
- [x] User / Password
- [ ] Key

## Requirements

- [Packer](https://www.packer.io) (1.8.x)

## Build Image

> The image is built from the [Raspios Lite Armhf 2022-09-07](https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2022-09-07/)
See `builder.pkr.hcl`

Initialize the project, update dependencies

```bash
packer init config.pkr.hcl
```

Build the image

```bash
sudo packer build build.pkr.hcl
```

Once the build is finished, the image will be available in thes `build` folder
as `xraspios-lite.img`

### Docker

Build with the official Packer Docker [image](https://hub.docker.com/r/hashicorp/packer)

> Not tested !
Initialize

```bash
docker run \
-v `pwd`:/workspace -w /workspace \
-e PACKER_PLUGIN_PATH=/workspace/.packer.d/plugins \
hashicorp/packer:latest \
init .
```

Build

```bash
docker run \
-v `pwd`:/workspace -w /workspace \
-e PACKER_PLUGIN_PATH=/workspace/.packer.d/plugins \
hashicorp/packer:latest \
build .
```

## Write Image

Write the image to and SD card

### Raspberry Pi Imager

Use Raspberry Pi Imager to configure WiFi, users and more and write to image to
the card.

> Check how rpi-imager write config
<https://github.com/raspberrypi/rpi-imager/blob/ce0b02b823a40ada3cd4a12a257da9506e46dda1/src/OptionsPopup.qml#L589>

### DD

> When rpi-imager no more needed to configure the wifi and user. TODO: Keys and no user?!
```bash
sudo dd bs=4M if=/dev/zero of=/dev/sdb oflag=sync
```

```bash
sudo dd bs=4M if=/path/to/image of=/dev/sdb oflag=sync
```

## References

- <https://www.packer.io>
- <https://www.packer.io/docs/builders/community-supported>
- <https://github.com/solo-io/packer-plugin-arm-image>
- <https://github.com/marketplace/actions/packer-github-actions>
- <https://downloads.raspberrypi.org>
62 changes: 62 additions & 0 deletions build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
source "arm-image" "raspberry-pi-os-lite" {
iso_checksum = "sha256:28582f75128e426215e2cda8d6be04c57c0d190d5bf2d4bef62201340d5e60cf"
iso_url = "https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2022-09-07/2022-09-06-raspios-bullseye-armhf-lite.img.xz"
output_filename = "./build/xraspios-lite.img"
}

build {
name = "xraspios-lite"
sources = [
"source.arm-image.raspberry-pi-os-lite"
]
/*
// https://docs.docker.com/engine/install/binaries/
// /usr/bin/cp: error writing '/usr/bin/dockerd': No space left on device
// /usr/bin/cp: error writing '/usr/bin/runc': No space left on device
provisioner "shell" {
inline = [
"apt-get update",
"cd /tmp",
"wget -c https://download.docker.com/linux/static/stable/armhf/docker-20.10.9.tgz -O - | sudo tar -xz",
"sudo cp docker/* /usr/bin/"
]
}
*/
/*
provisioner "shell" {
inline = [
"lsblk",
]
}
provisioner "shell" {
inline = [
"apt-get update -y",
"sudo apt-get install ca-certificates curl gnupg lsb-release",
"curl -sSL https://get.docker.com | sh",
"sudo usermod -aG docker pi"
]
}
provisioner "shell" {
inline = [
"lsblk",
]
}
provisioner "shell" {
scripts = [
"./scripts/install.sh",
# "./scripts/docker.sh",
# "./scripts/git.sh",
# "./scripts/tmux.sh",
# "./scripts/vim.sh"
]
}
*/

provisioner "ansible" {
playbook_file = "playbook.yml"
}
}

8 changes: 8 additions & 0 deletions config.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
packer {
required_plugins {
arm-image = {
version = ">= 0.2.6"
source = "github.com/solo-io/arm-image"
}
}
}
5 changes: 5 additions & 0 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/bash
echo "> Installing Docker..."

curl -sSL https://get.docker.com | sh
usermod -aG docker pi
4 changes: 4 additions & 0 deletions scripts/git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/bash
echo "> Installing Git..."

apt-get install -y git
10 changes: 10 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash
echo "--- XRASPIOS INSTALATION ---"
echo " "

echo "> Update APT"
sudo apt-get update && sudo apt-get upgrade -y

echo "> Installing Utils"

sudo apt-get install -y wget curl
4 changes: 4 additions & 0 deletions scripts/tmux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/bash
echo "> Installing Tmux..."

apt-get install -y tmux
4 changes: 4 additions & 0 deletions scripts/vim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /bin/bash
echo "> Installing Vim..."

apt-get install -y vim
9 changes: 9 additions & 0 deletions vars.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "password" {
sensitive = true
default = "#pi@12345"
}

variable "user" {
type = string
default = "pi"
}

0 comments on commit a4504a4

Please sign in to comment.