Skip to content

Instantly share code, notes, and snippets.

@sfloess
Last active March 26, 2024 17:03
Show Gist options
  • Save sfloess/e08619d152050d8da7f7452a1845a7f1 to your computer and use it in GitHub Desktop.
Save sfloess/e08619d152050d8da7f7452a1845a7f1 to your computer and use it in GitHub Desktop.
Debian Tips and Tricks

Debian

Tips and Tricks for Debian.

Install

List Installed Packages

Installed packages can be listed as follows:

  • apt list --installed
  • dpkg-query -l

See Contents of a .deb file

To see the contents of a .deb file, perform the following:

  1. apt-get update && apt-get install apt-file
  2. apt-file update
  3. apt-file list [deb file]

add-apt-repository

To install add-apt-repository, perform the following:

  1. apt update
  2. apt -y install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates
  3. add-apt-repository ppa:PPA Name]
  4. apt update
  5. apt install [package]

Repos

Ensure dpkg-dev is installed:

apt-get install dpkg-dev

Create

Local

To create a local repo:

dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

Proper

To create a proper repo:

dpkg-scanpackages -m -a [arch] [dir] | gzip > [dir]/Packages.gz

Example
#!/bin/bash

cd /opt/shared/repo/apt

echo

for arch in i386 amd64 mips armel armhf
do	
	printf "%-10s" "${arch}:"
	dpkg-scanpackages -m -a ${arch} pool | gzip > dists/buster/main/binary-${arch}/Packages.gz
done

echo

Trust a Repo

To trust a repo, /etc/apt/sources.list:

deb [ trusted=yes ] http://ftp.us.debian.org/debian/ jessie main contrib non-free

Upgrade Stretch to Buster

To upgrade from Stretch to Buster, perform the following:

  1. apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138
  2. grep -rl stretch /etc/apt/ | sudo xargs sed -i 's/stretch/buster/g'
  3. apt update -y && apt dist-upgrade -y
  4. reboot

Creating a rootfs

To create a rootfs of Debian perform the following (note you may want to ignore the pgp check using debootstrap --no-check-gpg --arch=$arch --foreign $distro $targetdir vs debootstrap --arch=$arch --foreign $distro $targetdir below):

apt-get install -y qemu-user-static debootstrap binfmt-support qemu-system-arm

distro=bookworm
arch=armhf
targetdir="${distro}_${arch}"

mkdir $targetdir
debootstrap --arch=$arch --foreign $distro $targetdir

cp /usr/bin/qemu-arm-static $targetdir/usr/bin/
cp /etc/resolv.conf $targetdir/etc

chroot $targetdir

distro=bookworm
export LANG=C

/debootstrap/debootstrap --second-stage

cat <<EOT > /etc/apt/sources.list
deb http://ftp.debian.org/debian $distro main contrib non-free
deb http://ftp.debian.org/debian $distro-updates main contrib non-free
EOT


apt-get update -y
apt-get upgrade -y

apt-get install -y dialog locales lsb-release ntp ntpdate openssh-server rsync sshfs vim htop wget curl screen

dpkg-reconfigure locales
dpkg-reconfigure tzdata

passwd

chroot

ping: address family not supported by protocol

  • apt-get remove -y inetutils-ping
  • apt-get install -y inetutils-ping

dnsmasq

  • Don't use a dnsmasq lease file: /etc/default/dnsmasq: DNSMASQ_OPTS="--leasefile-ro"
  • Leases stored in /var/lib/misc/dnsmasq.leases

How-To

Quickies

  • Configure
    • locale: dpkg-reconfigure locales
    • time zone: dpkg-reconfigure tzdata
    • dpkg --configure -a
  • Nic: inet 169.254.244.144/16 brd 169.254.255.255 scope global enp1s0
    • /etc/networks: rm link-local 169.254.0.0
  • Install LXDE: apt-get install task-lxde-desktop
  • Import Key
    • gpg --keyserver keyring.debian.org --recv-keys [key]
    • gpg --recv-keys [key]
    • gpg -a --export [key] | sudo apt-key add -

RPM to Deb

To convert an rpm to a deb file, execute: alien --scripts [rpm file]

Example: alien --scripts bluejeans-1.37.22.x86_64.rpm

Generate Seed Files

Once a machine/VM is setup, you can generate a seed file containing the setup (be sure to install debconf-utils):

  • Settings from installation: debconf-get-selections --installer
  • Current settings: debconf-get-selections

Setup a Bridge

Directions

  • apt-get install aptitude network-manager -y
  • aptitude install bridge-utils
  • systemctl enable NetworkManager
  • The file /etc/network/interfaces.d/[bridge name] should resemble:
auto [bridge name]

# Bridge setup
 iface [bridge name] inet dhcp
    bridge_ports [ethernet]

As an example a bridge named bridge0 and ethernet enp1s0:

auto bridge0

 iface bridge0 inet dhcp
    bridge_ports enp1s0

Additionally you must also modify your /etc/network/interfaces to be:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

Enable wake-on-lan

Ensure you install ethtool: apt install ethtool

auto [bridge name]

# Bridge setup
 iface [bridge name] inet dhcp
    bridge_ports [ethernet]
    /usr/sbin/ethtool -s [ethernet] wol g

As an example a bridge named bridge0 and ethernet enp1s0:

auto bridge0

 iface bridge0 inet dhcp
    bridge_ports enp1s0
    /usr/sbin/ethtool -s enp1s0 wol g

tftpd-hpa

If not running IPv6, /etc/default/tftpd-hpa should resemble:

# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure -4"

The -4 represents "use IPv4."

Files

  • The domainname: /etc/defaultdomain

ddclient

  • /etc/default/ddclient
run_dhclient="false"
run_ipup="false"
run_daemon="true"
daemon_interval="300"

OpenStack

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