Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ewaldj/ad3035d87b97bb05cb3b65276d7f839f to your computer and use it in GitHub Desktop.

Select an option

Save ewaldj/ad3035d87b97bb05cb3b65276d7f839f to your computer and use it in GitHub Desktop.

Revisions

  1. ewaldj revised this gist Oct 2, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reinstall_VPS_from_inside.txt
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,7 @@ lsblk

    # 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/bullseye/latest/debian-11-generic-arm64.tar.xz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M
    curl -L https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-arm64.tar.xzz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M

    sync

  2. ewaldj revised this gist Oct 2, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reinstall_VPS_from_inside.txt
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,7 @@ lsblk

    # 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
    curl -L https://cloud.debian.org/cdimage/cloud/bullseye/latest/debian-11-generic-arm64.tar.xz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M

    sync

  3. @4abhinavjain 4abhinavjain renamed this gist Apr 26, 2022. 1 changed file with 0 additions and 0 deletions.
  4. @4abhinavjain 4abhinavjain revised this gist Jan 27, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -78,3 +78,5 @@ reboot
    # 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.
  5. @4abhinavjain 4abhinavjain revised this gist Jan 27, 2022. 1 changed file with 21 additions and 19 deletions.
    40 changes: 21 additions & 19 deletions reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,27 @@
    # should works on any cloud-init enabled hypervisor (openstack.. )

    # start from a ubuntu minimal install
    # we need to shrink down the used space to move it in a tmpfs of 700MB
    # 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

    while ! ssh -o ConnectTimeout=2 -p 22 ubuntu@$instanceIP; do sleep 1; done
    # 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

    sudo snap remove --purge oracle-cloud-agent && sudo snap remove --purge core18 && sudo snap remove --purge snapd && sudo sudo apt -y purge snapd && sudo rm -rf ~/snap /snap /var/cache/snapd
    # 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/*


    # ok, the disk usage of / should be less than 600MB now
    # 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=700m tmpfs mnt
    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
    @@ -31,13 +36,13 @@ 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:

    while ! ssh -o ConnectTimeout=2 -p 1022 ubuntu@$instanceIP; do sleep 1; done
    # 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

    @@ -58,21 +63,18 @@ umount -l /dev/sda1
    df -h
    lsblk

    # the disk should be unmount
    # 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.

    # curl https://cdimage.debian.org/cdimage/openstack/current/debian-10-openstack-amd64.raw | dd of=/dev/sda bs=1M
    # 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

    # update :
    # curl -L https://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.raw | dd of=/dev/sda bs=1M

    # curl -L https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.raw | dd of=/dev/sda bs=1M

    curl -L https://cloud.debian.org/cdimage/cloud/bullseye/latest/debian-11-generic-amd64.tar.xz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M
    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

    while ! ssh -o ConnectTimeout=2 -p 22 debian@$instanceIP; do sleep 1; done

    # 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)
  6. @ClashTheBunny ClashTheBunny revised this gist Jan 2, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -66,7 +66,9 @@ lsblk
    # update :
    # curl -L https://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.raw | dd of=/dev/sda bs=1M

    curl -L https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.raw | dd of=/dev/sda bs=1M
    # curl -L https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.raw | dd of=/dev/sda bs=1M

    curl -L https://cloud.debian.org/cdimage/cloud/bullseye/latest/debian-11-generic-amd64.tar.xz | tar -OJxvf - disk.raw | dd of=/dev/sda bs=1M

    sync

  7. @ClashTheBunny ClashTheBunny revised this gist Jan 2, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -66,7 +66,7 @@ lsblk
    # update :
    # curl -L https://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.raw | dd of=/dev/sda bs=1M

    curl -L https://cdimage.debian.org/images/cloud/bullseye/20211220-862/debian-11-genericcloud-amd64-20211220-862.raw | dd of=/dev/sda bs=1M
    curl -L https://cdimage.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.raw | dd of=/dev/sda bs=1M

    sync

  8. @ClashTheBunny ClashTheBunny revised this gist Jan 2, 2022. 1 changed file with 15 additions and 17 deletions.
    32 changes: 15 additions & 17 deletions reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,13 @@
    # start from a ubuntu minimal install
    # we need to shrink down the used space to move it in a tmpfs of 700MB

    while ! ssh -o ConnectTimeout=2 -p 22 ubuntu@$instanceIP; do sleep 1; done

    # make sure we are on the highest kernel, so we can delete all the others ...
    sudo apt update && sudo apt upgrade -y && reboot
    sudo apt update && sudo apt dist-upgrade -y && sudo apt install lsof && sudo reboot

    # ... reconnect
    sudo apt install lsof
    sudo snap remove --purge oracle-cloud-agent && sudo snap remove --purge core18 && sudo snap remove --purge snapd && sudo sudo apt -y purge snapd && sudo rm -rf ~/snap /snap /var/cache/snapd
    sudo 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* && sudo apt -y autoremove && sudo apt -y autoclean && sudo apt -y clean
    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/*


    @@ -31,21 +31,16 @@ mount --make-private /
    unshare -m
    pivot_root . old_root

    # now the root storage is the RAM
    /usr/sbin/sshd -D -p 1022 &

    iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 1022 -j ACCEPT

    # lets restart all runnig process
    # reconnect on port 1022:

    service ssh restart
    while ! ssh -o ConnectTimeout=2 -p 1022 ubuntu@$instanceIP; do sleep 1; done

    # now the root storage is the RAM

    # now switch to a new ssh connexion to let the old sshd terminate

    service systemd-udevd restart
    service systemd-journald restart
    service systemd-networkd restart
    service systemd-timesyncd restart
    service systemd-resolved restart
    service systemd-logind restart
    service networkd-dispatcher restart
    pkill agetty
    pkill dbus-daemon
    pkill atd
    @@ -69,10 +64,13 @@ lsblk
    # curl https://cdimage.debian.org/cdimage/openstack/current/debian-10-openstack-amd64.raw | dd of=/dev/sda bs=1M

    # update :
    curl -L https://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.raw | dd of=/dev/sda bs=1M
    # curl -L https://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.raw | dd of=/dev/sda bs=1M

    curl -L https://cdimage.debian.org/images/cloud/bullseye/20211220-862/debian-11-genericcloud-amd64-20211220-862.raw | dd of=/dev/sda bs=1M

    sync

    reboot

    while ! ssh -o ConnectTimeout=2 -p 22 debian@$instanceIP; do sleep 1; done

  9. @dotsh dotsh revised this gist Oct 28, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ pivot_root . old_root

    # lets restart all runnig process

    service sshd restart
    service ssh restart

    # now switch to a new ssh connexion to let the old sshd terminate

  10. @dotsh dotsh revised this gist Oct 28, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@ echo 'tmpfs / tmpfs defaults 0 0' >> mnt/etc/fstab
    cd mnt
    mkdir old_root
    mount --make-private /
    unshare -m
    pivot_root . old_root

    # now the root storage is the RAM
  11. @dotsh dotsh revised this gist Oct 28, 2021. 1 changed file with 10 additions and 18 deletions.
    28 changes: 10 additions & 18 deletions reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -3,23 +3,15 @@
    # start from a ubuntu minimal install
    # we need to shrink down the used space to move it in a tmpfs of 700MB

    apt install lsof partprobe
    snap remove oracle-cloud-agent
    snap remove core18
    snap remove snapd
    apt purge snapd
    rm -rf ~/snap
    rm -rf /snap
    rm -rf /var/cache/snapd

    ## check what other package takes lot of space
    dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
    # remove large unused packages...
    apt remove linux-modules-extra-5.4.0-1037-oracle
    apt remove linux-oracle-headers-5.4.0-1037 linux-headers-5.4.0-1037-oracle
    apt autoremove
    apt autoclean
    apt clean
    # make sure we are on the highest kernel, so we can delete all the others ...
    sudo apt update && sudo apt upgrade -y && reboot

    # ... reconnect
    sudo apt install lsof
    sudo snap remove --purge oracle-cloud-agent && sudo snap remove --purge core18 && sudo snap remove --purge snapd && sudo sudo apt -y purge snapd && sudo rm -rf ~/snap /snap /var/cache/snapd
    sudo 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* && sudo apt -y autoremove && sudo apt -y autoclean && sudo apt -y clean
    sudo rm -rf /var/log/* /var/lib/apt/lists/*


    # ok, the disk usage of / should be less than 600MB now

    @@ -34,7 +26,7 @@ mount --move sys mnt/sys
    sed -i '/^[^#]/d;' mnt/etc/fstab
    echo 'tmpfs / tmpfs defaults 0 0' >> mnt/etc/fstab
    cd mnt
    mkdir old_roota
    mkdir old_root
    mount --make-private /
    pivot_root . old_root

  12. @dotsh dotsh revised this gist Oct 20, 2021. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,8 @@ 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
    mkdir old_roota
    mount --make-private /
    pivot_root . old_root

    # now the root storage is the RAM
    @@ -72,7 +73,11 @@ lsblk
    # the disk should be unmount
    # now, just copy the debian cloud image on the disk.

    curl https://cdimage.debian.org/cdimage/openstack/current/debian-10-openstack-amd64.raw | dd of=/dev/sda bs=1M
    # curl https://cdimage.debian.org/cdimage/openstack/current/debian-10-openstack-amd64.raw | dd of=/dev/sda bs=1M

    # update :
    curl -L https://cdimage.debian.org/cdimage/openstack/testing/debian-testing-openstack-amd64.raw | dd of=/dev/sda bs=1M

    sync

    reboot
  13. @dotsh dotsh revised this gist Mar 23, 2021. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion reinstall_VPS_from_inside.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # should works on any cloud-init enabled hypervisor (openstack.. )

    # start from a ubuntu minimal install
    # we need to shrink down the used space to move it in a tmpfs of 700MB

    @@ -12,7 +14,7 @@ rm -rf /var/cache/snapd

    ## check what other package takes lot of space
    dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
    # remove big un
    # remove large unused packages...
    apt remove linux-modules-extra-5.4.0-1037-oracle
    apt remove linux-oracle-headers-5.4.0-1037 linux-headers-5.4.0-1037-oracle
    apt autoremove
    @@ -58,8 +60,18 @@ 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
    # now, just copy the debian cloud image on the disk.

    curl https://cdimage.debian.org/cdimage/openstack/current/debian-10-openstack-amd64.raw | dd of=/dev/sda bs=1M
    sync

  14. @dotsh dotsh renamed this gist Mar 23, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  15. @dotsh dotsh created this gist Mar 23, 2021.
    68 changes: 68 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    # start from a ubuntu minimal install
    # we need to shrink down the used space to move it in a tmpfs of 700MB

    apt install lsof partprobe
    snap remove oracle-cloud-agent
    snap remove core18
    snap remove snapd
    apt purge snapd
    rm -rf ~/snap
    rm -rf /snap
    rm -rf /var/cache/snapd

    ## check what other package takes lot of space
    dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
    # remove big un
    apt remove linux-modules-extra-5.4.0-1037-oracle
    apt remove linux-oracle-headers-5.4.0-1037 linux-headers-5.4.0-1037-oracle
    apt autoremove
    apt autoclean
    apt clean

    # ok, the disk usage of / should be less than 600MB now

    cd /
    mount -t tmpfs -o size=700m 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
    pivot_root . old_root

    # now the root storage is the RAM

    # lets restart all runnig process

    service sshd restart

    # now switch to a new ssh connexion to let the old sshd terminate

    service systemd-udevd restart
    service systemd-journald restart
    service systemd-networkd restart
    service systemd-timesyncd restart
    service systemd-resolved restart
    service systemd-logind restart
    service networkd-dispatcher restart
    pkill agetty
    pkill dbus-daemon
    pkill atd
    pkill iscsid
    pkill rpcbind
    pkill unattended-upgrades
    kill 1

    umount -l /dev/sda1

    curl https://cdimage.debian.org/cdimage/openstack/current/debian-10-openstack-amd64.raw | dd of=/dev/sda bs=1M
    sync

    reboot