Contents

  1. Instructions to make a boot drive, that boots both in UEFI and BIOS mode
    1. Cloning - read-only drive
    2. Do it yourself - with the extraction method
  2. Do it yourself - instructions
    1. Download a compressed image file
      1. You need this step only if you want to boot in BIOS mode
      2. Partition table and boot structure from an image file
      3. Do also this step manually
      4. Download the image file and a checksum file
    2. Download the iso file
      1. 64-bit Ubuntu desktop or Ubuntu community flavour desktop iso file
      2. 64-bit Debian live iso file
      3. 64-bit Windows 7--11 iso file
      4. Check with md5sum that the iso file was downloaded correctly
      5. Create mountpoint /mnt/lp1
      6. Loop mount the iso file
      7. In a Windows iso file, check the size of the biggest file
      8. If a file in the iso file exceeds 4 GiB
    3. Install mkusb if you want to clone safely and easily (optional)
    4. Clone 'grub-do-it-yourself.img.xz' to the target drive
      1. Use mkusb or Disks
      2. Use dd to clone in a risky way
      3. Use Win32 Disk Imager to clone in Windows
    5. Mount the target drive
      1. Create mountpoint and /mnt/sd1
      2. Mount the partition on the USB pendrive or memory card
    6. Copy the content from the iso file to the target partition
      1. rsync
      2. Alternative 1
      3. Alternative 2
    7. Flush the buffers
    8. Now you have a live-only boot drive :-)
      1. Unmount the partition on the target drive and unplug it
    9. Continue if you wish
      1. Create a new partition for storage
    10. Make an Ubuntu persistent live drive
      1. casper-rw file
      2. Alternative - sharing free space between 'casper-rw' and 'home-rw'
      3. casper-rw partition
      4. Let Ubuntu create the partition for persistence automatically
      5. Edit grub.cfg
      6. Save the edited file and exit from the editor
    11. Now you have a drive with a second partition and/or persistence :-)
      1. Unmount the mounted partition on the target drive and unplug it
    12. Persistence with Debian 10 live
      1. partition for persistence
      2. Edit grub.cfg
      3. Create persistence.conf
      4. Flush the buffers, inform the kernel and unmount the partitions
  3. Check that your new boot drive works


Return to the main iso2usb page


Instructions to make a boot drive, that boots both in UEFI and BIOS mode

Cloning - read-only drive

If you are happy with a read-only partition table and file system, you can clone the Ubuntu and Ubuntu community flavour iso files. This is very reliable but you cannot store data on the drive, and you cannot make it a persistent live drive (unless you start again for example with mkusb). Return if this is what you want.

Do it yourself - with the extraction method

The simple extraction method for UEFI mode is extended to BIOS mode and described with detailed instructions.

This method is designed to work with

  • Ubuntu: 64-bit Ubuntu desktop and Ubuntu community flavour desktop iso files

  • Debian live (version 10--11) 64-bit iso files

  • Windows: 64-bit Windows (8--11) iso files

    • Windows 7 boots only in BIOS mode
    • Several Windows 10 all Windows 11 iso files and contain a version of the file install.wim with size > 4 GiB. It means that this method does not work because the FAT32 file system cannot manage it. There is a detailed description of a modified method at this link: /windows-installer-for-big-files See also this link.

Other linux distros and versions: This method may or may not work in UEFI and/or BIOS mode depending on the boot structure. It helps if it is similar to Ubuntu's boot structure.

  • Linux Mint: From 'linuxmint-18.1-cinnamon-64bit.iso' you get a USB drive that boots in UEFI and BIOS mode, and you can make it persistent live.
  • Debian 9, Stretch: From 'debian-live-9.0.1-amd64-cinnamon.iso', you get a USB drive that boots only in BIOS mode. The structure for booting and persistence is different from Ubuntu. (A cloned live-only USB drive can boot in UEFI and BIOS mode; If you wish, mkusb can create a USB drive that boots in UEFI and BIOS mode, and make it persistent live.)

