7

I've searched a lot over here and after reading all that all I understood is that I have to disable swap.

Installation

I first installed VirtualBox and booted from the MATE live CD (Minimal Installation). Then I installed it on my pendrive. It is USB 3.0 SanDisk Ultra 64 GB. This one.

Booting from USB

Everything went well and I have a functioning desktop.

Background

I don't have a personal desktop to use; I have to use a shared laptop that my father uses. Dual booting will freak him out. I have tried Puppy, KNOPPIX, Tails, and Slax. Nothing worked well for me. I decided to install the whole OS onto my pendrive.

Considering I use this for basic stuff like browsing, watching videos, copying files and not too heavy stuff. How will this affect the life of my USB drive?

I've read articles saying it will kill my pendrive, about write and read cycles and how USB have less of it. So, shall I continue using it like this? If yes, then how can I maximize the life of my pendrive?

Also, I will use it for about 20 hours a week.

System Information

  Ubuntu MATE 18.04
  Intel Core i5 5th gen. processor
  8GB RAM
  64GB USB 3.0 pendrive
  47GB available disk space

Update

I made this post 3 months ago, asking about using Ubuntu from a pendrive. My usage has increased since then, and I have tried many different OSes, currently using Kubuntu 18.04.

I've used this pendrive on 3 different machines, two laptops (Dell and a MacBook) and a desktop computer. I didn't face any issues except wifi worked properly on all the three systems. I've been using this pendrive for about 8 months and it's still working fine.

Avizini
  • 73

4 Answers4

20

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.

MatsK
  • 916
7

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.

4

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.

C.S.Cameron
  • 19,519
  • I have been searching for over three years for someone that can confirm that their thumb drive was bricked running Ubuntu: https://askubuntu.com/questions/588035/lifespan-a-flash-drive-running-ubuntu – C.S.Cameron Jul 22 '18 at 16:31
  • 3
    This calculation assumes that every memory cell including the most worn memory cells are written to 10000 times. Some logical memory locations will be written to many more times than the average in an installed system, so the system must have an efficient algorithm to spread the wear by remapping between the logical memory locations and the memory cells. I think this algorithm can be a weak link in the chain. -- But it is certainly true that USB pendrives last longer now, than some years ago, and that their lifetime is better than the reputation. – sudodus Jul 22 '18 at 16:57
  • And of course a booted pendrive is only written to a small percentage of the time. I finally bricked an eleven year old 4GB Kingston DataTraveler that I have always run Ubuntu on. Bricked it using Disk Destroyer , not running Ubuntu. – C.S.Cameron Jul 22 '18 at 17:09
  • I think it becomes a problem, when the mounted partitions (root, maybe home) are nearly full (so that there is no longer a lot of free space). – sudodus Jul 22 '18 at 17:13
  • In all my time visiting Ask Ubuntu and Ubuntu forums I've only met one person who claims to have bricked a flash drive running Ubuntu, The drive was a give away from a trade show and he was running Ubuntu server, full time. He admitted maybe pulling the drive when it was in service. – C.S.Cameron Jul 22 '18 at 17:22
  • 1
    Josh did a good article on Wear Leveling back in 2008: http://www.bress.net/blog/archives/114-How-Long-Does-a-Flash-Drive-Last.html – C.S.Cameron Jul 22 '18 at 17:36
  • In a similar way, it is claimed that persistent live drives must not be updated and full-upgraded as much as possible (including security upgrades, improved software but excluding kernel upgrades), because it will choke the overlay mechanism and the system will fail. I have been testing it in an SSD and a hard disk drive (with plenty of free space after the full upgrade), and a system started from 16.04.1 LTS is still working :-) – sudodus Jul 22 '18 at 17:38
  • There are some questions here at AskUbuntu about hardware failures, where memory cards are read-only or unreadable, and I could not help make them work. But we don't know the whole story: What about overheating, electric shock (static electricity), unplugging while writing, mechanical damage ...) – sudodus Jul 22 '18 at 17:44
  • 1
    @Peter Mortensen: Sandisk says all their drives use wear leveling, even Fits. http://forums.sandisk.com/t5/All-SanDisk-USB-Flash-Drives/Does-my-USB-Flash-Drive-have-wear-leveling/td-p/339714 . Read somewhere else Sandisk uses dynamic leveling. – C.S.Cameron Jul 22 '18 at 20:12
  • @WinEunuuchs2Unix, This is an interesting discussion. There is evidence that the memory cells of pendrives and memory cards have a much shorter expected life (number of write cycles to failure) than HDDs and SSDs. There is also evidence, that pendrives and memory cards last much longer than most people think. I am still recommending methods to decrease wear in systems booted and run from such drives, but I am considering a change (for example in favour of journaling). – sudodus Jul 23 '18 at 05:12
  • oh! If this is the case then I need not worry, 1 year of usage will be good for me. Thanks! – Avizini Jul 25 '18 at 06:28
