7

I have an Ubuntu live USB and I don't have any other PC, laptop, or USB sticks. Can I make my live USB persistent? If not, is there any other way to save files in it so that they will stay there even after I restart my PC?

Note: I have a PC with an Intel 6th Gen Core i3 processor and 4GB RAM, and I'm currently running Ubuntu from a 16GB USB stick. I can't borrow others' computers or USB drives, but I do have a phone if that helps.

MDeBusk
  • 1,175
  • 2
  • 8
  • 21
MrDuck
  • 73
  • Instead of telling us what you have not, please tell us what you have :-) What computer (brand name and model), what operating system in the computer, what iso file with Ubuntu, and where (in what computer)? Can you borrow a computer or USB pendrive or memory card? – sudodus Jul 30 '22 at 11:24
  • i have a pc, it has intel 6th gen i3 processor, 4 gb ram and i'm running ubuntu from a 16gb usb stick (live session) – MrDuck Jul 30 '22 at 11:36
  • 3
    Bad Idea: Persistence requires re-partitioning the USB stick. While this can be done by a Live system, changes to your only boot media means you will get only a single chance to get it right. No practice, no undo, no margin for error. Revisit your other limitations so that an unexpected problem doesn't leave you completely stranded. – user535733 Jul 30 '22 at 11:53
  • 1
    How did you create the live Ubuntu system in your USB drive? Would you be able to do something similar, just a bit different in order to get a [fresh] Ubuntu system that is persistent live? When you have problems with the hard disk drive, I suggest that you cooperate with someone, a friend, colleague or relative, borrow a computer and/or a USB drive and make what you want. (But it is not a good idea to tamper with your current Ubuntu system, if you have no margin for failure.) – sudodus Jul 30 '22 at 12:24
  • I have never used a phone for this purpose, but I know that other people have done it successfully. If you have a removable micro-SD card in the phone, it might work to attach it into the computer (maybe with an adapter from micro-SD to a standard SD slot in the computer). You can probably find instructions via the internet how use the whole phone for this purpose, but I don't know how risky it is. – sudodus Jul 30 '22 at 12:33
  • 3
    @sudodus i created the live usb from my phone (which doesn't have any SD card in it) ... i made it from an app called EtchDroid.. but it doesn't have any options for persistence, and i searched for any other apps or anything that would let me make persistent usb but couldn't find any... so, if anything goes wrong while trying to make the USB persistence in my pc, i can make another Live USB from my phone, that's not an issue i guess. – MrDuck Jul 30 '22 at 14:46
  • 1
    @MrDuck, In that case you can use the methods suggested by C.S.Cameron. – sudodus Jul 30 '22 at 16:12

3 Answers3

14

Usually I recommend using mkusb in order to create a persistent live USB drive. But in this case I think it is too risky, because there is no backup, the only working operating system is in the target drive.

Instead I suggest to make the default /var/log and /var/crash mounted writable partition into a 'free' usbdata partition, that can be mounted and unmounted by the user.

  • When booting, at the grub menu, press 'e' to make a temporary edit: add nopersistent to the line starting with linux

    linux ... quiet splash nopersistent ---
    
  • continue booting with F10 or ctrl x

  • now you can unmount the partition with ext4 file system

    sudo umount /dev/sdx3
    

    where x is the drive letter (can be a, b, c ...)

  • change the label

    sudo tune2fs -L usbdata /dev/sdx3
    
  • shutdown, wait for 10 seconds and boot again.

The system will be live (not persistent live), but the ext4 partition can be used for storage. Until you have another drive available this is a rather safe method to create storage space on the drive. In order to make it convenient, you can create one or more directories at its top level and modify the ownership.

The partition will probably automount (it did when i tested with Lubuntu 20.04.4 LTS, which is lighter than standard Ubuntu).

cd /media/lubuntu/usbdata
sudo mkdir Docs
sudo chown 999 Docs

999 is the numeric ID of the live user (for standard Ubuntu as well as Lubuntu and the other community flavours). Now you can go there and test writing files.

cd Docs
echo 'Hello World' > hello
cat hello
ls -l hello
sudodus
  • 46,324
  • 5
  • 88
  • 152
  • 2
    Wowwwww... it works, thank you so much, i was in so much pain, and it's gonna take me some time to get a new hdd. it really helped me, thanks – MrDuck Jul 30 '22 at 16:32
  • @MrDuck, you are welcome. I'm glad that I could help you :-) – sudodus Jul 30 '22 at 17:51
6

Live USB to Persistent USB

A persistent Linux USB is basically just a Live USB with a persistent overlay file or partition, (ie casper-rw, writable or home -rw).

It is possible to make a Persistent USB from scratch:

Simple Hand Made Persistent USB that Boots either BIOS or UEFI

It is also possible to make a Full install of Ubuntu from a Live USB to itself, see: https://askubuntu.com/a/855805/43926

Similar see: How to make a persistent Drive using Startup Disk Creator

And Can Ubuntu be installed to the pendrive it was booted from?.

C.S.Cameron
  • 19,519
  • 3
    @user68186 Yes, it works using toram, see links above.. – C.S.Cameron Jul 30 '22 at 15:42
  • 2
    They only have 4GB of RAM; using toram would use up a significant fraction of that for the compressed filesystem image. But as a temporary way to get a persistent USB setup created, yeah this could work. The OP says they can access their USB stick from their phone, and that's how they made it in the first place. So they have a way to try again if something goes wrong. – Peter Cordes Jul 31 '22 at 01:44
  • 1
    @PeterCordes i did tried using toram but for some reason it was quite laggy, maybe because my ram is 4GB and the files for running Ubuntu system don't fit, i don't know. – MrDuck Jul 31 '22 at 02:56
  • 1
    @MrDuck: Yeah, with only a small amount of physical RAM left, running a modern heavyweight desktop like KDE or GNOME would probably need more than you have. Especially running a web browser. So the kernel would keep evicting clean pages of executables and having to page-fault them back in (from the compressed ramdisk), and compressing dirty pages to "compressed swap" (https://www.kernel.org/doc/html/v5.14/vm/zswap.html / https://wiki.archlinux.org/title/zswap) and have to keep paging them back in when they're needed again very soon afterwards. Swap thrashing maybe, but without a slow disk. – Peter Cordes Jul 31 '22 at 03:38
  • 2
    @MrDuck sudodus has did that on a PC with 4GB RAM, but that's Ubuntu 16.04 so probably lighter. You should try Xubuntu or Lubuntu instead which is far ligher than Ubuntu or Kubuntu – phuclv Jul 31 '22 at 03:45
3

No, you can't. And the amount of work and the high risk of data loss makes such project absurd.

You can use MKUSB to re-do the live USB but this time selecting the 'persistent live' option, arguably the easiest and fool-proof method.

ChanganAuto
  • 1,670
  • 8
  • 14
  • 21