Browse Source

add FreeBSD support (testet with ArchBSD) and (theoretical) MacOS support

master
Markus Bergholz 6 years ago
parent
commit
cfce806442
3 changed files with 128 additions and 37 deletions
  1. +12
    -0
      README.md
  2. +2
    -0
      getchroot
  3. +114
    -37
      superchroot

+ 12
- 0
README.md View File

@@ -4,6 +4,7 @@ chroot-tools
1. `superchroot` – full automatic chroot helper
* as root – `systemd-nspawn`, `arch-chroot` or `chroot`
* as user – `fakechroot` or `proot`
* support Linux, FreeBSD and MacOS Hosts
2. `getchroot` – download and extract prepared folder installation of sevaral linux distributions.
* supported linux distributions are:
* Arch Linux
@@ -14,6 +15,7 @@ chroot-tools
* Debian Sid
* Fedora 19 (Schrödinger's cat)
* Fedora 20 (Heisenbug)
* ArchBSD
3. `createchroot`– creates a folder install for sevaral linux distributions
* supported linux distributions are:
* Arch Linux
@@ -32,6 +34,7 @@ chroot-tools
* fakechroot _(optional)_
* fakeroot _(optional)_
* [proot](http://proot.me/) _(optional)_
* bindfs _(for usage on MacOS)_

## ToDo

@@ -40,12 +43,21 @@ chroot-tools
* improvements for ubuntu debootstraps needed and the handle dash error messages!
* any ideas?
* add own script for handling graphical access?
* create FreeBSD container.

## current status

* Debian, Arch and Fedora images are fine.
* Ubuntu images works only with systemd method?!

## About chroot

It's not possible to chroot a BSD system on a Linux system or vice versa!
You can only chroot a Linux system on a Linux host!
You can only chroot a FreeBSD system on a FreeBSD host!
You can only chroot a MacOS system on a MacOS host!


# Documentation / Usage

For more use `--help` commands or read the [Wiki](https://github.com/markuman/chroot-tools/wiki).

+ 2
- 0
getchroot View File

@@ -47,6 +47,7 @@ function print_help {
raring: Ubuntu 13.04, Raring Ringtail
fedora19: Fedora 19, Schrödinger's cat
fedora20: Fedora 20, Heisenbug
archbsd: ArchBSD

This will download a prepared tar.xz file to $_CHROOT and extract to your given folder

@@ -80,6 +81,7 @@ if (("$#" == 2)); then
"fedora19") build_chroot $1 $2 ;;
"fedora20") build_chroot $1 $2 ;;
"squeeze") build_chroot $1 $2 ;;
"archbsd") build_chroot $1 $2 ;;
"update") update_chroot $2 ;;
*) echo -e "unknown option\n" ;;
esac


+ 114
- 37
superchroot View File

@@ -1,7 +1,7 @@
#!/bin/bash
# WTFPL

set -e
set -e

## functions
# ==========
@@ -15,6 +15,9 @@ set_chroot (){
"systemd") chroot_systemd $folder ;;
"chroot") chroot_chroot $folder ;;
"arch") chroot_arch $folder ;;
"mac") chroot_darwin $folder ;;
"darwin") chroot_darwin $folder ;;
"bsd") chroot_bsd $folder ;;
*) printf "unknown option\n" ;;
esac

