Skip to content

Commit 7da1070

Browse files
committed
Chroot tuning and fixing for arch
1 parent 71dc6de commit 7da1070

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

distro_extractor/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ NiceOS do not provide package manager. Instead, it uses other distributions pack
44

55
Currently, we support **3** extract methods:
66
- Virtual machine (**vm**)
7-
- our recommended method for extracting
8-
- you need virtual machine provider (_QEMU_ or _VirtualBox_) and distribution install _ISO_
7+
- **our recommended method for extracting**
8+
- you need virtual machine provider (_QEMU_ or _VirtualBox_) and distribution installation _ISO_
99
- Root file system (**rfs**)
1010
- installing by extracting distribution _rootfs_ into temp folder and perform _chroot_ install there
1111
- Debootstrap (**deb**)
@@ -18,7 +18,7 @@ NiceOS support out of the box these distributions (alphabetical order):
1818
---
1919
**NOTE:**
2020
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.
21+
Also, many distributions provide mirrors at different geographical places and URLs - try to use closest and fastest mirror for you. And always check downloaded files signature.
2222
---
2323

2424

distro_extractor/arch-based/inc.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@ PM=arch
44

55
function distro_install_command() {
66
packages=$(cat "$NICE_PRESET_PATH/packages.${PM}.txt" | xargs)
7-
echo "pacman -Sy --noconfirm $packages"
7+
8+
# Disable pacman checking free space
9+
echo -n 'cat /etc/pacman.conf | sed "s/CheckSpace/#CheckSpace/" > /tmp/pacman.conf && '
10+
echo -n 'cp /tmp/pacman.conf /etc/pacman.conf && '
11+
12+
# Add default server and initialize keys
13+
echo -n 'echo "Server = https://mirror.rackspace.com/archlinux/\$repo/os/\$arch" >> "/etc/pacman.d/mirrorlist" && '
14+
echo -n "pacman-key --init && pacman-key --populate archlinux && pacman -Sy --noconfirm $packages"
815
}

scripts/extract_from_chroot.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@ source ./.config.sh || exit 1
66
source "$BASE/distro_extractor/$DISTRO/inc.sh" || dd "File '$BASE/distro_extractor/$DISTRO/inc.sh' cannot be sourced"
77
command=$(distro_install_command)
88

9+
if [ "0" == $(ls "$VM_MOUNT_ROOT" | wc -l) ]; then
10+
dd "Chroot path $VM_MOUNT_ROOT seems empty, probably tar failed"
11+
elif [ "1" == $(ls "$VM_MOUNT_ROOT" | wc -l) ]; then
12+
# Rootfs has been pack in one folder
13+
export VM_MOUNT_ROOT="$VM_MOUNT_ROOT/$(ls "$VM_MOUNT_ROOT")"
14+
fi
15+
916
notify "We need sudo for bind mounting, chroot and cleanup"
17+
sudo cp /etc/resolv.conf "$VM_MOUNT_ROOT/etc/"
18+
1019
sudo mount --bind /sys "$VM_MOUNT_ROOT/sys"
11-
sudo mount --bind /dev "$VM_MOUNT_ROOT/dev"
1220
sudo mount --bind /proc "$VM_MOUNT_ROOT/proc"
13-
sudo cp /etc/resolv.conf "$VM_MOUNT_ROOT/etc/"
21+
sudo mount --bind /dev "$VM_MOUNT_ROOT/dev"
1422

23+
[[ $(type -t chroot_pre_hook) == 'function' ]] && chroot_pre_hook || true
1524
sudo chroot "$VM_MOUNT_ROOT" /bin/sh -c "'$command'"
1625

17-
sudo umount "$VM_MOUNT_ROOT/proc"
18-
sudo umount "$VM_MOUNT_ROOT/dev"
19-
sudo umount "$VM_MOUNT_ROOT/sys"
26+
sudo umount -l "$VM_MOUNT_ROOT/dev"
27+
sudo umount -l "$VM_MOUNT_ROOT/proc"
28+
sudo umount -l "$VM_MOUNT_ROOT/sys"
29+
30+
./scripts/extract.sh
31+
sudo rm -rf "$VM_MOUNT_ROOT"

scripts/extract_signpost.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ elif [ -n "$DISTRO_ROOTFS" ]; then
2525
requires_distro_variable
2626
export NICE_EXTRACT_DISTRO_HDD_IMAGE_PATH=/tmp/nice-not-exists.noimg
2727
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"
28+
notify "We need sudo for untar rootfs"
29+
sudo tar --checkpoint=100 -xf "$DISTRO_ROOTFS" -C "$VM_MOUNT_ROOT"
2930
./scripts/extract_from_chroot.sh
30-
./scripts/extract.sh
31-
sudo rm -rf "$VM_MOUNT_ROOT"
3231

3332
elif [ -n "$DEBOOTSTRAP_SUITE" ]; then
3433
which debootstrap > /dev/null || dd "Debootstrap binary not found"
3534

3635
export VM_MOUNT_ROOT="$STORAGE/temp/extract/debootstrap_$(date +%s)" && mkdir -p "$VM_MOUNT_ROOT"
3736
export NICE_EXTRACT_DISTRO_HDD_IMAGE_PATH=/tmp/nice-not-exists.noimg
3837
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"
38+
sudo debootstrap --variant=minbase --merged-usr --arch="${NICE_ARCH:-amd64}" --include="$(cat "$NICE_PRESET_PATH/packages.deb.txt" | xargs | sed 's/ /,/g')" "$DEBOOTSTRAP_SUITE" "$VM_MOUNT_ROOT" "$DEBOOTSTRAP_MIRROR" "$DEBOOTSTRAP_SCRIPT"
4039
./scripts/extract.sh
4140
sudo rm -rf "$VM_MOUNT_ROOT"
4241

0 commit comments

Comments
 (0)