How to maximize the life of a pendrive which has a full installation of Ubuntu MATE 18.04 on it

To increase the lifespan of your USB stick, minimising the number of read/writes in various ways:

Disable Swap

Swapping is the process of using part of the USB stick as volatile memory. This will increase the amount of RAM available, but it will result in a high number of read/writes. It is unlikely to increase performance significantly.

Disable swap with the swapoff command:

sudo swapoff --all

Ref.: How to permanently disable swap file?

Disabling Journaling on the Filesystem

Using a journaling filesystem such as ext3 or ext4 WITHOUT a journal is an option to decrease read/writes. The obvious drawback of using a filesystem with journaling disabled is data loss as a result of an ungraceful dismount (i.e. post power failure, kernel lockup, etc.).

You can disable journaling on ext4 on an unmounted drive like this:

umount /dev/sdaX
tune4fs -O ^has_journal /dev/sdaX
e4fsck –f /dev/sdaX
sudo reboot

Check if journaling is disabled for the filesystem and the partition is mounted:

dmesg | grep EXT4

Ref.: https://foxutech.com/how-to-disable-enable-journaling/

The noatime Mount Flag

Assign the noatime mount flag to partitions residing on the USB stick by adding it to the options section of the partition in /etc/fstab.

Ref.: https://www.howtoforge.com/reducing-disk-io-by-mounting-partitions-with-noatime

Directories in RAM

Highly used directories such as /var/tmp/ and possibly /var/log can be relocated to RAM in /etc/fstab like this:

tmpfs /var/tmp tmpfs nodev,nosuid,size=50M 0 0

This will allow /var/tmp to use 50MB of RAM as disk space. The only issue with doing this is that any drives mounted in RAM will not persist past a reboot. Thus if you mount /var/log and your system encounters an error that causes it to reboot, you will not be able to find out why.

Directories in external Hard Disk

You can also mount some directories on a persistent USB hard disk.


SSDs are designed for OS, Pen Drives are not

Although you can use pen drives to store and execute an Operating System (OS) they were not designed for that purpose like an SSD (Solid State Device) is. As such you will not find the manufacturer utilities such as TRIM nor Linux support such as the nvme command (Is it still bad to use swap on a modern SSD?).

Below is what wikipedia has to say about Pen Drive lifespan. Ensure you avoid the SLC type which might only last a few days.

Longevity

The memory in flash drives is commonly engineered with multi-level cell (MLC) based memory that is good for around 3,000-5,000 program-erase cycles,[51] but some flash drives have single-level cell (SLC) based memory that is good for around 100,000 writes. There is virtually no limit to the number of reads from such flash memory, so a well-worn USB drive may be write-protected to help ensure the life of individual cells.

Estimation of flash memory endurance is a challenging subject that depends on the SLC/MLC/TLC memory type, size of the flash memory chips, and actual usage pattern. As a result, a USB flash drive can last from a few days to several hundred years.[52]

Regardless of the endurance of the memory itself, the USB connector hardware is specified to withstand only around 1,500 insert-removal cycles.[53]

Booting operating systems

Most current PC firmware permits booting from a USB drive, allowing the launch of an operating system from a bootable flash drive. Such a configuration is known as a Live USB.[64]

Original flash memory designs had very limited estimated lifetimes. The failure mechanism for flash memory cells is analogous to a metal fatigue mode; the device fails by refusing to write new data to specific cells that have been subject to many read-write cycles over the device's lifetime. Premature failure of a "live USB" could be circumvented by using a flash drive with a write-lock switch as a WORM device, identical to a live CD. Originally, this potential failure mode limited the use of "live USB" system to special-purpose applications or temporary tasks, such as:

  • Loading a minimal, hardened kernel for embedded applications (e.g., network router, firewall).
  • Bootstrapping an operating system install or disk cloning operation, often across a network.
  • Maintenance tasks, such as virus scanning or low-level data repair, without the primary host operating system loaded.

As of 2011, newer flash memory designs have much higher estimated lifetimes. Several manufacturers are now offering warranties of 5 years or more. Such warranties should make the device more attractive for more applications. By reducing the probability of the device's premature failure, flash memory devices can now be considered for use where a magnetic disk would normally have been required. Flash drives have also experienced an exponential growth in their storage capacity over time (following the Moore's Law growth curve). As of 2013, single-packaged devices with capacities of 1 TB are readily available,[35] and devices with 16 GB capacity are very economical. Storage capacities in this range have traditionally been considered to offer adequate space, because they allow enough space for both the operating system software and some free space for the user's data.


If you only average 20 hours a week using a bootable pendrive it should last just about forever.

Lets do the math:

A pendrive is good for between 10000 and 1000000 writes, (and infinite reads).

One write = 64GB / 0.030 GB/s = 2133 sec = 0.6 hours.

Minimum lifetime = 10000 writes x 0.6 hours / write = 16667 hours or

16667 hours / 20 hours per week = 833 weeks, (or 16 years).

Kind of seems like a waste of time to put a lot of effort into improving this.

EDIT

Since I last investigated flash drive life it seems the estimate for consumer flash, (MLC), life expectancy has dropped to as low as 1000 - 10000 writes.

This makes the minimum life expectancy = 16 years / 10 = 1.6 years.

Perhaps it is worthwhile reducing writes to consumer, (cheap), MLC type flash drives.