Skip to content

Instantly share code, notes, and snippets.

@adamsdesk
Created July 9, 2014 16:18
Show Gist options
  • Save adamsdesk/2c1faa68a6b28a261a85 to your computer and use it in GitHub Desktop.
Save adamsdesk/2c1faa68a6b28a261a85 to your computer and use it in GitHub Desktop.
How to Create a Custom USB Debian Installer
This custom installer assumes to use the Debian Wheezy 32-bit/AMD 64-bit.
Example of preseed file http://www.debian.org/releases/stable/example-preseed.txt.
- Plug the USB flash drive into a Linux based system.
- # sudo blkid
* Note the device name for the USB flash drive to be used in the next step.
- Use gParted or fdisk or cfdisk to create the following on the USB flash drive.
- Create as: Primary Partition
- Free space preceding (MIB): 1
- Free space following (MIB): 0
- File system: ext4
- Label: deb-install
- Manage newly created partition flags, set "boot".
- # sudo mkdir /mnt/usb
- # sudo mount /dev/sdb1 /mnt/usb
* Note: Replace "sdb1" with the applicable device name for the USB flash drive and the partition number should be "1".
- # sudo grub-install %%--%%force %%--%%no-floppy %%--%%root-directory=/mnt/usb /dev/sdb
* Note: Replace "sdb" with the applicable device name for the USB flash drive. The device name should not have a number at the end. The number represents the partition, we want to just go directly to the device into the MBR (master boot record).
- # sudo mkdir /mnt/usb/hdmedia-wheezy
- # sudo wget http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/hd-media/vmlinuz -O /mnt/usb/hdmedia-wheezy/vmlinuz
* 32-bit: # sudo wget http://ftp.debian.org/debian/dists/wheezy/main/installer-i386/current/images/hd-media/vmlinuz -O /mnt/usb/hdmedia-wheezy/vmlinuz
- # sudo wget http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/hd-media/initrd.gz -O /mnt/usb/hdmedia-wheezy/initrd.gz
* 32-bit: # sudo wget http://ftp.debian.org/debian/dists/wheezy/main/installer-i386/current/images/hd-media/initrd.gz -O /mnt/usb/hdmedia-wheezy/initrd.gz
- # sudo mkdir /mnt/usb/isos
- # wget http://cdimage.debian.org/debian-cd/7.5.0/amd64/iso-cd/debian-7.5.0-amd64-CD-1.iso
* 32-bit: # wget http://cdimage.debian.org/debian-cd/7.5.0/i386/iso-cd/debian-7.5.0-i386-CD-1.iso
* Download ISO to a temporary location.
- # sudo cp debian-7.5.0-amd64-CD-1.iso /mnt/usb/isos/
- # sudo nano /mnt/usb/boot/grub/grub.cfg
* Contents of grub.cfg. Make sure to replace "debian-7.5.0-amd64-CD-1.iso" (2) with the corresponding ISO file name.:<file text grub.cfg>
# This is to define colors in the grub menu
#set color_normal='green/black'
#set color_highlight='light-green/black'
set gfxmode=640x480
insmod vbe
font="/boot/grub/unicode.pf2"
loadfont $font
terminal_output gfxterm
insmod png
background_image -m stretch /boot/grub/dsi-bootloader-loading.png
# Define some paths
# The / is the root of the installation media (/dev/sdb1)
set isosdir='/isos'
set hdmediawheezy='/hdmedia-wheezy'
# Below is where the running debian installer will find the preseed file
# Debian installer provided with hd-media images mounts the installation media filesystem
# under /hd-media
set preseed='/hd-media/preseed'
# Manual entry
menuentry 'Debian 7.5.0 (Wheezy) AMD64 Manual Install' {
linux $hdmediawheezy/vmlinuz iso-scan/filename=$isodir/debian-7.5.0-amd64-CD-1.iso priority=critical
initrd $hdmediawheezy/initrd.gz
}
# Automated entry
menuentry 'Debian 7.5.0 (Wheezy) AMD64 Automatic Install' {
linux $hdmediawheezy/vmlinuz iso-scan/filename=$isodir/debian-7.5.0-amd64-CD-1.iso preseed/file=$preseed/standard-wheezy.preseed auto=true priority=critical
initrd $hdmediawheezy/initrd.gz
}
#set default="1"
#set timeout="10"
</file>
- # sudo cp /boot/grub/unicode.pf2 /mnt/usb/boot/grub
- # sudo cp ~/dsi-bootloader-loading.png /mnt/usb/boot/grub
* The image is stored at [[\\serverwin7-pc\c\Groups\R&D\projects\VIP\gfx-loading-media\dsi-bootloader-loading.png]].
- # sudo mkdir /mnt/usb/preseed
- # sudo nano /mnt/usb/preseed/standard-wheezy.preseed
* Contents of standard-wheezy.preseed:<file text preseed>
####################################################################
# PRESEED - Created 2014-04-09 10:33:00
####################################################################
# Wiki: http://wiki.debian.org/DebianInstaller/Preseed
# Great work! Thanks for preseed and the d-i installer
####################################################################
# Installation Sources
####################################################################
# Where are we pulling bits from?
# Note: To use your own local repository, this is what you want
# to edit.
#
# It should look like this:
#d-i mirror/http/hostname string (IP Address of your local server)
#d-i mirror/http/directory string (HTTP Path to your Repository - like /natty )
d-i mirror/http/hostname string ftp.ca.debian.org
d-i mirror/http/directory string /debian/
d-i mirror/suite string wheezy
# Post install APT setup
d-i apt-setup/uri_type select d-i
d-i apt-setup/hostname string ftp.ca.debian.org
d-i apt-setup/directory string /debian/
d-i apt-setup/another boolean false
d-i apt-setup/security-updates boolean false
d-i finish-install/reboot_in_progress note
d-i prebaseconfig/reboot_in_progress note
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
####################################################################
# Networking
####################################################################
d-i netcfg/get_hostname string deb-install
d-i netcfg/get_domain string oz.displaysystemsintl.com
d-i mirror/http/proxy string
d-i netcfg/choose_interface select eth0
d-i netcfg/wireless_wep string
d-i hw-detect/load_firmware boolean false
####################################################################
# Disk Partitioning/Boot loader
####################################################################
# We assume the target computer has only one harddrive.
# In most case the USB Flash drive is attached on /dev/sda
# but sometimes the harddrive is detected before the USB flash drive and
# it is attached on /dev/sda and the USB flash drive on /dev/sdb
# You can set manually partman-auto/disk and grub-installer/bootdev or
# used the early_command option to automatically set the device to use.
#d-i partman/early_command string \
# USBDEV=$(mount | grep hd-media | cut -d " " -f1 | sed "s/\(.*\)./\1/");\
# BOOTDEV=$(list-devices disk | grep -v $USBDEV | head -1);\
# debconf-set partman-auto/disk $BOOTDEV;\
# debconf-set grub-installer/bootdev $BOOTDEV;
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
# This makes partman automatically partition without confirmation.
# Uncomment line below once verified the correct device is being used.
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/mount_style select uuid
# This one makes grub-installer install to the MBR even if finds some other OS
# too, which is less safe as it might not be able to boot that other OS.
d-i grub-installer/with_other_os boolean true
####################################################################
# Localizations
####################################################################
# Install Time
d-i console-tools/archs string skip-config
d-i debian-installer/locale string en_US
d-i keymap select us
d-i debian-installer/language string en
d-i debian-installer/country string CA
d-i localechooser/supported-locales select en_US.UTF-8
# Timezone
d-i tzconfig/gmt boolean false
d-i tzconfig/choose_country_zone/America select Regina
d-i tzconfig/choose_country_zone_single boolean true
d-i time/zone select America/Regina
d-i clock-setup/utc boolean true
d-i kbd-chooser/method select American English
d-i mirror/country string manual
d-i clock-setup/ntp boolean false
####################################################################
# User Creation
####################################################################
# Root User
d-i passwd/root-login boolean false
# Mortal User. Only one can be created at this state.
d-i passwd/user-fullname string
d-i passwd/username string add-username
d-i passwd/user-password-crypted passwd add-password
d-i passwd/user-default-groups string sudo
####################################################################
# Software Selections
####################################################################
d-i base-installer/install-recommends boolean false
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server ntp
popularity-contest popularity-contest/participate boolean false
d-i preseed/late_command string /bin/sh -x /hd-media/scripts/postinstall.sh
####################################################################
# Additional preseed entries (from data/debconf)
####################################################################
exim4-config exim4/no_config boolean true
</file>
- # sudo mkdir /mnt/usb/scripts
- # sudo nano /mnt/usb/scripts/postinstall.sh
* Contents of "postinstall.sh".<file bash postinstall.sh>
#!/bin/sh
# "Post Install Script"
# Copy sshd configuration file. DOES NOT WORK AT POST INSTALL.
#cp /hd-media/repo/sshd_config /target/etc/ssh/
# Changes the behavior of disk checks (fsck) to automatically repair without prompting for user input.
sed -i 's/#FSCKFIX=no/FSCKFIX=yes/' /target/etc/default/rcS
# Set mount count file systen check
# Commented out because I don't think this command can be run at this stage.
# tune2fs -c5 /target/dev/sda1
</file>
- # sudo sync
- # sudo umount /mnt/usb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment