self-flash-image/switch_root.sh

22 lines
621 B
Bash
Executable File

#!/bin/sh
sudo modprobe zram num_devices=4
echo 500M | sudo tee /sys/block/zram2/disksize
sudo mkfs.ext4 -m0 /dev/zram2
mkdir /tmp/sys
sudo mount /dev/zram2 /tmp/sys
sudo tar -cpSf - \
--acls --xattrs --selinux \
--exclude-from ./exclude.list \
/ |
sudo tar -xvf - \
--acls --xattrs --selinux \
-C /tmp/sys
sudo truncate -s0 /tmp/sys/etc/fstab
sudo swapoff -a
sudo mkdir -p /sysroot
sudo mount --rbind /tmp/sys /sysroot
sudo touch /etc/initrd-release
# it will stop all other services (isolate) and call systemctl switch-root /sysroot
sudo systemctl --no-block isolate initrd-switch-root