Ubuntu To Usb

Ubuntu To Usb

Reading time1 min
#Ubuntu#Linux#USB#Persistence#PortableOS#PersistentUbuntuUSB

How to Create a Persistent Ubuntu USB Drive for True Portability

Persistent Ubuntu USBs occupy a peculiar niche—an environment fully in your pocket, yet not quite a full install on disk. Deploying one transforms any compatible machine into your workstation, preserving installed packages, dotfiles, and local documents between boots, with no trace left on the host.


Why Bother with Persistence?

Standard live USBs are ephemeral: adjustments to system settings, installed deb packages, or saved files are lost on reboot. For software engineers, auditors, traveling sysadmins, or penetration testers, that's an operational dead end. A persistent USB instead reserves a writable overlay, so your environment evolves as you work.

  • Maintain custom toolchains (Python, Node, build essentials)
  • Persist network configurations or VPN credentials
  • Save logs, notes, and generated files

Potential drawbacks: write speeds are, as always, bounded by USB throughput. Entry-level 8 GB sticks work, but you'll soon wish for a high-end 32 GB+ USB 3.1 drive.


Prerequisites

  • USB Drive: 16 GB minimum recommended; USB 3.0+ preferred.
  • Ubuntu ISO: Official release (e.g., ubuntu-22.04.4-desktop-amd64.iso).
  • A host machine (Windows, Linux, or macOS).

Tooling options (best-in-class, as of 2024-06):

PlatformToolPersistence Support
WindowsRufus (≥3.15)Full
LinuxmkusbFull
macOSbalenaEtcherLimited/None

Note: Mac users—Etcher doesn't currently support persistent overlays. For robust results use a Linux VM.


Persistent USB Creation: Rufus on Windows

  1. Download Rufus
    Latest builds: https://rufus.ie/
    Confirm version ≥3.15 for persistence support.

  2. Obtain Ubuntu ISO
    Use SHA256 checksums to verify integrity after download:

    sha256sum ubuntu-22.04.4-desktop-amd64.iso
    

    Compare with the official checksum.

  3. Insert USB Drive
    16 GB or larger, no critical data—this process wipes the device.

  4. Run Rufus
    Rufus autodetects USBs, but verify the correct target drive in UI. Mistakes here are terminal.

  5. Configure for Persistence

    • Boot selectionDisk or ISO image (Please select)
    • Select Ubuntu ISO.
    • Persistent partition size slider: set at least 4 GB, but use more if your USB allows.

    Gotcha: FAT32 splits files >4GB; NTFS is possible with caveats, but stick with FAT32 unless needed.

  6. Partition Scheme

    • MBR for broad compatibility (BIOS+UEFI), GPT for strictly UEFI targets.
    • Caution: some Secure Boot systems reject these images, especially with persistence enabled.
  7. Start

    • Click START.
    • Observe the log for errors (common: "WRITE ERROR [0x00000015] - The device is not ready").
    • All existing data is lost.
  8. Booting

    • Access host firmware boot menu (F12/F10/ESC, varies).
    • Select USB device.
    • Ubuntu launches with persistence.

Errors launching? Check if the device is set to legacy boot, not UEFI Secure Boot. Disable Secure Boot to avoid kernel signature errors.


Persistent USB Creation: mkusb on Ubuntu Linux

mkusb offers granular control, including partition layouts and UEFI/BIOS handling. Installation:

sudo add-apt-repository ppa:mkusb/ppa
sudo apt update
sudo apt install mkusb mkusb-nox usb-pack-efi

Run as root:

sudo mkusb

Follow the prompts ("Install (make a boot device)"), then:

  • Choose 'persistent live'
  • Source your ISO; target your USB stick (double-check device ID—lsblk helps)
  • Set overlay (casper-rw) size—50% of free space leaves adequate room for both OS and persistent data
  • Accept all warnings (“This will wipe /dev/sdX”)
  • Wait for completion; mkusb displays progress and detailed logs.

Example partition layout:

/dev/sdX
├── /dev/sdX1  (EFI/boot, ~512 MB, FAT32)
/dev/sdX2  (Ubuntu root, ext4)
/dev/sdX3  (casper-rw, ext4, persistence)
/dev/sdX4  (optional NTFS/FAT32 data partition)

Test the stick post-build on another system. If you see an error:
/dev/loop6: Can't open blockdev
usually means the device didn’t support the overlay format—try a different USB brand/model.


Day-to-Day With a Persistent Ubuntu USB

Once booted, persistent USB workflows are similar to a real install, with notable exceptions:

  • Installed Packages: All dpkg/apt-installed tools (e.g., apt install git vim gnome-tweaks) are retained.
  • User Data: Documents, shell history, custom scripts—everything in $HOME is persistent.
  • System Customization: GNOME layout tweaks, bash aliases, etc., survive reboots.

Practical example:

sudo apt-get update
sudo apt-get install htop
touch ~/my-notes.txt
echo "USB persistence works." >> ~/my-notes.txt

Reboot. All changes remain.

Side notes:

  • Extensive write cycles wear cheap USB flash; industrial or SLC sticks last longer.
  • Performance: even with USB 3.0, not comparable to SSD.
  • Certain kernel or driver upgrades may not persist seamlessly; always test after major changes.

Tips and Non-Obvious Pitfalls

  • Strictly eject (don't just pull) the USB before hardware removal; filesystem corruption risk is high.
  • For data above 4 GB, add a dedicated exFAT/NTFS partition for file transfer between OSes.
  • Persistence overlays aren't encrypted by default. Consider LUKS or VeraCrypt for sensitive data.
  • Upgrading the underlying Ubuntu version is non-trivial; often requires a full rebuild of the USB.
  • Known issue: laptops with certain NVMe or RAID storage setups can confuse GRUB's boot menu—sometimes requiring manual intervention at launch.

Conclusion

A well-built persistent Ubuntu USB isn't a full OS install—but for troubleshooting, incident response, or just having a familiar Linux dev toolkit on hand, it's irreplaceable. No install, no admin rights. For best results, standardize on a reputable USB stick (Samsung BAR Plus or SanDisk Extreme, for example) and keep a second unit for backup.

Got stuck? Boot fails or the overlay misbehaves? Often, simply switching to another USB brand resolves odd hardware issues.


Questions or persistent problems—post logs or error messages below. No environment is truly portable, but a good persistent USB comes extremely close.