Skip to content

Instantly share code, notes, and snippets.

@AndersonIncorp
Created June 29, 2018 16:36
Show Gist options
  • Save AndersonIncorp/28aabd6be1a43199ee1bd27d1bcfd654 to your computer and use it in GitHub Desktop.
Save AndersonIncorp/28aabd6be1a43199ee1bd27d1bcfd654 to your computer and use it in GitHub Desktop.
Install any linux distro on VPS with low RAM, locked ISO boot

Overview

Scenario

  • Your VPS provider doesn't support ISO mount
  • Your VPS has low RAM and cannot load whole ISO image
  • Your current /boot is to small to contain ISO file

Workaround

  • Boot low memory ISO (CorePure64.iso ~ 14MB)
  • Create new partition ~1GB / size of your ISO
  • dd your ISO into that partition
  • boot that partiton with grub (custom command required for every distro)

Content/steps in this file

  • Install CorePure64.iso (Tiny Core Linux) into grub
  • Partition and dd archlinux.iso
  • Install archlinux

Pre Requirements

  • You need ANY OS currently working, in example centos was used
  • IP configuration if not using DHCP
  • Know how to partition disk (resize2fs, split, create 2 partitions from 1)

Installation of archlinux if non supported by VPS hosting

Install CorePure64.iso (Tiny Core Linux) into grub

wget https://distro.ibiblio.org/tinycorelinux/9.x/x86_64/release/CorePure64-9.0.iso -O /boot/CorePure64-9.0.iso 
nano /etc/grub.d/40_custom
#/etc/grub.d/40_custom
menuentry "CorePure64-9.0.iso" {
    loopback loop (hd0,msdos1)/CorePure64-9.0.iso
    linux (loop)/boot/vmlinuz64
    initrd (loop)/boot/corepure64.gz
}
# One of
grub2-mkconfig -o /boot/grub2/grub.cfg
grub-mkconfig -o /boot/grub/grub.cfg
reboot

Partition and dd archlinux.iso

Setting up static IP network in Tiny Core Linux

sudo su
pkill udhcpc
ifconfig eth0 203.0.113.2 netmask 255.255.255.0
route add default gw 203.0.113.1 eth0
echo "nameserver 8.8.8.8" > /etc/resolv.conf
ifconfig eth0 up
ping -c 4 google.com
exit

Install e2fsprogs(resize2fs), util-linux(fdisk,sfdisk,cfdisk)

tce-load -wi e2fsprogs
tce-load -wi util-linux

Save table
Mount /boot and save part table inside

sudo su
fdisk -l
mount /dev/xvda1 /mnt
sfdisk -d /dev/xvda > /mnt/part_table # Restore with sfdisk /dev/xvda < /mnt/part_table
umount /mnt

Partition disk, goal is to create new ~1GB partition and dd your iso into it
This is just simple log of input, read how to do it on your own
https://access.redhat.com/articles/1196333
https://access.redhat.com/articles/1190213

# really should use cfdisk instead
# I did log this just for myself
sudo su
fdisk -l /dev/xvda
e2fsck -f /dev/xvda3
resize2fs /dev/xvda3 23G
fdisk /dev/xvda
p
d
3
p
n
p
3
23G # Last sector, Remove ext4 signature? no
p
w
q
fdisk /dev/xvda
n
p
p
w
q

dd archlinux.iso pipe from wget

# check if url valid
wget -S --spider http://archlinux.ip-connect.vn.ua/iso/2018.06.01/archlinux-2018.06.01-x86_64.iso -O /dev/null
# dd
wget http://archlinux.ip-connect.vn.ua/iso/2018.06.01/archlinux-2018.06.01-x86_64.iso -q -O -|dd of=/dev/xvda4 bs=4M

Add grub boot record

reboot # boot into current primary os
nano /etc/grub.d/40_custom
#/etc/grub.d/40_custom
menuentry "/dev/xvda4 archlinux-2018.06.01-x86_64.iso" {
    linux (hd0,msdos4)/arch/boot/x86_64/vmlinuz archisobasedir=arch archisolabel=ARCH_201806
    initrd (hd0,msdos4)/arch/boot/intel_ucode.img
    initrd (hd0,msdos4)/arch/boot/x86_64/archiso.img
}
# One of
grub2-mkconfig -o /boot/grub2/grub.cfg
grub-mkconfig -o /boot/grub/grub.cfg
reboot