Do it yourself - instructions

Download a compressed image file

You need this step only if you want to boot in BIOS mode

An extracted system boots directly in UEFI mode. When this is enough, you need no bootloader for BIOS mode, but it is also a convenient method to get the partition table and boot structure.

Partition table and boot structure from an image file

A compressed image file can be extracted and flashed to the target drive in order to get partition table and the boot structure necessary for booting via grub in BIOS mode. This works also when you are running an installed system booted in UEFI mode, when there are problems to install 'grub-pc' and run 'grub-install' in order to install the bootloader (for BIOS mode).

Do also this step manually

Otherwise, in BIOS mode and running a live system, it is possible to create the boot structure for BIOS mode with a FAT32 partition and extract from the iso file into it and install the bootloader.

sudo grub-install

So if you want to do also this step yourself, boot in BIOS mode and create it. You may need to add some flags to the FAT32 partition to make a computer want to boot into it also in UEFI mode.

The structure created, when you use the compressed image file can be used to check what you need in order to get a system that works in both boot modes. (This is easiest, if you have two USB pendrives, one where you do it yourself, and one with the extracted partition table and boot structure.)

Download the image file and a checksum file

Download this compressed image file: grub-do-it-yourself.img.xz

Check that the md5sum is correct with the following file: grub-do-it-yourself.img.xz.md5.asc

You may want a higher level of security. This file is signed with gpg and you can verify it according to the following commands.

gpg --keyserver keyserver.ubuntu.com --recv-keys EB0FC2C8
gpg --verify grub-do-it-yourself.img.xz.md5.asc 

The warning "was NOT verified" means that there is no chain of trusted keys between your computer's keyring and the key, that was used to sign the checksums (the key of sudodus). Check that the result matches with the following output, when you verify it,

