Skip to content

Commit 98f87a2

Browse files
committed
Extract: add support for rootfs and debootstrap
1 parent 1a4b534 commit 98f87a2

10 files changed

Lines changed: 125 additions & 17 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ all:
44
@echo "make build|linux|busybox|initrd|target|ssh|sync|test|check|clean|download|up|extract|vbox|cmd|gui"
55

66
extract:
7-
./scripts/extract_from_vm.sh && ./scripts/extract.sh
7+
./scripts/extract_signpost.sh
88

99
vbox:
1010
./scripts/vbox_disk_generate.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ make build
4040
make gui
4141
```
4242

43-
For extracting binaries from other distribution just look at [distro_extractor](distro_extractor/) folder. We virtually provide extract recipes for every linux distro ever made 😉 For example if you prefer _debian_ binaries over _arch_ just use something like `DISTRO=devuan DISTRO_ISO=/path/to/devuan_chimaera_4.0.0_amd64_minimal-live.iso make extract`
43+
For extracting binaries from other distribution just read [supported distributions](distro_extractor/README.md). We virtually provide extract recipes for every linux distro ever made 😉 For example if you prefer _debian_ binaries over _arch_ just use something like `DISTRO=devuan DISTRO_ISO=/path/to/devuan_chimaera_4.0.0_amd64_minimal-live.iso make extract`. For more extract methods run `make extract`.
4444

4545
## User's config
4646

distro_extractor/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Extracting packages from other distributions
2+
3+
NiceOS do not provide package manager. Instead, it uses other distributions package managers.
4+
5+
Currently, we support **3** extract methods:
6+
- Virtual machine (**vm**)
7+
- our recommended method for extracting
8+
- you need virtual machine provider (_QEMU_ or _VirtualBox_) and distribution install _ISO_
9+
- Root file system (**rfs**)
10+
- installing by extracting distribution _rootfs_ into temp folder and perform _chroot_ install there
11+
- Debootstrap (**deb**)
12+
- for debian based distributions using _debootstrap_ binary
13+
14+
## Supported distributions
15+
16+
NiceOS support out of the box these distributions (alphabetical order):
17+
18+
---
19+
**NOTE:**
20+
Always check firstly for latest version for your architecture and desired flavour on distribution homepage or use your specific version instead of example one.
21+
Also, many distributions provide mirrors at different geographical places and URLs - try to use closest and fastest mirror for you.
22+
---
23+
24+
25+
- Artix (https://artixlinux.org/)
26+
- vm `DISTRO=artix DISTRO_ISO=/path/to/artix-base-openrc-20220123-x86_64.iso make extract`
27+
- Debian (https://www.debian.org/)
28+
- deb: `DEBOOTSTRAP_SUITE=stable DEBOOTSTRAP_MIRROR='https://deb.debian.org/debian/' make extract`
29+
- Devuan (https://www.devuan.org/)
30+
- vm: `DISTRO=devuan DISTRO_ISO=/path/to/devuan_chimaera_4.0.0_amd64_minimal-live.iso make extract`
31+
- deb: `DEBOOTSTRAP_SUITE=stable DEBOOTSTRAP_MIRROR='https://packages.devuan.org/merged' make extract`
32+
- Ubuntu (https://ubuntu.com/)
33+
- rfs: `DISTRO=debian-based DISTRO_ROOTFS=/path/to/ubuntu-base-21.10-base-amd64.tar.gz make extract`
34+
- deb: `DEBOOTSTRAP_SUITE=jammy DEBOOTSTRAP_SCRIPT=stable DEBOOTSTRAP_MIRROR='http://archive.ubuntu.com/ubuntu' make extract`
35+
- Void (https://voidlinux.org/)
36+
- vm: `DISTRO=void DISTRO_ISO=/path/to/void-live-x86_64-20210930.iso make extract`
37+
- rfs: `DISTRO=void DISTRO_ROOTFS=/path/to/void-x86_64-ROOTFS-20210930.tar.xz make extract`

distro_extractor/artix/inc.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ function boot_info_qemu() {
1717
echo "Run '/bin/sshd'"
1818
echo "For future password prompt write $VM_PASS"
1919
}
20+
21+
function distro_install_command() {
22+
packages=$(cat "$NICE_PRESET_PATH/packages.${PM}.txt" | xargs)
23+
echo "pacman -Sy --noconfirm $packages"
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
PM=deb
4+
5+
function distro_install_command() {
6+
packages=$(cat "$NICE_PRESET_PATH/packages.${PM}.txt" | xargs)
7+
echo "apt-get update && apt-get install --no-install-recommends --assume-yes $packages"
8+
}

distro_extractor/devuan/inc.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

3-
PM=deb
3+
source distro_extractor/debian-based/inc.sh || exit 1
4+
45
VM_USER=devuan
56
VM_PASS=$VM_USER
67

distro_extractor/void/inc.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ function boot_info() {
99
echo "Start boot by pressing enter or wait 10 sec"
1010
echo "After boot finished"
1111
}
12+
13+
function distro_install_command() {
14+
packages=$(cat "$NICE_PRESET_PATH/packages.${PM}.txt" | xargs)
15+
echo "xbps-install --yes -S $packages"
16+
}

scripts/extract_from_chroot.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
source ./.config.sh || exit 1
5+
6+
source "$BASE/distro_extractor/$DISTRO/inc.sh" || dd "File '$BASE/distro_extractor/$DISTRO/inc.sh' cannot be sourced"
7+
command=$(distro_install_command)
8+
9+
notify "We need sudo for bind mounting, chroot and cleanup"
10+
sudo mount --bind /sys "$VM_MOUNT_ROOT/sys"
11+
sudo mount --bind /dev "$VM_MOUNT_ROOT/dev"
12+
sudo mount --bind /proc "$VM_MOUNT_ROOT/proc"
13+
sudo cp /etc/resolv.conf "$VM_MOUNT_ROOT/etc/"
14+
15+
sudo chroot "$VM_MOUNT_ROOT" /bin/sh -c "'$command'"
16+
17+
sudo umount "$VM_MOUNT_ROOT/proc"
18+
sudo umount "$VM_MOUNT_ROOT/dev"
19+
sudo umount "$VM_MOUNT_ROOT/sys"

scripts/extract_from_vm.sh

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,6 @@
22

33
source ./.config.sh || exit 1
44

5-
HYPERVISOR=${HYPERVISOR:-'qemu'}
6-
if [ -z "$DISTRO" ]; then
7-
echo "You need to specify extracting distribution from $BASE/distro_extractor, use one of"
8-
ls "$BASE/distro_extractor"
9-
dd "use \`export DISTRO=artix\` for example"
10-
fi
11-
if [ -z "$DISTRO_ISO" ]; then
12-
echo "You need to specify distribution install iso path"
13-
echo "use \`export DISTRO_ISO=/data/dwn/artix-base-openrc-20220123-x86_64.iso\` for example"
14-
echo " or "
15-
dd "use \`export DISTRO_ISO=/data/dwn/devuan_chimaera_4.0.0_amd64_minimal-live.iso\` for example"
16-
fi
17-
18-
195
function boot_info_qemu() {
206
echo "For future password prompt write $VM_PASS"
217
}

scripts/extract_signpost.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
set -e
4+
source ./.config.sh || exit 1
5+
6+
function requires_distro_variable() {
7+
if [ -z "$DISTRO" ]; then
8+
echo "You need to specify extracting distribution from $BASE/distro_extractor, use one of"
9+
ls "$BASE/distro_extractor"
10+
dd "use \`export DISTRO=artix\` for example"
11+
fi
12+
}
13+
14+
15+
if [ -n "$DISTRO_ISO" ]; then
16+
requires_distro_variable
17+
which VBoxManage &> /dev/null && HYPERVISOR_CANDIDATE=virtualbox || true
18+
which qemu-system-x86_64 &> /dev/null && HYPERVISOR_CANDIDATE=qemu || true
19+
20+
export HYPERVISOR=${HYPERVISOR:-"$HYPERVISOR_CANDIDATE"}
21+
./scripts/extract_from_vm.sh
22+
./scripts/extract.sh
23+
24+
elif [ -n "$DISTRO_ROOTFS" ]; then
25+
requires_distro_variable
26+
export NICE_EXTRACT_DISTRO_HDD_IMAGE_PATH=/tmp/nice-not-exists.noimg
27+
export VM_MOUNT_ROOT="$STORAGE/temp/extract/rootfs_$(date +%s)" && mkdir -p "$VM_MOUNT_ROOT"
28+
tar --checkpoint=100 -xf "$DISTRO_ROOTFS" -C "$VM_MOUNT_ROOT"
29+
./scripts/extract_from_chroot.sh
30+
./scripts/extract.sh
31+
sudo rm -rf "$VM_MOUNT_ROOT"
32+
33+
elif [ -n "$DEBOOTSTRAP_SUITE" ]; then
34+
which debootstrap > /dev/null || dd "Debootstrap binary not found"
35+
36+
export VM_MOUNT_ROOT="$STORAGE/temp/extract/debootstrap_$(date +%s)" && mkdir -p "$VM_MOUNT_ROOT"
37+
export NICE_EXTRACT_DISTRO_HDD_IMAGE_PATH=/tmp/nice-not-exists.noimg
38+
notify "We need sudo for debootstrap and cleanup"
39+
sudo debootstrap --variant=minbase --merged-usr --arch="${ARCH:-amd64}" --include="$(cat "$NICE_PRESET_PATH/packages.deb.txt" | xargs | sed 's/ /,/g')" "$DEBOOTSTRAP_SUITE" "$VM_MOUNT_ROOT" "$DEBOOTSTRAP_MIRROR" "$DEBOOTSTRAP_SCRIPT"
40+
./scripts/extract.sh
41+
sudo rm -rf "$VM_MOUNT_ROOT"
42+
43+
else
44+
echo "You need to provide extract method. Use one of:"
45+
echo "'DISTRO_ISO' OR 'DISTRO_ROOTFS' OR 'DEBOOTSTRAP_SUITE'"
46+
dd "For example use \`export DISTRO_ISO=/data/dwn/artix-base-openrc-20220123-x86_64.iso\`"
47+
fi

0 commit comments

Comments
 (0)