@@ -22,60 +25,113 @@ set_chroot (){

super_chroot(){

OS=$(uname)

if [ "$UID" -ne 0 ]; then
if [ $OS == "Darwin" ] || [ $OS == "FreeBSD" ]; then
printf "You need root access.\n"
elif [ $OS == "Linux" ]; then
if which fakechroot >/dev/null; then
printf "fakechroot found...\n"
chroot_fakechroot $folder

elif which proot >/dev/null; then
printf "proot found ...\n"
chroot_proot $folder

else
printf "I can not find fakechroot nor proot and you aren't root. Sorry, but I can\'t chroot.\n"
fi
else
printf "Unknown plattform\n"
fi
else

if which fakechroot >/dev/null; then
printf "fakechroot found...\n"
chroot_fakechroot $folder
if [ $OS == "Darwin" ]; then
chroot_darwin $folder
elif [ $OS == "FreeBSD" ]; then
chroot_bsd $folder

elif [ $OS == "Linux" ]; then
if which systemd-nspawn >/dev/null; then
chroot_systemd $folder

elif which arch-chroot >/dev/null; then
chroot_arch $folder

else
printf "\nRunning classic chroot with mount -t... \n\n"
chroot_chroot $folder
fi
else
printf "Unknown plattform\n"
fi
fi

elif which proot >/dev/null; then
printf "proot found ...\n"
chroot_proot $folder
}

else
printf "I can not find fakechroot nor proot and you aren't root. Sorry, but I can\'t chroot.\n"
fi
else

if which systemd-nspawn >/dev/null; then
chroot_systemd $folder
chroot_mount() {

elif which arch-chroot >/dev/null; then
chroot_arch $folder
OS=$(uname)

else
printf "\nRunning classic chroot with mount -t... \n\n"
chroot_chroot $folder
fi
fi
if [ $OS == "FreeBSD" ]; then
if ! df -P -T $folder/dev/|grep nullfs; then
mount_nullfs /proc $folder/proc
mount_nullfs /dev $folder/dev
mount_nullfs /run $folder/run
mount_nullfs /tmp $folder/tmp
fi

elif [ $OS == "Linux" ]; then

mountpoint -q "$folder/proc" || mount proc "$folder/proc" -t proc
mountpoint -q "$folder/sys" || mount sys "$folder/sys" -t sysfs
mountpoint -q "$folder/dev" || mount udev "$folder/dev" -t devtmpfs
mountpoint -q "$folder/dev/pts" || mount devpts "$folder/dev/pts" -t devpts
mountpoint -q "$folder/dev/shm" || mount shm "$folder/dev/shm" -t tmpfs
mountpoint -q "$folder/run" || mount run "$folder/run" -t tmpfs
mountpoint -q "$folder/tmp" || mount tmp "$folder/tmp" -t tmpfs

fi

}

mount_bindfs() {

bindfs /dev $folder/dev
bindfs /tmp $folder/tmp

}

chroot_mount() {
umount_bindfs() {

mountpoint -q "$folder/proc" || mount proc "$folder/proc" -t proc
mountpoint -q "$folder/sys" || mount sys "$folder/sys" -t sysfs
mountpoint -q "$folder/dev" || mount udev "$folder/dev" -t devtmpfs
mountpoint -q "$folder/dev/pts" || mount devpts "$folder/dev/pts" -t devpts
mountpoint -q "$folder/dev/shm" || mount shm "$folder/dev/shm" -t tmpfs
mountpoint -q "$folder/run" || mount run "$folder/run" -t tmpfs
mountpoint -q "$folder/tmp" || mount tmp "$folder/tmp" -t tmpfs
fusermount -u $folder/dev
fusermount -u $folder/tmp

}

chroot_umount() {

printf "Doing lazy umount chroot folder ...\n"
umount -l "$folder/proc"
umount -l "$folder/sys"
umount -l "$folder/dev/pts"
umount -l "$folder/dev/shm"
umount -l "$folder/dev"
umount -l "$folder/run"
umount -l "$folder/tmp"
OS=$(uname)

if [ $OS == "Darwin" ]; then
umount_bindfs $folder
elif [ $OS == "FreeBSD" ]; then
umount $folder/proc
umount $folder/dev
umount $folder/run
umount $folder/tmp
else
printf "Doing lazy umount chroot folder ...\n"
umount -l "$folder/proc"
umount -l "$folder/sys"
umount -l "$folder/dev/pts"
umount -l "$folder/dev/shm"
umount -l "$folder/dev"
umount -l "$folder/run"
umount -l "$folder/tmp"
fi

}

@@ -111,13 +167,28 @@ chroot_chroot(){

}

chroot_darwin(){

mount_bindfs "$folder"
chroot $folder

}

chroot_bsd(){

chroot_mount "$folder"
chroot $folder

}


print_help(){

echo '
superchroot <folder>
superchroot [chroot-option] <folder>

[chroot options]: systemd (root), chroot (root), arch (root), fakechroot, proot, exit (umount directories from chroot methode)
[chroot options]: systemd (root), chroot (root), arch (root), mac (root), bsd (root), fakechroot, proot, exit (umount directories from chroot methode)


EXAMPLES - force method
@@ -129,6 +200,12 @@ print_help(){
EXAMPLES - automaticaly best choice
~#: superchroot arch/
~$: superchroot arch/


ATTENTION
On a Linux system: you can only chroot Linux systems!
On a FreeBSD system: you can only chroot FreeBSD systems!
On a MacOS system: you can only chroot MacOS systems!
'

}


Loading…
Cancel
Save