2

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

  1. 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.
  2. Reboot from your Live DVD or Live USB.
  3. 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.
  4. 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.

Paddy Landau
  • 4,548
  • 2
    External hard drives are connected to the computer by a USB cable, so jostling the external hard drive can cause severe drive wear and data loss unless the external hard drive is an SSD. This makes an SSD an economically viable solution for this use case compared to a spinning disk drive. – karel Jul 25 '18 at 15:09
  • Good point, @karel. I keep my USB drives on a stable surface while using them. – Paddy Landau Jul 25 '18 at 15:17
  • https://askubuntu.com/a/1058414/852249 -> I think 1 year of life is good for me. I'll buy another drive if it dies. Yeah, HDD is a good idea. I guess that will be more expensive for me, I had one which failed misreably and I lost all my data. > hide the grub menu. I'll look into this – Avizini Jul 25 '18 at 16:06
  • and on pendrives, I trust them more. I have a hp 2.0 32gb drive which is serving me since ~2010 and still works good. It has been washed in washing machine for (i dont remember) x times. Still it works as it was before. – Avizini Jul 25 '18 at 16:10
  • @Avizini If you wash your drives, you'll definitely prefer pen drives, ha ha! All of my hard drives have lasted years (they are still going strong), so maybe you were unlucky? In the long term, I think that a hard drive will be cheaper (you don't need a large one — on eBay, I just found a 60Gb SSD drive for £26, and a 40Gb hard drive for £10). Something for you to consider! – Paddy Landau Jul 26 '18 at 12:27
  • @PaddyLandau Yeah I often forget my pendrives in my pockets and wash them. >so maybe you were unlucky. Right. I'll consider buying a good harddrive and try it. last time I just went with a cheap option and that failed. :) – Avizini Jul 27 '18 at 16:35
  • As an extra point, if you install Ubuntu onto your external drive (or indeed your pendrive), you won't be limited to using your father's computer. You'll be able to boot your system on any computer (unless it's been locked down), without changing the computer's internal drive. For best results, keep your system fully updated. Because of the speed difference, you'll be glad that you got an external USB drive instead of using your pendrive. And… please don't leave the hard drive in your pocket :) – Paddy Landau Jul 28 '18 at 12:35
  • I have turned on update notifications. Also, will not leave them in my pockets..:) – Avizini Aug 02 '18 at 13:22
  • @PaddyLandau Here's an update: Everything was working well but now I cannot find my drive, it has been a day since I saw it. I guess its lying in some corner of my house or maybe the washing machine..:/. I've decided to buy an external drive! – Avizini Aug 12 '18 at 05:49
  • @Avizini It's a pity that we can't use the internal drive on our phones :) An attempt was made to create an Ubuntu phone that would automatically turn into a desktop when you docked it, but it came to aught. – Paddy Landau Aug 12 '18 at 09:28