8

I'd like to have Ubuntu installed on a USB stick, that I could plug in (almost) any computer and boot from it, and that I could use (almost) normally, as if it was installed on that computer. I'd also like to have a data partition on it that could be used by (almost) any computer, mostly to store some portable apps, just in case.


My main concern is to increase the lifetime of my drive, but without making it too unstable.

To do that, I have to choose the right options in /etc/fstab for my partitions. Currently, I'm thinking about these:

  • /: ext4, defaults,lazytime,commit=60,errors=remount-ro
  • /media/data: FAT32, defaults,lazytime,check=strict

So lazytime should be better than the often proposed noatime or the default relatime, since, as I understand it, it's applied to creation, access and modification times, it's POSIX compliant (contrary to relatime), and it reduces the amount of write cycles by storing times in RAM and writing them from time to time.

Combined with commit=60, it should reduce writes enough to compensate the journal of ext4, that I want to keep to have a stable system.

Do you think those options are good enough? Do you see other options I could use to reduce writes but keep a stable system?


My current setup:

  • USB stick: SanDisk Ultra Fit (32 Go)
  • OS: Xubuntu 16.04 i386
  • installation: full install (from a Live USB built with Rufus)
  • drivers: none proprietary
  • file systems:
    • partition table: GPT
      • 2: ESP, /boot/efi, 128 Mio, FAT32, [boot,esp]
      • 3: ABP, 128 Mio, HFS+
      • 4: BBP, 2 Mio, [bios_grub]
      • 5: swap, 512 Mio
      • 6: root, /, 24 Gio, ext4, defaults,errors=remount-ro,lazytime,commit=60
      • 1: data, /media/data, ~3.6 Gio, FAT32, defaults,lazytime,check=strict
    • RAM:
      • /tmp, tmpfs, defaults,nosuid,nodev,noexec,mode=1777
  • swap:
    • vm.swappiness=5
    • swap partition: 512 Mio, for emergency
    • zRAM
    • swap files:
      • /var/swap/hib.swp: same size as RAM, for hibernation, generated by a script at startup
      • /var/swap/opt.swp: if needed, generated by a script
  • overprovisioning: ~5.6%
    • built-in: ~1.2 Gio (apparently)
    • added: 512 Mio
  • scheduler: deadline
CidTori
  • 241
  • lazytime is independent and can be combined with noatime / relatime see here http://unix.stackexchange.com/a/276863/209113 – dgonzalez Jan 11 '17 at 18:28
  • Yes but I'd like to use the original (and POSIX) atime if possible, if lazytime reduces writes enough. – CidTori Jan 14 '17 at 10:48
  • OK, that's a game changer, i usually don't need atime at all. I use with no problems noatime with lazytime, ZRAM / ZSWAP, and higher commit values such 90-180s (even 600s). All of course depending on your system requeriments. – dgonzalez Jan 14 '17 at 19:23
  • Do you mean you use ZRAM and ZSWAP at the same time? I hope so because I was thinking about using ZRAM and didn't know about ZWAP, and now I'd hate to have to choose… – CidTori Jan 14 '17 at 20:03
  • No only one is recomended, check this for more info http://askubuntu.com/a/472227/298047 (but yes you'll have to choose...). For your use case I would go with ZRAM to avoid almost any hdd(usb)-swapping (it's used on default Lubuntu installer). Also check @sudodus answer, who has wide knowledge about this kind of things. – dgonzalez Jan 14 '17 at 20:13
  • Well ok… Yes ZRAM makes sense since I only use an emergency swap partition. And yes it's one of his posts that made me discover ZRAM ^^ – CidTori Jan 14 '17 at 20:52
  • And what do you think about swapspace ? – CidTori Jan 15 '17 at 09:21
  • Mostly OK, maybe I would set somehow higher swappiness value, maybe arround 20 (but with ZRAM it is uncommon your system reach to swapping). Also I don't like hibernation to much. – dgonzalez Jan 15 '17 at 19:39
  • No I mean the tool called swapspace, its supposed do dynamically generate swap files. But I'm also interested in your opinion about my swap setup ^^ You mean you would make it swap more often? – CidTori Jan 15 '17 at 19:47
  • @CidTori can you give an update on all the options you used, did it all work well? – David d C e Freitas Mar 08 '23 at 18:44
  • I’d like to, but I had to stop working on that project a long time ago I didn’t encounter new problems anyway, and I’m interested in any feedback if someone wants to try it – CidTori Mar 09 '23 at 11:05
  • If I remember well, I did try configuring everything as in my questions, except the swap part I think, without problem, but I can’t say if the writes reduction was really effective – CidTori Mar 09 '23 at 11:07

1 Answers1

5

I have made a lot of installed systems into USB flash drives, and I think such systems can work quite well. You have found some mount options, that I have not found (and not used). I am looking forward to future reports from you :-)


See this link about my systems, and the tweaks that I suggest,

help.ubuntu.com/community/Installation/UEFI-and-BIOS#Final_system_tweaks

I think it is important to get a fast USB 3 flash drive (and I think there are better drives for this purpose than the Ultra Fit),

help.ubuntu.com/community/Installation/FromUSBStick#Notes_about_speed

I think that the lifetime of good USB pendrives is rather good now, but still, it is important to backup all important files at regular intervals.


An alternative is a persistent live drive with a casper-rw partiiton, and if you wish you can add a home-rw partition,

help.ubuntu.com/community/mkusb/persistent

A persistent live drive is more portable, but cannot be updated and upgraded like an installed system (the kernel and drivers cannot be upgraded). But an installed system is often portable enough.

sudodus
  • 46,324
  • 5
  • 88
  • 152
  • Yes I saw those pages when searching about this =) I know that Ultra Fit does not fit well for this, but it's really cheap so it's perfect to test things out ^^ I saw a lot of things about persistent Live USB, but since I want to be able to update and upgrade, I can't use it. Thanks for the feedback ! =) – CidTori Jan 11 '17 at 17:00
  • When following your first link, I found this post. After the installation, you tweak /syslinux/txt.cfg and /boot/grub/grub.cfg. Why is that needed? And should I worry about UEFI and BIOS? – CidTori Jan 14 '17 at 11:05
  • That post is describing a special system, where /syslinux/txt.cfg is tweaked to add a menu entry for the installed system. You need not worry about UEFI and BIOS, but if you want to use the pendrive to boot an installed system in computers running in UEFI mode and computers running in BIOS mode, and not only one of those boot modes, you need a special procedure after the basic installation. – sudodus Jan 14 '17 at 11:14
  • Well, I'm interested… I think it will be my next question ^^ – CidTori Jan 14 '17 at 21:20
  • See also https://askubuntu.com/questions/258753/how-to-make-ubuntu-use-more-ram-to-cache-a-specific-set-of-binaries – David d C e Freitas Mar 09 '23 at 07:23