• Stars
    star
    658
  • Rank 68,502 (Top 2 %)
  • Language Makefile
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make bootable Linux disk image (ab)using Docker

docker-to-linux - make bootable Linux disk image abusing Docker

! Support development of this project > patreon.com/iximiuz

There is no real goal behind this project. Just out of my curiosity what if:

  • launch a base Linux container (debian, alpine, etc)
  • pull in Linux kernel & init system (systemd, OpenRC, etc)
  • dump container's filesystem to a disk image
  • install bootloader (syslinux) to this image...

Then it should be probably possible to launch a real virtual machine with such an image!

Try it out:

# 1. Build the image.
#    Depending on your setup, you may need to preceed `make` with `sudo`.
make debian  # or ubuntu, or alpine

# 2. Run it! Use username `root` and password `root` to log in.
qemu-system-x86_64 -drive file=debian.img,index=0,media=disk,format=raw -m 4096
# 2. Alternate
qemu-system-x86_64 -hda debian.qcow2 -m 512

# 3. Clean up when you are done.
make clean

It works!

You can increase or decrease the size of the VM hard disk via the environment variable VM_DISK_SIZE_MB (1024 by default).
For example for a 3GB disk:

make debian VM_DISK_SIZE_MB=3072  # or ubuntu, or alpine

Check out Makefile for more details or read my article on iximiuz.com.

Features

  • Real quick build a bootable Linux image with a single command!
  • 3 target distributives: Ubuntu 20.04, Debian Bullseye, Alpine 3.13.5
  • Build from macOS (including M1 chips) or Linux hosts

FAQ

  • Q: I'm getting an error about "read-only filesystem". How can I make it writable?

    A: It's Linux default behaviour to mount the / filesystem as read-only. You can always remount it with mount -o remount,rw /.

  • Q: How can I access network from the VM / How can I SSH into the VM?

    A: Networking is not configured at the moment. If you want to configure it yourself, search for TUN/TAP/bridge devices. Don't forget to open a PR if you come up with a working solution.

Release notes

2021-05-24

  • Start using ext4 instead of ext3.

2021-05-07

  • Fix - Ubuntu 20.04 stopped working because of the changed path to vmlinuz and initrd files.

2021-05-02

  • Fix macOS support #10 (thanks to @xavigonzalvo for reporting and suggesting the fix)
    • move losetup call from Makefile to the builder container
    • explicitly select amd64 architecture in target distr Dockerfiles to support builds on ARM hosts (aka M1)
  • Upgrade target distr versions
    • Ubuntu 18.04 -> 20.04
    • Debian Stretch -> Bullseye
    • Alpine 3.9.4 -> 3.13.5

2020-02-29

  • Improve Alpine support #7 (creds @monperrus)

2019-08-02

  • Fix loopback device lookup #3 (creds @christau)

2019-06-03

  • Initial release

TODO

  • add basic networking support
  • support different image formats (e.g. VirtualBox VDI)
  • support different target architectures (e.g. ARM)

Similar projects

...or tangential projects relying on the similar technique:

More Repositories

1

cdebug

cdebug - a swiss army knife of container debugging
Go
1,310
star
2

client-go-examples

Collection of mini-programs demonstrating Kubernetes client-go usage.
Go
1,012
star
3

kexp

k'exp - Kubernetes Explorer
TypeScript
798
star
4

awesome-container-tinkering

List of awesome tools to tinker with containers.
582
star
5

pq

Parse and Query log files as time series
Rust
377
star
6

labctl

iximiuz Labs control - start remote microVM playgrounds from the command line.
Go
181
star
7

conman

Simplistic container manager
Go
110
star
8

flask-gevent-tutorial

How to use Flask with gevent (uWSGI and Gunicorn editions)
Python
93
star
9

simple-event-loop

Fully-functional Event Loop in 100 Lines of Python
Python
62
star
10

prometheus-playground

Prometheus Playground
Python
47
star
11

shimmy

Simplistic container runtime shim
Rust
39
star
12

ptyme

Simplest possible example of PTY usage
C
33
star
13

goimagego

goimagego - work with container images in Go (showcase)
Go
22
star
14

golife.c

Conway's Game of Life written in C and compiled to WebAssembly
C
20
star
15

envoy-playground

Container-based playground showing various capabilities of service proxy pattern.
Makefile
18
star
16

node-diskusage-ng

Get disk usage info in pure JS via OS built-in tools
JavaScript
17
star
17

wsmux

wsmux - a simple WebSocket tunnel server
Go
17
star
18

reapme

Playing with Linux processes termination in Rust
Rust
15
star
19

nim-2048

The 2048 game implementation in nim
Nim
14
star
20

producer-consumer-vis

Producer-consumer problem visualization
JavaScript
13
star
21

popen2

popen2() - bidirectional popen()
C
12
star
22

cancharts

Lightweight HTML5 canvas charts
JavaScript
11
star
23

readlines-ng

Tiny and fast async generator to read streams line by line
JavaScript
7
star
24

nom-parser-example

nom parser example
Rust
5
star
25

algorithms

Collection of different kind of algorithms
Scheme
4
star
26

todolist

A simple client-server TODO app
Go
2
star
27

multi_reader.rs

MultiReader - a composite reader implementation
Rust
2
star
28

echelon0

First echelon of logs analysis
Rust
2
star
29

js-itertools

Attempt to port Python's itertools to JavaScript
JavaScript
2
star
30

x86emu-py

Python
1
star
31

dotfiles

My dotfiles
Vim Script
1
star
32

CareersAnalyzer-web

CSS
1
star
33

node-express-ex-boilerplate

ExpressJS App Extended Boilerplate
JavaScript
1
star
34

CareersAnalyzer-grabber

Python
1
star