Skip to content

Instantly share code, notes, and snippets.

@sfloess
Last active Sep 9, 2021
Embed
What would you like to do?
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=armhf --foreign $distro $targetdir vs debootstrap --arch=armhf --foreign $distro $targetdir below):

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

targetdir=rootfs
distro=buster

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

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

chroot $targetdir

distro=buster
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-src http://ftp.debian.org/debian $distro main contrib non-free
deb http://ftp.debian.org/debian $distro-updates main contrib non-free
deb-src http://ftp.debian.org/debian $distro-updates main contrib non-free
deb http://security.debian.org/debian-security $distro/updates main contrib non-free
deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free
EOT


apt-get update -y

apt-get install -y dialog locales lsb-release nis ntp ntpdate openssh-server rsync sshfs vim

dpkg-reconfigure locales

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
  • 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]
    ethernet-wol g

As an example a bridge named bridge0 and ethernet enp1s0:

auto bridge0

 iface bridge0 inet dhcp
    bridge_ports enp1s0
    ethernet-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