Install archlinux

Just instructions for myself
Example is done using Ukraine mirrors, and Europe/Kiev timezone

Static IP network setup

ip addr add 203.0.113.2/24 dev eth0
ip route add default via 203.0.113.1 dev eth0
echo "nameserver 8.8.8.8" > /etc/resolv.conf
ip link set dev eth0 up
ping -c 4 google.com

System clock

timedatectl set-ntp true
timedatectl status

Partition disks, use whatever you want, in the end required /boot && /swap && / filesystems
Create fs and mount

cfdisk /dev/xvda
# /dev/xvda1 512MiB type 83 bootable
# /dev/xvda2 512MiB type 82 swap
# /dev/xvda3 type 83 all free space, rootfs
# /dev/xvda4 untouched cause this is arch iso bootable partition (optional from previous steps on VPS install)
mkfs.ext4 /dev/xvda1
mkswap /dev/xvda2
swapon /dev/xvda2
mkfs.ext4 /dev/xvda3
mount /dev/xvda3 /mnt
mkdir /mnt/boot
mount /dev/xvda1 /mnt/boot

Select mirrors

cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
sed -i 's/^Server/#Server/' /etc/pacman.d/mirrorlist
sed -i '/Ukraine/,/^\s*$/s/^#Server/Server/' /etc/pacman.d/mirrorlist

Install base, and whatever you want

pacstrap /mnt base base-devel
pacstrap /mnt nano htop tmux openssh

FSTAB

genfstab -U /mnt >> /mnt/etc/fstab

CHROOT

arch-chroot /mnt

Time zone && hwclock

ln -sf /usr/share/zoneinfo/Europe/Kiev /etc/localtime
hwclock --systohc

Locale

nano /etc/locale.gen
#/etc/locale.gen
en_US.UTF-8 UTF-8
en_US ISO-8859-1
#
locale-gen
nano /etc/locale.conf
#/etc/locale.conf
LANG=en_US.UTF-8
#

Hostname

echo "vps01" > /etc/hostname
nano /etc/hosts
#/etc/hosts
127.0.0.1       localhost
::1             localhost
203.0.113.2     vps01.localdomain vps01
#

Network netctl

nano /etc/netctl/ethernet-eth0
#/etc/netctl/ethernet-eth0
Description='A basic static ethernet connection'
Interface=ens3
ExcludeAuto=no
Connection=ethernet
Priority=10
DNSOptions=('resolv_conf_local_only=no')
DNS=('8.8.8.8' '8.8.4.4' '208.67.222.222' '208.67.220.220' '2001:4860:4860::8888' '2001:4860:4860::8844')

IP=static
Address=('203.0.113.2/24')
Gateway='203.0.113.1'

IP6=static
Address6=('2001:DB8::11b/48')
Gateway6='2001:DB8::1'
#
pacman -S ifplugd
systemctl enable netctl-ifplugd@eth0

Initramfs

mkinitcpio -p linux

Root password

passwd # https://www.grc.com/passwords.htm

Bootloader
grub is actually v2, old grub is grub-legacy
target=i386-pc is valid for non efi, mbr either 64/32 bit os
Look other args (for efi) inside archlinux wiki

pacman -S intel-ucode grub
grub-install --target=i386-pc /dev/xvda
nano /etc/grub.d/40_custom
#/etc/grub.d/40_custom
menuentry "/dev/xvda4 archlinux-2018.06.01-x86_64.iso" {
    linux (hd0,msdos4)/arch/boot/x86_64/vmlinuz archisobasedir=arch archisolabel=ARCH_201806
    initrd (hd0,msdos4)/arch/boot/intel_ucode.img
    initrd (hd0,msdos4)/arch/boot/x86_64/archiso.img
}
#
grub-mkconfig -o /boot/grub/grub.cfg

Exit and reboot

exit
umount -R /mnt
reboot

Post boot optional

pacman -S haveged
systemctl enable haveged
systemctl start haveged

Backup fresh drive with dd to ftp if you have one
http://www.barryhubbard.com/linux/ghost-hard-drive-to-an-ftp-server/

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