Skip to content

Instantly share code, notes, and snippets.

@tr3buchet
Last active July 5, 2023 11:26
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save tr3buchet/6407920 to your computer and use it in GitHub Desktop.
Save tr3buchet/6407920 to your computer and use it in GitHub Desktop.
debian usb debootstrap

make sure any needed utilities are installed

sudo aptitude install debootstrap coreutils util-linux e2fsprogs

get usb device

df -h

unmount the usb device (supposing it is /dev/sdb1)

sudo umount /dev/sdb1

wipe and make 1 partition

sudo fdisk /dev/sdb
 - o   create a new empty DOS partition table
 - p   print the partition table
 - n   add a new partition
    - use all defaults
 - a   toggle a bootable flag
    - use partition 1
- w   write table to disk and exit

put a new filesystem on it

# for non usb i'd use ext4
sudo mkfs.ext4 /dev/sdb1

# for usb i'd use ext2
sudo mkfs.ext2 /dev/sdb1

mount usbstick in filesystem

mkdir ~/tmp/usbstick -p
sudo mount /dev/sdb1 /home/grumpy/tmp/usbstick

install base system

sudo debootstrap --arch amd64 wheezy /home/grumpy/tmp/usbstick http://ftp.debian.org/debian/

sudo debootstrap --arch amd64 jessie /home/grumpy/tmp/usbstick http://mirror.rackspace.com/debian/

go into usb chroot env

sudo mount -t proc none $HOME/tmp/usbstick/proc
sudo mount --bind /sys $HOME/tmp/usbstick/sys
sudo mount --bind /dev $HOME/tmp/usbstick/dev
sudo cp /etc/resolv.conf $HOME/tmp/usbstick/resolv.conf
sudo chroot $HOME/tmp/usbstick/

update sources.list

# my sources.list
deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free

deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free

# wheezy-updates, previously known as 'volatile'
deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free

install a few useful things

aptitude update
aptitude install locales sudo vim ntp openssh-client openssh-server tmux

configure networking

add the following to /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

add the following to /etc/hosts

127.0.1.1      your_hostname

configure timezone/locale

# setup timezone
dpkg-reconfigure tzdata

# i choose en_US.UTF-8
dpkg-reconfigure locales

make sure ntp is rocking

ntpq -p
date -R

# and if necessary..
dpkg-reconfigure ntp

add any users (and my add to sudoers)

adduser grumpy
adduser grumpy sudo

# or if no adduser
usermod -G sudo -a grumpy

prepare boot parameters

aptitude install grub-pc linux-base linux-image-amd64
# when the "Configuring grub-pc" menu pops up I selected "/dev/sdb"

setup /etc/fstab

blkid /dev/sdb1 -o export | head -n 1 > /etc/fstab

then edit /etc/fstab to look something like this:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
UUID=5763e67c-53f4-448c-8376-d371c24f4057       /       ext4    errors=remount-ro       0       1

exit chroot, unmount and see if it worked!

exit
sudo umount $HOME/tmp/usbstick/sys
sudo umount $HOME/tmp/usbstick/dev
sudo umount $HOME/tmp/usbstick/proc
sudo umount $HOME/tmp/usbstick/

special thanks

a good deal of my steps were gleaned from reading this

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