tester@xenial32 ~ $ gpg --keyserver keyserver.ubuntu.com --recv-keys EB0FC2C8
gpg: directory `/home/tester/.gnupg' created
gpg: new configuration file `/home/tester/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/tester/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/tester/.gnupg/secring.gpg' created
gpg: keyring `/home/tester/.gnupg/pubring.gpg' created
gpg: requesting key EB0FC2C8 from hkp server keyserver.ubuntu.com
gpg: /home/tester/.gnupg/trustdb.gpg: trustdb created
gpg: key EB0FC2C8: public key "Nio Sudden Wiklund (sudodus) <address@mailserver.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

tester@xenial32 ~ $ gpg --verify grub-do-it-yourself.img.xz.md5.asc
gpg: Signature made mån 18 sep 2017 21:48:47 CEST using RSA key ID EB0FC2C8
gpg: Good signature from "Nio Sudden Wiklund (sudodus) <nio.wiklund@gmail.com>"
gpg: WARNING: not a detached signature; file 'grub-do-it-yourself.img.xz.md5' was NOT verified!
tester@xenial32 ~ $ 

Then there is reason to trust that nobody else has written the checksums. The date of the signature will change at updates, and the text might be translated to your local language, but it should be clear that it is a 'Good signature from "Nio Sudden Wiklund (sudodus)"'.

If you have the compressed image file and the md5sum file in the same directory, you can use the md5sum program to check like this,

md5sum -c grub-do-it-yourself.img.xz.md5.asc

tester@xenial32 ~ $ md5sum -c grub-do-it-yourself.img.xz.md5.asc
grub-do-it-yourself.img.xz: OK
md5sum: WARNING: 14 lines are improperly formatted

The 'improperly formatted lines' are the lines belonging to the gpg signature.

Download the iso file

Download the iso file

64-bit Ubuntu desktop or Ubuntu community flavour desktop iso file

http://releases.ubuntu.com or for the community flavours http://cdimage.ubuntu.com

If the iso files of the version with the longest remaining support are not found via those links, you can find them via the following general link,

http://old-releases.ubuntu.com

and right now, when this is written, you want to find Ubuntu 16.04.1 LTS via the following link,

http://old-releases.ubuntu.com/releases/xenial

or

64-bit Debian live iso file

You find current Debian iso files via www.debian.org/CD/live/

or

64-bit Windows 7--11 iso file

You find Windows iso files via Microsoft's web pages (and you need a license key to use it later on).

Check with md5sum that the iso file was downloaded correctly

Check the md5sum result with the uploaded values via this link: UbuntuHashes

Examples:

md5sum ubuntu-22.04.1-desktop-amd64.iso

md5sum ubuntu-23.04-desktop-amd64.iso

md5sum debian-live-11.6.0-amd64-standard.iso

md5sum Win10_US_x64.iso

Create mountpoint /mnt/lp1

Create the mountpoint only once.

sudo mkdir -p /mnt/lp1

Loop mount the iso file

sudo mount -o loop file.iso /mnt/lp1

for example

sudo mount -o loop ubuntu-22.04.1-desktop-amd64.iso /mnt/lp1
sudo mount -o loop Win10_US_x64.iso /mnt/lp1

In a Windows iso file, check the size of the biggest file

When you have loop mounted a Windows iso file, you should check the size of the biggest file, often '''install.wim'''. If it is > 4GiB, you need an ntfs partition. You can look for the biggest file with the following command line,

find /mnt/lp1 -ls|sort -nk7|tail -n1

Convert from bytes to MiB (you can divide by 2^30 in bc).

You can find all files that exceed the limit directly with the following command line,

find /mnt/lp1 -size +4G -printf "%11s %p\n" | sort -n

If a file in the iso file exceeds 4 GiB

If a file exceeds the limit, you should download and use another compressed image file, that provides two partitions, one with the file system FAT16 and one with NTFS, that can manage the big file.

There is a detailed description at this link: /windows-installer-for-big-files

Install mkusb if you want to clone safely and easily (optional)

https://help.ubuntu.com/community/mkusb

Clone 'grub-do-it-yourself.img.xz' to the target drive

Normally you would clone grub-do-it-yourself.img.xz to a USB pendrive or memory card, minimum size 8GB. The image extracts to 7744 MB. There is a margin for undersized 8 GB pendrives and cards. Please unmount all partitions on the target drive before cloning.

Use mkusb or Disks

Use mkusb or Disks to clone in a safe way, via the GUI or using mkusb-dus

dus grub-do-it-yourself.img.xz

or

Use dd to clone in a risky way

Avoid this method if you can, because it is risky.

Identify the target drive. You can use lsblk without options or better, copy and paste the following command line

lsblk -d -o name,vendor,model,type,size,hotplug

Make sure there are no mounted partitions in the target drive

sudo umount /dev/sdX?

where X is the drive letter of the target drive, and then use the correct drive letter in the cloning command line

xzcat -c grub-do-it-yourself.img.xz | sudo dd of=/dev/sdX bs=4096

where X is the drive letter of the target drive. Check that the drive letter is correct, and double-check the details of the whole command line. A minor typing error might overwrite your family pictures.

Flush the buffers and inform the kernel of the new partition table

sync

sudo partprobe

Use Win32 Disk Imager to clone in Windows

Mount the target drive

Create mountpoint and /mnt/sd1

Create mountpoint only once.

sudo mkdir -p /mnt/sd1

Mount the partition on the USB pendrive or memory card

Identify the target drive. You can use lsblk without options or better, copy and paste the following command line

lsblk -d -o name,vendor,model,type,size,hotplug

or blkid, grep and cut, copy and paste the following command line

sudo blkid |grep DIDITMYSELF|cut -d ' ' -f 1-2

and then use the correct drive letter in the mounting command line

sudo mount /dev/sdX1 /mnt/sd1

where X is the drive letter of the target drive. Double-check that the drive letter is correct.

Copy the content from the iso file to the target partition

rsync

sudo rsync -r --info=progress2 /mnt/lp1/ /mnt/sd1

There may be some warning and error messages from the rsync copying process. Some links cannot be understood and some permissions cannot be preserved by the FAT32 file system in the target partition. But the result will still be a useful system in the drive.

But I have seen cases, when running in some versions of 32-bit Ubuntu systems, where rsync does not copy all the files correctly. They are truncated (too small). When this happens the system in the drive will not work. rsync did not notice it; there was no warning or error message about this problem.

Alternative 1

You can use mkusb for the whole process instead. It is made and tested to manage these cases, where rsync truncates some files.

Alternative 2

You can try to extract the content from the iso file to the target partition with your favourite tool for compressed files, for example

1. 7z (via the package p7zip-full) in Ubuntu and

2. 7-zip in Windows.

Flush the buffers

sync

Now you have a live-only boot drive :-)

Unmount the partition on the target drive and unplug it

sudo umount /mnt/sd1

Check that no partition on the target drive is mounted with

df

(and you can unmount the iso file too

sudo umount /mnt/lp1

but it is mounted read-only, and not dangerous to leave mounted)

In Windows you should eject the drive and wait until it is 'safe to remove the device'.

or

Continue if you wish

Create a new partition for storage

If there is space enough (if the drive contains more than 8 GB), create a second partition. It is easy to use gparted to create the second partition.

Make an Ubuntu persistent live drive

casper-rw file

(The old method for persistence is a file system in a file. Today it is usually better to use a partition for persistence.)

Create a file with the name 'casper-rw'. There is free space in the FAT32 partition for the maximum 4 GB size. The partition must be mounted.

sudo mount /dev/sdX1 /mnt/sd1  # replace X with the actual drive letter like you did before
sudo dd if=/dev/zero of=/mnt/sd1/casper-rw bs=1M count=4095

and create an 'ext2' file system inside the file

sudo mkfs.ext2 /mnt/sd1/casper-rw

Alternative - sharing free space between 'casper-rw' and 'home-rw'

You can use almost all (say 95%) of the remaining free space shared between a 'casper-rw' file and a 'home-rw' file. Decide how much to use for each of them depending on how you intend to use the drive: to install programs and/or to store data.

casper-rw partition

If you have a USB pendrive (or memory card or SSD via USB adapter), that is bigger than 8 GB, it can be better to use a partition for persistence. This way you can use the whole drive. It works with

  • Ubuntu 19.10
  • Debian 10 live

and we expect that it will work with newer versions of Ubuntu and Debian.

Again check carefully that you create the partition for persistence in the correct drive X.

sudo fdisk /dev/sdX
n
<press the Enter key>
<press the Enter key>
<press the Enter key>
w

and create an 'ext2' file system in the partition

sudo mkfs.ext2 -L casper-rw /dev/sdX2

You can also use gparted to create the second partition. In that case, remember the label casper-rw.

There is an obvious advantage with journaling: the file system will be more robust. So if you think your system will be responsive enough, and you can accept more wear, create an ex4 file system with mkfs.ext4 instead of the ext2 file system.

Let Ubuntu create the partition for persistence automatically

This method is convenient, but tests indicate that the system will sometimes get unresponsive as if it were swapping when the system is created in Ubuntu 18.04.x LTS. This is different from when the same ext4 file system with journaling is created manually or the system is created in an installed Ubuntu 19.10 system. It seems to be more responsive when the boot option toram is added alongside persistent in the grub menuentry.

The cause is [not yet] identified. There is no error as checked by e2fsck -f. Maybe some different setting in the file system can be identified. Maybe the partition boundaries are not optimal when created automatically. Something seems not quite compatible, when part of the system is created manually in 18.04.x LTS and part is created automatically in 19.10.

See also the bug report #1851123 'Ubuntu 19.10 and focal live cloned create and mount casper-rw partition'. The problem is that it is mounted and busy, so that it cannot be unmounted when running live-only. The bug is fixed in casper version 1.432, which is available in the Focal Fossa current daily iso files (starting at 2019-11-14). The casper-rw partition will not be mounted when you boot with the boot option toram or todisk. Of course there will be persistence with the boot option persistence, even when you add toram. You can also use the boot option nopersistent with Ubuntu 19.10 iso files as well as with Focal Fossa daily iso files to avoid mounting the casper-rw partition.

In Ubuntu 19.10 with the system files in a FAT32 partition, if you create

  • neither a casper-rw file
  • nor a casper-rw partition,
  • and there is space available in the USB drive,

the Ubuntu system (I think software in the package 'casper') will do it for you the first time that you boot into the USB drive.

This will happen even if you don't add the boot option 'persistent', which might be irritating, but it can also be very useful, because it makes it easier to create a working persistent live system in Windows.

I noticed that the file system ext4 with journaling was created automatically. Due to journaling it can make the system slow, particularly if the USB drive is slow. You can tweak ext4 by turning off journaling or use the simpler ext2 which lacks journaling. You will also reduce wear when there is no journaling (with ext2 or with ext4 with journaling turned off).

There is an obvious advantage with journaling: the file system will be more robust. So if you think your system will be responsive enough, let Ubuntu create the partition for persistence automatically and keep journaling.

Edit grub.cfg

The first partition must be mounted.

sudo mount /dev/sdX1 /mnt/sd1  # replace X with the actual drive letter like you did before

Edit the file /mnt/sd1/boot/grub/grub.cfg to add the boot option persistent to the line starting with linux

linux ... quiet splash persistent ---

and if there is enough RAM in the computer(s) you can copy the content of the iso file to RAM with the boot option toram

linux ... quiet splash persistent toram ---

You may want an extra menuentry for maintenance (backup and repair) of your casper-rw partition.

  • copy the menuentry, that you edited
  • modify it to have the boot option nopersistent and maybe toram

linux ... quiet splash nopersistent ---

Save the edited file and exit from the editor

Now you have a drive with a second partition and/or persistence :-)

Now you have a drive with a second partition for storage in Ubuntu and the Ubuntu community flavours. Windows can use the first partition (and if the second partition is a Microsoft file system, FAT32 or NTFS, an up to date Windows 10 system can use the second partition too).

Or you have persistence via the casper-rw file, or both.

Unmount the mounted partition on the target drive and unplug it

sudo umount /mnt/sd1

Check that no partition on the target drive is mounted with

df

(and you can unmount the iso file too

sudo umount /mnt/lp1

but it is mounted read-only, and not dangerous to leave mounted).

Persistence with Debian 10 live

partition for persistence

If you have a USB pendrive (or memory card or SSD via USB adapter), that is bigger than 8 GB, it can be better to use a partition for persistence. This way you can use the whole drive. It works with Debian 10 live, "Buster", and we expect that it will work with newer versions.

Again check carefully that you create the partition for persistence in the correct drive X.

sudo fdisk /dev/sdX
n
<press the Enter key>
<press the Enter key>
<press the Enter key>
w

and create an 'ext2' file system in the partition

sudo mkfs.ext2 -L persistence /dev/sdX2

Edit grub.cfg

The first partition must be mounted.

sudo mount /dev/sdX1 /mnt/sd1  # replace X with the actual drive letter like you did before

Edit the file /mnt/sd1/boot/grub/grub.cfg to add the boot option 'persistence' to the line starting with linux

linux ... quiet splash persistence ---

Create persistence.conf

Create a mountpoint

sudo mkdir /mnt/sd2

Mount the new partition

sudo mount /dev/sdX2 /mnt/sd2

and write a configuration file into it

sudo bash -c 'echo / union > /mnt/sd2/persistence.conf'

Flush the buffers, inform the kernel and unmount the partitions

sync
sudo partprobe
sudo umount /mnt/sd1 /mnt/sd2 /mnt/lp1

Check that your new boot drive works

Check that your new boot drive works as expected, and if not, try again, maybe you missed a step ...


Return to the main iso2usb page

Installation/iso2usb/diy (last edited 2023-04-29 00:27:27 by nio-wiklund)