Ubuntu: Manually Creating Casper -rw File



Question:

I was wondering if there was a way to create the casper -rw file for persistence manually, i.e. via terminal. I've been using Ubuntu 14.04 Live USB with persistence and it ran fine for the last two weeks. Last night, I was installing a bunch of apps (or at least, I thought I was) and I got a few errors after which the terminal froze. I had no idea what went wrong, so I just forced shut down and fell asleep.

This morning, I tried to boot my netbook and the screen went blank after the grub menu and just stayed like that. I figured I must've accidentally updated the kernel and it messed up the system. So I plugged in another USB with another OS in my netbook, booted, browsed to the drive where the casper -rw file was located and deleted it.

This solved one problem. I could boot into Ubuntu alright, except I just didn't have persistence. So is there a way to manually create the persistence file WHILE I'm running Ubuntu? I don't want to do another fresh install as I only have two drives (one for backup and one for Ubuntu) and my backup drive's running Porteus and it always fails to create bootable USBs due to some module issue.

I would also like to know if there's a way to stop Ubuntu from updating kernel so as not to get in the same situation again in the future. Thanks!


Solution:1

1) To create casper-rw via terminal, you can can enter the following 2 commands one after the other, replacing 512 with any other number of MBs you want for your casper-rw file's size:

dd if=/dev/zero of=casper-rw bs=1M count=512    mkfs.ext3 -F casper-rw  

2) To prevent kernel upgrades, you can install Synaptic Package Manager, select the installed linux image package(s) (linux-image-xxxxxxxxxx), and then choose Package > Lock Version from the menu.


Solution:2

Boot with the boot option toram

Boot (live-only) with the boot option toram to be able do to 'anything' with the boot drive, edit it or unplug it without affecting the running operating system.

toram makes the content originally from the iso file copied to RAM (and it will be mounted on /cdrom).

Now you can unmount all partitions on the boot drive. It means that you will be allowed to edit the partition table, or even install an operating system.

Ways to create persistence

You can use the following methods to create persistence

  • mount the FAT32 partition with read-write permissions and create a casper-rw file as described in the other answers to your question, a file with a file system inside.

  • if you are booting via grub, use gparted to shrink the FAT32 partition and after that use the unallocated space to create a new partition with the ext2 file system or (ext4 file system and later remove journaling) and add the label casper-rw. This partition can be bigger than 4 GB, which is a big advantage. (Ubuntu cannot use a casper-rw partition for persistence in the same drive (the boot drive) when booting via syslinux, but it can if the casper-rw partition is in another drive.)

  • install mkusb temporarily and use it to create a new persistent live drive, but in this case I would really recommend that you get a new cheap USB pendrive, that you can use for the live system, and install the persistent live system into the other drive.

  • download and clone from a compressed image file to a persistent live system or an installed system (like a system is installed in small devices like mobile phones and Raspberry Pi). This can be done with mkusb in Ubuntu and with Win32DiskImager in Windows.

Links

askubuntu.com/questions/928755/can-you-install-the-os-onto-the-usb-you-are-using-to-boot-the-iso-from/928777#928777

Yes, it works with the following recipe :-)

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

Try Ubuntu (Kubuntu, Lubuntu, Xubuntu, ...) before installing it

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

help.ubuntu.com/community/mkusb/persistent

help.ubuntu.com/community/mkusb/sp

wiki.ubuntu.com/Win32DiskImager


Solution:3

If the casper-rw file is on a FAT32 formatted device (which many bootable USB drives use), you might consider:

dd if=/dev/zero of=/cdrom/casper-rw bs=1MiB count=4095  
  • dd: Command to write raw data
  • if=/dev/zero: Read from device which generates noll (0 value) bytes.
  • of=/cdrom/casper-rw: The output file where the casper-rw file lives. You may need to change this depending on what's mounted where. The live Ubuntu system typically mounts the root device (USB stick or CD/DVD) at /cdrom.
  • bs=1MiB: Tell dd how big blocks to write. 1MiB = 1024 * 1024 bytes.
  • count=4095: Files on FAT32 can be up to 4GB in size. 4095 * 1MB is just shy of 4GB.

You may need to mount /cdrom as read-write (or wherever your bootable device is mounted):

mount | grep /cdrom  

You should see a line like:

/dev/sdb1 on /cdrom type vfat (ro,noatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)  

The /cdrom device is mounted in this case on /dev/sdb1. To mount it read-write, you would do:

mount /dev/sdb1 /cdrom -o remount,rw  

This will mount the USB drive already mounted on /cdrom with the remount,rw option which says literally remount read-write

Then you can use the dd command to create your persistence file and use the mkfs command mentioned above to format it.

NOTE: You will probably need to reboot for the persistence file to take effect.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »