5

I want to install Ubuntu 20.04, and I decided that instead of dual-booting Ubuntu with Windows from the same disk, it will be better to install it on a separate disk. As I don't have another hard disk, I want to utilize a 32GB pendrive that I have for this purpose.

Then there are several considerations:

  1. Read/write speed
  2. Slowdowns by read/write queues
  3. Wear and tear by frequent write operations

So the things I need from a filesystem:

  1. Works fast
  2. Does not slow down the OS
  3. Does not damage the USB stick by writing too frequently

So if I have to choose between ext4 and btrfs, which of them would be better for this purpose?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Tom
  • 51
  • 1
  • 1
  • 2
  • 2
    No file system is going to speed up your pendrive, just do a quick IO test on it to see if it's comparable to your main disk... or just put one of your OSs in a VM (VirtualBox). – user1133275 May 02 '20 at 02:17
  • Good idea. A VM is the practical solution. – Claus Andersen May 02 '20 at 07:03
  • Issue with btrfs https://unix.stackexchange.com/questions/680902/btrfs-automounted-and-mounted-via-gnome-disks-error-finding-object-for-block – Martian2020 Dec 10 '21 at 22:33

2 Answers2

2

I've seen benchmarks (eg: this one) that put btrfs considerably slower than ext4. The benchmark I linked attributes this to copy-on-write behaviour of btrfs.

However benchmarks test quite narrow parameters which may not be reflected by running an OS. For example btrfs supports transparent file compression. This may speed up the otherwise slower file system considerably at the expense of CPU.

A big proportion of OS IO is based on small file reads. This means that slow down due to reading data on disk is much less than you might expect when compared to spinning hard drives. That's because USB flash drives have very low "seek time", running Ubuntu from a flash drive is pretty smooth.


As for wearing out a flash drive, this is more of a problem. If you use it heavily then you will eventually wear out a USB drive where you might not ever wear out of a hard drive. F2FS is your better option (Yes I realise it wasn't in your question). This was designed to reduce flash wear and importantly designed to spread flash wear.

Quite often you don't need to worry though... It will depend on you and how much money you have. Think about whether or not you really care about spending another $10 in a year or two.

A lot of the better usb flash drives (well known brands with a reputation to maintain) will fail into read-only mode. Ext4 is designed to be very hard to corrupt so when the time comes you're unlikely to lose data if you formatted with ext4.


If you are still concerned about wear then you might want to do something a little funky with your setup: make the windows PC hard-drive host part of your file-system.

You can create a large single file on your main Windows hard drive and then use it as a loopback device, (that file can be used like a hard drive). This will let you put frequently changing areas of your file system (/var and /home) onto your Windows PC and keep them away from your USB drive.

However this approach will mean your pen-drive linux will no-longer boot on any machine, only yours.

Philip Couling
  • 17,591
  • 5
  • 42
  • 82
1

The difference is negligible in your situation. The (slow) speed of the pen drive is the limiting factor.

In your case I would run a "Live" setup. Originally made for use for CD boot this can be used for USB drives as well. This will boot into memory and only read from the pendrive. Data is then not persisted between restarts. To persist data you can simply mount the location you want to write to.

This will be the fastest setup for a pendrive. No need to worry about the filesystem.

Follow the regular official Ubuntu instructions here: Create a bootable USB stick on Windows. They hint about the Live CD stating:

Test out the Ubuntu desktop experience without touching your PC configuration

Or these generic instruction which handle any bootable CD image: How to Create Ubuntu Live USB in Windows

Live booting will give you the best experience. If you were to create an embedded system you would do something along those lines.

If you insist on using the pendrive as a regular harddrive it will then be slower. So slow that you will not feel any diffence due to the filesystem. While ext4 might be slightly faster the reason why I would choose that is however due to more mature tooling (see Difference Between Btrfs and Ext4)

As Ubuntu is a full operating system which expects that it can write all over the filesystem they have not optimized for your usecase. If you are serious about running a full system from a pendrive (and not just for play/testing) then you should look into UnionFS or aufs. This is an overlay filesystem which allows you to keep the OS filestructure but decide which parts are persisted to disk. You would then boot the OS into memory and then make sure that something like /etc is written to disk.

I do not know of any Ubuntu based distributions which uses this technique out of the box. But if you are willing to switch distro Knoppix does it well AFAIK.

UPDATE: Latest version of Knoppix 8.6.1 seems like the easy way to go.

Claus Andersen
  • 3,239
  • 1
  • 12
  • 24
  • 1
    Have you benchmarked these file systems to see if they really do perform similarly? Btrfs supports transparent compression and packing multiple files per block which may reduce the io bottleneck at the expense of cpu. Running Ubuntu directly off a usb drive runs pretty smoothly, no need for any overlayfs or unionfs. – Philip Couling Jan 18 '21 at 21:58
  • The common pen drive still have slow IO compared to a regular disk. But even if you think the IO is fast enough for you I would still not do it. USB flash drives can withstand between [10,000 to 100,000](https://en.wikipedia.org/wiki/Flash_memory#Write_endurance) write/erase cycles, depending on the memory technology used. Most if not all regular USB pen drives is using TLC (many) and MLC (higher end). That is a far more interesting [test](https://stackoverflow.com/questions/25285535/test-the-limit-of-read-write-cycles-of-a-usb-flash-drive). – Claus Andersen Jan 19 '21 at 07:56
  • I'm well aware of wearing out USB drives. However [pendrive linux](https://www.pendrivelinux.com/) (complete with persistence) is a pretty common practice. For the price of a cheap USB drive, It'll likely last longer than you expect, maybe a couple of years. And the better pen-drives such as sandisk will fail into read-only mode. USB drives are slower, yes, though their low seek time eats a lot of of the performance gap compared to spinning disks. Sure they're not going to compare to an SSD. – Philip Couling Jan 19 '21 at 09:34
  • You seem to feel strongly for this and infer something into my answer which is not written. Wearing out a drive "in a couple of years" is not reasonable to me. And make sure what write patterns the applications you use have. The original question worried about wear. Your answer is "do not worry/care". I outline how to avoid the problem. Both are correct. – Claus Andersen Jan 19 '21 at 13:22
  • No no. I disagree with your answer as written. I'd be happy to discuss further in a chat room. But frankly, I've posted my answer and see little point to re-iterate my points here. – Philip Couling Jan 19 '21 at 14:34