Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save 4abhinavjain/893ec13c651bee08088c8f4661998952 to your computer and use it in GitHub Desktop.

Select an option

Save 4abhinavjain/893ec13c651bee08088c8f4661998952 to your computer and use it in GitHub Desktop.
DIY install debian on Oracle Cloud Infrastructure ( Free Tier ) - ARM64
# should works on any cloud-init enabled hypervisor (openstack.. )
# start from a normal ubuntu 20.04 install as minimal was not available for ARM64
# Since ARM64 machines has higher RAM, Shrinking is desired but not necessary. Instead we will increase tmpfs to 1700MB
# Getting root (if sudo -i doesn't work then set a root password beforehand using 'sudo passwd root'
sudo -i
# make sure we are on the highest kernel, so we can delete all the others ...
sudo apt update && sudo apt dist-upgrade -y && sudo apt install lsof && sudo reboot
# snap removal didn't work so proceed without it.
sudo snap remove --purge oracle-cloud-agent && sudo snap remove --purge core18
sudo apt purge -y $(dpkg-query -Wf '${Package}\n' | grep header) $(apt list --installed | grep -oP "^linux.*\d\d\d\d-oracle" | grep -v "$(uname -r)") linux-modules-extra-$(uname -r) lxc* lxd* vim* && sudo apt -y autoremove && sudo apt -y autoclean && sudo apt -y clean
sudo rm -rf /var/log/* /var/lib/apt/lists/*
# use df to check the size. It should be now ~1100MB. If it is higher than 1700 MB then increase the size below
# make sure you have root here
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 /
unshare -m
pivot_root . old_root
# commands below open 1022 port a ssh port. Please ensure the port you select is open under Oracle's VNIC
/usr/sbin/sshd -D -p 1022 &
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 1022 -j ACCEPT
# reconnect on port 1022: I kept the old putty session (on port 22) open and it didn't disconnect
# now the root storage is the RAM
pkill agetty
pkill dbus-daemon
pkill atd
pkill iscsid
pkill rpcbind
pkill unattended-upgrades
kill 1
# check with "lsof /old_root" that there is no remaining process
umount -l /dev/sda1
# check :
df -h
lsblk
# the disk should be unmount ; for me lsblk showed a /dev/sda1 partiion but it went well.
# now, just copy the debian cloud image on the disk.
# I wanted an ARM64 image and Debian 10 , therefore I used this one https://cloud.debian.org/cdimage/cloud/buster/latest/debian-10-generic-arm64.tar.xz
curl -L https://cloud.debian.org/cdimage/cloud/buster/latest/debian-10-generic-arm64.tar.xz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M
sync
reboot
# reboot command didn't work and returned an error "running in chroot, ignoring request" ; I tried exiting as they told here (https://bbs.archlinux.org/viewtopic.php?id=184076) but it was of no use
# I forced rebooted it from the Oracle instances' GUI and it seemed stuck on "STOPPING." But after an hour I noticed that the VM was rebooted and running.
# I was able to login with the same public key as original ubuntu, but the username that worked was debian
# SUCCESS!! I checked with lsb_release -a and it showed Debian 10 (earlier it was showing ubuntu)
# Additional things: You may want to reinstall the Oracle cloud agent that was removed in the beginning.
@Julienraptor01
Copy link

Julienraptor01 commented Feb 20, 2026

i did change some things for my setup
i did drop the ssh secondary as it's basically useless
also i did fix the reboot not working at the end by using kernel magic

# elevate to root
sudo -i
# prevent any snap installation
cat <<EOF > /etc/apt/preferences.d/nosnap.pref
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOF
# update 
apt update
apt dist-upgrade -y
apt install lsof -y
# make snap disappear
snap remove --purge oracle-cloud-agent
snap remove --purge core18
snap remove --purge snapd
systemctl stop snapd
systemctl disable snapd.service snapd.socket
apt purge snapd -y
rm -rf /var/cache/snapd/ /var/lib/snapd/ /var/snap/ /snap/ /home/*/snap /root/snap
# reboot so latest kernel is used
reboot
# re-elevate to root
sudo -i
# do the cleanup
apt purge $(dpkg-query -Wf '${Package}\n' | grep header) $(apt list --installed | grep -oP "^linux.*\d\d\d\d-oracle" | grep -v "$(uname -r)") linux-modules-extra-$(uname -r) lxc* lxd* vim* -y
apt autoremove -y
apt autoclean -y
apt clean -y
rm -rf /var/log/* /var/lib/apt/lists/*
# check /dev/sda1, it should be small enough
df -h
# create the ramdisk (since i'm on the arm64 ampere A1 i have 24GB ram so put 4G there)
cd /
mount -t tmpfs -o size=4000m tmpfs mnt
tar --one-file-system -c . | tar -C /mnt -x
# switch the VFS
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
# rewrite the fstab to pount to our ramdisk
sed -i '/^[^#]/d;' mnt/etc/fstab
echo 'tmpfs / tmpfs defaults 0 0' >> mnt/etc/fstab
# go into our ramdisk
cd mnt
mkdir old_root
mount --make-private /
unshare -m
pivot_root . old_root
# actually fix the env so shit work
chroot /mnt
# kill processes
pkill agetty
pkill dbus-daemon
pkill atd
pkill iscsid
pkill rpcbind
pkill -f unattended-upgrades
kill 1
# check if there is no stupid process still running
lsof /old_root
# prep our disk to be overwritten
umount -l /dev/sda1
# last sanity check
df -h
lsblk
# here we gooooo (flashing latest debian)
curl -L https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-arm64.tar.xz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M
# sync once it's done
sync
# now to reboot we need to use magic trick as reboot won't work under chroot
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

thanks for the tutorial tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment