Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please Support Debian ( sample code included ) #3085

Open
anasouardini opened this issue Jan 7, 2025 · 1 comment
Open

Please Support Debian ( sample code included ) #3085

anasouardini opened this issue Jan 7, 2025 · 1 comment

Comments

@anasouardini
Copy link

anasouardini commented Jan 7, 2025

describe the request

I'm a noob when it comes to Linux but I know for a fact that it's possible to bootstrap any Linux OS from any other Linux OS.

I just hate the preseeding method that Debian offers with the straight useless documentation they have and the only way I can automate my Debian installation is through bootstraping (using bootstrap), which is nice and all, but having a put-together script is not like the method that ArchInstall does which by using a config file.

Even though the "Arch BTW" still won't die, I know that the best and easy OS installer ever is ArchInstall and I'd love to use to install Debian for my mini servers at home.

I just want to provide urls form ArchInstall for each of my one of machines and just watch it set them up while doing something else. This would make Arch also carry Debian users for the installation and not just their internal tools troubleshooting 😆

Also if there is a tool that does this, please point me in that direction.

I've already tinkered with the debootstrap tool as I said, I don't know how much help would be to write this small script but here it is:

#!/bin/bash

printGreen() {
	printf '\033[1;32m> %s\033[0m\n' "$@" >&2 # bold Green
}
printRed() {
	printf '\033[1;31m> %s\033[0m\n' "$@" >&2 # bold Red
}

[[ $(whoami) = 'root' ]] || printRed "Err -> you have to run the script as root" && exit 1

mountPath=/mnt
mirror=http://ftp.es.debian.org/debian/
distribution=bookworm # 2nd half of 2025, trixi would be used here
arch=amd64
partTableType='msdos'

function setup() {
	printGreen "Pick a device:"
	lsblk -dno name,size,type,mountpoint | awk '{print NR, ") ", $0}'

	echo ""
	read -p 'Device number: ' deviceNumber

	chosenDevice=$(lsblk -dno name,size,type,mountpoint | sed -n ${deviceNumber}p | awk '{print "/dev/" $1}')

	echo ""
	printGreen "Are you sure you want to format the device ${chosenDevice}? (y/N)"
	read -p "[n] : " isContinue
	if [[ ! $isContinue = "y" ]]; then
		exit 0
	fi

	mountedPath=$(mount | grep $mountPath)
	if [[ -n $mountedPath ]]; then
		printGreen "${mountPath} is being used to mount some device; unmount it first"
		exit 1
	fi

	printGreen "removing potential old GPT label"
	dd if=/dev/zero of=$chosenDevice bs=1M count=2

	printGreen "Partitioning and formatting"
	parted "$chosenDevice" --script mklabel "$partTableType"
	parted "$chosenDevice" --script mkpart primary ext4 1MB 100%
	parted "$chosenDevice" --script set 1 boot on
	yes | mkfs.ext4 -L 'ROOT' "${chosenDevice}1"

	mkdir -p $mountPath
	printGreen "Mounting ${chosenDevice}1 to ${mountPath}"
	mount "${chosenDevice}1" $mountPath

	# Installing debootstrap
	which debootstrap
	if [[ $? != 0 ]]; then
		echo "debootstrap not found. Installing..."
		apt-get update -y
		apt-get install debootstrap -y
	fi

	printGreen "debootstraping..."
	debootstrap --cache-dir=/home/venego/.debootstrap-cache --arch="$arch" "$distribution" "$mountPath" "$mirror"
}

function chrooting(){
  printGreen "Setting up bindings"
  mount --make-rslave --rbind /dev $mountPath/dev
  mount --make-rslave --rbind /proc $mountPath/proc
  mount --make-rslave --rbind /sys $mountPath/sys
  mount --make-rslave --rbind /run $mountPath/run
  
  printRed "--------- Changing rootfs to ${mountPath}"
  
  # printGreen "Adding non-free and contrib repos"
  # chroot $mountPath /bin/bash -c "echo 'deb http://ftp.es.debian.org/debian ${distribution} main contrib non-free-firmware' > /etc/apt/sources.list && apt update -y"
  printGreen "Installing kernel and grub packages"
  chroot $mountPath /bin/bash -c "apt install linux-image-amd64 firmware-linux-free network-manager grub2 -y"
  printGreen "Installing grub"
  chroot $mountPath /bin/bash -c "grub-install ${chosenDevice} && update-grub"
  printGreen "setting password for root"
  # literlly repeating the password twice using echo :)
  chroot $mountPath /bin/bash -c "printf "root\nroot\n" | passwd root"
  
  printGreen "Unounting ${chosenDevice}"
  umount -R $mountPath
}

function testing(){
  testing in a VM
  printGreen "Booting ${chosenDevice} in Qemu"
  qemu-system-x85_64 -machine accel=kvm:tcg -m 512 -hda $chosenDevice
}

setup
chrooting
# testing
@svartkanin
Copy link
Collaborator

Feel free to raise a PR with the Debian profile configuration and setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants