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
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.
@ligmaSec
Copy link

is there any way to boot from a vmdk disk?

@4abhinavjain
Copy link
Author

is there any way to boot from a vmdk disk?

vmdk disk image can be easily converted into other raw or qcow2 images using VirtualBox tools.

@4abhinavjain
Copy link
Author

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: https://lowendspirit.com/discussion/3840/migrate-a-kvm-vps-from-one-host-to-another-easy-mode/). 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).

@ligmaSec
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: https://lowendspirit.com/discussion/3840/migrate-a-kvm-vps-from-one-host-to-another-easy-mode/). 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 ?

@nulshell
Copy link

nulshell commented Jun 9, 2023

After reboot, and during the first time ssh connection, I didn't check the popup message carefully and chose the first option, maybe adding the new host fingerprint to known host or something like that. Then I cannot login any more, and realized the ssh public key in the image has been different now. Is there anyway I can update the ssh key on Oracle website? I tried the instance's cloud shell, it needs login first as well.

@sokolster
Copy link

After reboot, and during the first time ssh connection, I didn't check the popup message carefully and chose the first option, maybe adding the new host fingerprint to known host or something like that. Then I cannot login any more, and realized the ssh public key in the image has been different now. Is there anyway I can update the ssh key on Oracle website? I tried the instance's cloud shell, it needs login first as well.

Just try user debian instead of ubuntu
And remove old string with servername/ip from local machine file ~/.ssh/known_hosts

@nulshell
Copy link

After reboot, and during the first time ssh connection, I didn't check the popup message carefully and chose the first option, maybe adding the new host fingerprint to known host or something like that. Then I cannot login any more, and realized the ssh public key in the image has been different now. Is there anyway I can update the ssh key on Oracle website? I tried the instance's cloud shell, it needs login first as well.

Just try user debian instead of ubuntu And remove old string with servername/ip from local machine file ~/.ssh/known_hosts

Thanks. I use a portable version of MobaXterm on Windows as ssh client, and didn't find the known_hosts path it uses. In my %userprofile%/ssh/known_hosts, I only found github records used with git bash.

@nulshell
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.

@mabocrack
Copy link

hi there!

Is it possible to dd Windows ARM64 instead of Debian ?

Thank you :)

@mabocrack
Copy link

up

@4abhinavjain
Copy link
Author

Hi @mabocrack

It may be possible, but I will try to consider this: https://winaero.com/install-windows-10-arm-qemu/ and get the qemu binary from here: https://qemu.weilnetz.de/w64/

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

@4abhinavjain
Copy link
Author

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: https://lowendspirit.com/discussion/3840/migrate-a-kvm-vps-from-one-host-to-another-easy-mode/). 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.

@4abhinavjain
Copy link
Author

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.

@shoopea
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 "127.0.1.1\t`hostname`" >> /etc/hosts

@fliespl
Copy link

fliespl commented Sep 1, 2023

Anyone had success with debian 12?

@33Fraise33
Copy link

Anyone had success with debian 12?

Jup works perfectly

@tm4dev
Copy link

tm4dev commented Sep 14, 2023

Thanks for useful tutorial.
This one easier way https://github.com/bohanyang/debi

@KITE2459
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?

@backslash112
Copy link

Wondering why no grub config required...

@romor001
Copy link

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

@nepto
Copy link

nepto commented Feb 20, 2024

It still works well. Good job!

The image for the Debian/12 (Bookworm) is:
https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-arm64.tar.xz

@4abhinavjain
Copy link
Author

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