If you want to install Debian on a new computer, you will need to boot the installer first. A convenient way is to download a CD image and write it to the flash drive, as described in Debian’s FAQ How do I write a CD/DVD/BD image to a USB flash drive. Usually a simple copy (sudo cp debian-testing-amd64-DVD-1.iso /dev/sda) will do.

Note: Make sure to verify that /dev/sda is actually your flash drive!

However, today the capacity of a flash drive exceeds the size of a CD or DVD and thus wasting space. E.g. if you have a 16g usb flash drive, and the first DVD is “just” 3.6g big, you would waste more than 10g…

There is a solution to this problem: Partitioning. You can create an additional partition and thus make the remaining space of the flash drive available. You can then place there the firmware files there, so that the firmware files are available during the installation.

The partitioning is however a bit unusual, since the image debian is providing, is able to boot from CD as well as boot from USB. So, it must be a CD image and at the same time provide a EFI boot partition. This is done, by creating a partition table, that looks like this, after you have written the image to the flash drive:

$ sudo sfdisk -l /dev/sda # assuming your flash drive is available as /dev/sda
Disk /dev/sda: 14,5 GiB, 15504900096 bytes, 30283008 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x71b9b10a

Device     Boot Start     End Sectors  Size Id Type
/dev/sda1  *        0 7562015 7562016  3,6G  0 Empty
/dev/sda2       22184   23015     832  416K ef EFI (FAT-12/16/32)

There are two partitions, and the EFI partition is overlapping the big one… This means, that the EFI partition is actually embedded in the image (where else could it be?). To not confuse any OS, if you plug in the flash drive, the first partition has no type, so that it is ignored.

After the two partitions, there is plenty empty space. So, let’s create a new partition after the two existing ones. I’ll use sfdisk here as a scriptable partitioning tool. See also Using sfdisk to partition disk for some examples on how to use it beyond what is described here.

Note: This will change the partition table of the device, make sure, you reference the correct one (e.g. /dev/sda), otherwise you will loose data!

The flag -a will tell sfdisk, to append a new partition rather than creating a whole new table. We will start the partition after 4g, leaving the first 4g completely to the debian image.

$ echo '4GiB,,c;' | sudo sfdisk -a /dev/sda
Checking that no-one is using this disk right now ... OK

Disk /dev/sda: 14,5 GiB, 15504900096 bytes, 30283008 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x71b9b10a

Old situation:

Device     Boot Start     End Sectors  Size Id Type
/dev/sda1  *        0 7562015 7562016  3,6G  0 Empty
/dev/sda2       22184   23015     832  416K ef EFI (FAT-12/16/32)

/dev/sda3: Created a new partition 3 of type 'W95 FAT32 (LBA)' and of size 10,5 GiB.
/dev/sda4: Done.

New situation:
Disklabel type: dos
Disk identifier: 0x71b9b10a

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *          0  7562015  7562016  3,6G  0 Empty
/dev/sda2         22184    23015      832  416K ef EFI (FAT-12/16/32)
/dev/sda3       8388608 30283007 21894400 10,5G  c W95 FAT32 (LBA)

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

You can see in the “new situation”, that the first two partitions are not touched and a new partition (/dev/sda3) has been added and uses the remaining space. The type is c, which is suitable for a big FAT32 partition.

As last step, we need to format the new partition:

$ sudo mkfs.vfat -n "LABEL" /dev/sda3

And you can store the firmware files there, so you have everything in one place for installing debian.

And there is still space left, so you can use the flash drive as usual.

One important last step is missing: The bootable cd also brings a GPT with it. But we added the new partition only in the MBR. So, operating systems, that prefer GPT over MBR won’t see the data partition. In order to fix this, we’ll remove the GPT completely and only use the MBR:

sudo sgdisk -z /dev/sda

That’s all.

One note on how to update the debian image later on without loosing data: You need to make sure, that the new CD/DVD image does not exceed 4g (which is the offset of our data partition). After you have written the CD/DVD image to the flash drive, you need to recreate the data partition. You can use the same sfdisk command as above (make sure to use the same offset of 4GiB). That’s all, your data should be still there. Also, don’t forget to remove the GPT again.