# Install AM·OS anywhere: boot to a rescue system
# Target/Rescue Environment Prequisities:
# 20GB target disk - 4GB RAM Rescue & Target (minimum recommended)
# Run as run root
# copy and paste steps 1-7 in bulk into rescue environment or booted from live disk
# (where target disk isn't mounted at boot)
#
# 1. Create RAM disk for the ISO
mkdir -p /mnt/ramdisk
mount -t tmpfs -o size=2500M tmpfs /mnt/ramdisk

# 2. Download the ISO directly to RAM
# curl -L -o /mnt/ramdisk/amos.iso https://anne.media/mirror/amos-current-edge-x86_64.iso
wget -O /mnt/ramdisk/amos.iso https://anne.media/mirror/amos-current-edge-x86_64.iso

# 3. Mount the ISO
mkdir -p /mnt/iso
mount -o loop,ro /mnt/ramdisk/amos.iso /mnt/iso

# 4. Extract the live environment into RAM
mkdir -p /mnt/amos-live
mount -t tmpfs -o size=1000M tmpfs /mnt/amos-live
cd /mnt/amos-live
xzcat /mnt/iso/isolinux/initrd.img | cpio -idmv

# 5. Load dm-integrity module (tampering protection)
# (needed if you'll use advanced install mode and choose luks + dm-integrity. Harmless to run anyway)
modprobe dm-integrity
mount --bind /lib/modules /mnt/amos-live/lib/modules

# 6. Bind mount pseudo-filesystems and the ISO
mount --bind /dev /mnt/amos-live/dev
mount --bind /proc /mnt/amos-live/proc
mount --bind /sys /mnt/amos-live/sys
mkdir -p /mnt/amos-live/mnt/iso
mount --bind /run /mnt/amos-live/run
mount --bind /dev/pts /mnt/amos-live/dev/pts
mount --bind /mnt/iso /mnt/amos-live/mnt/iso

# 7. Chroot
chroot /mnt/amos-live /bin/bash

# Finally. Once in the chroot, run
/mnt/iso/install/setup.sh 




# if something goes wrong in the installed system (kernel upgrade/ima enforce), quick how to in rescue:
mount /dev/sda1 /mnt
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount --bind /dev /mnt/dev
mount --bind /run /mnt/run
mount --bind /dev/pts /mnt/dev/pts
chroot /mnt /bin/bash