Forked from ishad0w/oci_ubuntu_to_debian.multiarch.sh
Last active
October 5, 2022 15:23
-
-
Save sokolster/cffe096c13eb9d2a4b1804f83fca982c to your computer and use it in GitHub Desktop.
Debian 11 on Oracle Cloud (Free Tier) - (ARM64)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# clean arm64/amd64 instance with (ubuntu 22.04 minimal) | |
# all actions require root privileges (aka "sudo -i") | |
export DEBIAN_FRONTEND=noninteractive; apt update && apt install lsof | |
# prepare | |
snap remove --purge oracle-cloud-agent && snap remove --purge core18 && \ | |
apt-get purge -y $(dpkg-query -Wf '${Package}\n' | grep header) $(dpkg-query -Wf '${Package}\n' | grep -oP "^linux.*\d\d\d\d-oracle" | grep -v "$(uname -r)") linux-modules-extra-$(uname -r) lxc* lxd* vim* snapd* python* && \ | |
apt-get -y autoremove --purge && apt-get -y autoclean && rm -rf /var/log/* /var/lib/apt/* /var/cache/apt/* && cd / && \ | |
mount -t tmpfs -o size=1700m tmpfs mnt && tar --one-file-system -c . | tar -C /mnt -x && \ | |
mount --make-private -o remount,rw / && \ | |
mount --move dev mnt/dev && mount --move proc mnt/proc && \ | |
mount --move run mnt/run && mount --move sys mnt/sys && \ | |
sed -i '/^[^#]/d;' mnt/etc/fstab && \ | |
echo 'tmpfs / tmpfs defaults 0 0' >> mnt/etc/fstab && \ | |
cd mnt && mkdir old_root && \ | |
mount --make-private / | |
# manual | |
unshare -m | |
pivot_root . old_root | |
# start sshd on 1022 (you need to reconnect to this ssh instance for the next steps) | |
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 1022 -j ACCEPT ; /usr/sbin/sshd -D -p 1022 & | |
# killall | |
for i in agetty dbus-daemon atd iscsid rpcbind unattended-upgrades; do pkill $i; done | |
kill 1 | |
umount -l /dev/sda1 | |
# debian 11 install (for ARM64/aarch64) | |
curl -L https://cloud.debian.org/cdimage/cloud/bullseye/latest/debian-11-genericcloud-arm64.tar.xz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M && sleep 10 && sync && echo "Done! Go reboot" && echo b | tee /proc/sysrq-trigger | |
# done | |
# default user now is "debian" | |
#in new system (deb11) | |
export DEBIAN_FRONTEND=noninteractive | |
echo "deb http://deb.debian.org/debian bullseye main contrib non-free | |
deb http://deb.debian.org/debian bullseye-updates main contrib non-free | |
deb http://deb.debian.org/debian bullseye-backports main contrib non-free | |
deb http://security.debian.org/debian-security/ bullseye-security main contrib non-free" > /etc/apt/sources.list && \ | |
apt update && apt full-upgrade -y && \ | |
sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen && update-locale LANG=en_US.UTF-8 && \ | |
apt install -y htop && reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment