Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 4abhinavjain/893ec13c651bee08088c8f4661998952 to your computer and use it in GitHub Desktop.
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
# 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
curl -L | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M
# reboot command didn't work and returned an error "running in chroot, ignoring request" ; I tried exiting as they told here ( 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.
Copy link

hi there!

Is it possible to dd Windows ARM64 instead of Debian ?

Thank you :)

Copy link


Copy link

Hi @mabocrack

It may be possible, but I will try to consider this: and get the qemu binary from here:

Please do give it a try and share here in case it works.

Copy link

UPDATE: 22-Mar-2023
While the mentioned method worked, I have been thinking another strategy to change OS by booting the instance into rescue mode and writing an image to the medium (once converted to a raw format) using a dd command and then later adjusting the partition size with tools like GParted.
The good thing about the dd command is that it can also do so remotely. I recently moved OS from one VPS to another (same size and hardware though) using the dd command, and it works well (using this article: I highly encourage you to try this approach as it brings more flexibility (it may even be possible to migrate existing Raspberry Pi image to OCI cloud).

is rescue mode equivalent to the local console connection in OCI ?

No, rescue mode is like booting with another drive and then mount and chroot into the desired root partition.

Copy link

I started over and it worked, thanks to the author👍。The previous problem was because I didn't choose to keep the original key option.

Another question is, is it necessary to install Oracle cloud agent on Debian? I haven't yet, but wondered if it's allowed or we better install it. The ram use is much lower without it. The oracle document listed manual install options only on 3 distributions, Oracle, Centos, Ubuntu.

Glad that it worked. I recall it is not necessary but I would suggest to do or check the Oracle free tier use policy. They may want the agent to be installed for monitoring stats purposes or in case the VM get hacked and start disrupting their infrastructure.

Copy link

shoopea commented Jul 12, 2023

I noticed sudo stopped working when following your steps.
I got it fixed by using that extra command after the reboot : echo -e "\t`hostname`" >> /etc/hosts

Copy link

fliespl commented Sep 1, 2023

Anyone had success with debian 12?

Copy link

Anyone had success with debian 12?

Jup works perfectly

Copy link

tm4dev commented Sep 14, 2023

Thanks for useful tutorial.
This one easier way

Copy link

If i using ssh with password in ubuntu 22.04 lts not minimal,
After this how to do .txt, ssh connections still remain with password connection? just changed user ubuntu to debian? Or need private key file when i made ubuntu oci instance?

Copy link

Wondering why no grub config required...

Copy link

Worked fine with the Debian 10 image. Did a manual upgrade to Debian 11 afterwards. Thanks a lot for this! Much apreciated!

Copy link

nepto commented Feb 20, 2024

It still works well. Good job!

The image for the Debian/12 (Bookworm) is:

Copy link

Great! Glad ghait works on Debian 12 as well. Thanks for the feedback

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