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.
I don't know how far your budget extends, but if you can afford an external USB drive, you can install your system on one. It will leave the hard drive in your father's computer completely unaffected.
- The external USB hard drive will likely last many times longer than a pendrive
- The external USB, while slower than an internal hard drive, will run faster than a pendrive
- You won't have to forgo the benefits mentioned in the answer from @MatsK.
To install on an external USB drive
- Either create a Live DVD and insert it into the laptop's DVD drive; or create a Live USB (on your pendrive) and insert it into one of the laptop's USB slots.
- Reboot from your Live DVD or Live USB.
- As soon as the Live DVD or Live USB has successfully booted, insert your external USB drive into another of the laptop's USB slots.
- Install Ubuntu onto the external USB drive. When you select the installation options, do NOT choose the default target — this will change your father's laptop drive, which, you say, "will freak him out." Instead, choose "Something else", and select your USB external drive to install. Take extreme care to select the USB external drive (which will probably show up as
/dev/sdc
, but that depends on your setup). Also take great care NOT to install Grub onto the laptop, but instead onto your external hard drive.
Problems and questions
If you have trouble with point 2 or point 4, or you get to a stage in point 4 where are unsure if it's safe to proceed, start a thread on Ubuntu Forums where people can ask you questions about your setup and feed back to you what to do next.
Running your installation
Each time you want to run your installed Ubuntu, plug in the USB external drive and reboot. Before leaving the laptop, shut it down completely (not restart, hibernate or sleep) and remove your USB external drive.
Backups
Finally, you need to consider all-too-often-neglected backups. Whether you use a pendrive or a USB external drive, they can fail suddenly. If you have few files, you can use something like Dropbox or Google Drive.
Dual-boot hint
If you are brave, you can in fact install a dual boot on the laptop but you can hide the Grub menu so that your father is unaware of it. But you really need to know your stuff to do this safely.