0

This question is different from the one marked as duplicate as I know how to install Ubuntu on an USB Key but I want to have an additional partition on this USB Key


I have an USB 3.0 Stick with 64GB and I want to use it to save some backup data in an encrypted Partition but also have one partition with a bootable ubuntu.

Making a bootable ubuntu stick is easy:

# sudo dd if=ubuntu-16.04.2-desktop-amd64.iso of=/dev/sdX bs=1k count=2048 conv=fdatasync

(changed sdd to sdX to prevent users from copying it and harm their system)

But then I get a strange partition table:

# fdisk -l /dev/sdd
Medium /dev/sdd: 58,4 GiB, 62746787840 Bytes, 122552320 Sektoren
Einheiten: sectors von 1 * 512 = 512 Bytes
Sektorengröße (logisch/physisch): 512 Bytes / 512 Bytes
I/O Größe (minimal/optimal): 512 Bytes / 512 Bytes
Typ der Medienbezeichnung: dos
Medienkennung: 0x15e2543d

Gerät      Boot Start    Ende Sektoren Größe Id Typ
/dev/sdd1  *        0 3035519  3035520  1,5G  0 Leer
/dev/sdd2       14432   19295     4864  2,4M ef EFI (FAT-12/16/32)

This seems to be correct as my stick is booting fine. But I really don't understand it.

When I partion the usb device before and have one FAT32 and one LUKS parttion then I still can dd the iso to the first partition /dev/sdd1 but it is not bootable anymore.

I set the bootable flag on the first partition of course an my laptop tries to boot it but only shows a blinking underscore.

There are so many misleading informations in the web about this scenario. I am lost. I am familiar with partitioning, and MBR and GRUB but only in using it. It seems I never really understood what is going on and many things have changed since I last did it (EFI, loop devices..)

It seems to be very difficult to use an USB stick as a bootable ubuntu AND as a backup partition. But I still think this should be a matter of

  • Formatting and partitioning USB stick
  • Copying ISO to partition
  • Make some magic like MBR, bootable flag, Grub2

Can somebody help with a small step-by-step command line example to get things running on a modern ubuntu 16.04?

The second partition doesn't need to be mounted on Windows by the way.

Janning
  • 1,885
  • Your question is showing up in the Close Queue as too broad. I think this is due to the way you've phrased it. Your example of blasting a drive full of zeros in no way magically results in the partition table you have provided (in fact it results in no partition table). I recommend that you [edit] this post to make it clear. Or at the very least review this old documentation which covers the basics of what you are trying to accomplish. – Elder Geek Mar 14 '17 at 13:48
  • The old doc you mentioned seems to be very well. I will check it out. – Janning Mar 14 '17 at 17:08
  • Excellent! Best of luck! If you still have an issue after that, feel free to come back and [edit] your post with further detail as outlined here – Elder Geek Mar 14 '17 at 17:38

2 Answers2

1

I'll answer you question in an effort to clear your confusion.

You can make a bootable USB. Just install Ubuntu the USB stick. Once you have this bootable disk, you can repartition, resize, and make the same changes to the USB drive the same way you do on your regular system's hard drive.

This bootable drive that you have created can be cloned to an ISO, just as your regular internal hard drive can be cloned to an ISO. You use the dd command in your question to make copies of this ISO into other drives. After you make copies you can also edit and modify the partitions as you indicated for your criterion.

The thing you can't do is make an ISO of a CDROM installer, or use a LiveUSB ISO installer (which is built using the same basic algorithm of a DVD, but on an USB stick instead) as your cloned drive. As you see from the details your experience included in your question, the drive would be corrupted (as far as being able to boot) if you make partition changes.

While this isn't what you are looking for, a deliberate and specific design has gone into making an installer version (called a persistent usb) to overcome the limited design and intent of the OS installer.

An ubuntu installer with the ability to modify the partitions of the media doesn't exist at this time. If it did exist, someone would post the source as an answer, or point you to the solution.

You could, alternatively, while it may take a lot of work, make your own installer and add it to your own Ubuntu pendrive. It's discussed here: Install from existing Linux

This is an alternate method of making your own LiveUSB for your Pendrive:
Installation/FromLinux

I haven't attempted to create this environment. So I can't comment on whether the task would be easy. I'm just trying to provide you with what would be involved if you are trying to have a Pendrive that can be used as an installer and also have partitions that are editable.

L. D. James
  • 25,036
1

You can create a persistent live drive with mkusb. Directly after that, while still booted from the other system, you can edit the partition table and shrink some partition and create your own partitions. But I think the partition structure of the persistent live drive by mkusb is good enough for your purpose. There is an ext partition for persistence and an NTFS partition for communication with Windows computers. You can store files in both of those partitions.

There is a total of 5 partitions. It can look like the following listed output in a USB 3 pendrive with 128 GB. During the installation you can decide the percentage of the available drive space for persistence (the casper-rw partition with the ext2 file system, and the rest of the drive space will be used for the usbdata partition with the NTFS file system). In this case I used the default, 50%.

parted -s "/dev/sdd" print
Model: SanDisk ExtremePro (scsi)
Disk /dev/sdd: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 2      1049kB  2097kB  1049kB               primary  bios_grub
 3      2097kB  130MB   128MB   fat32        primary  boot, esp
 4      130MB   1663MB  1533MB               primary
 5      1663MB  64,8GB  63,2GB  ext2         primary
 1      64,8GB  128GB   63,2GB  ntfs         primary  msftdata

lsblk -o MODEL,NAME,FSTYPE,LABEL,MOUNTPOINT,SIZE "/dev/sdd"
MODEL            NAME   FSTYPE  LABEL                    MOUNTPOINT   SIZE
ExtremePro       sdd                                                119,2G
                 |-sdd1 ntfs    usbdata                              58,9G
                 |-sdd2                                                 1M
                 |-sdd3 vfat    usbboot                               122M
                 |-sdd4 iso9660 Ubuntu 16.04.1 LTS amd64              1,4G
                 `-sdd5 ext4    casper-rw                            58,9G

See details at the following links,

help.ubuntu.com/community/mkusb

help.ubuntu.com/community/mkusb/persistent

mkUSB-quick-start-manual-12.pdf

sudodus
  • 46,324
  • 5
  • 88
  • 152