|Live USB Persistence
Date: August 07, 2013, 04:43:25 PM
As it turns out, adding persistence to your Live USB is not difficult to do. It's not quite as simple as just running some script, but most of the work can be done using the graphical tool, gparted, plus a small handful of Linux commands.
To start, insert your thumb drive into a USB port. Do not mount it. Make sure to identify the device:
In most cases, the thumb drive will be sdb or sdc, depending on how many internal disks you have.
Fire up gparted, passing it the device path:
gparted /dev/sdb # for example
What you want to do is create 2 ext2 partitions. The first should be slightly larger than the ISO file, the second should span the remainder of the disk. You may have to remove existing partitions first before creating the ones you want.
The reason for using ext2 partitions vs. ext3 or ext4 is because of journaling. Both ext3 and ext4 do extensive journaling which isn't a good thing for thumb drives due to the increased amount of I/O required. Thumb drives do have a lifespan.
Once you have created the 2 partitions, right-click on the first one and select Manage Flags. Check the box labeled "boot". Also, right-click on the second partition and select Label. Enter a label you'll remember, or jot it down, because we're going to need that label - MYLABEL would suffice.
When done, the partitions should look something like this:
Make sure everything's written to the drive and exit gparted.
Now you need to mount both /dev/sdb1 (or sdc1) and the ISO image. We're going to use arbitrary mount points for this example. More experienced users will know how they want to manage this:
mount /dev/sdb1 /tmp/mnt1
mount /path/to/isofile/bluestar-base-2013.08.07-i686.iso /tmp/mnt2
Now we want to copy the contents of the ISO file system to the thumb drive partition:
tar cpf - . | tar xpf - -C /tmp/mnt1
When this is done, the contents of mnt1 and mnt2 should be identical.
You can now unmount the ISO image:
rm -rf /tmp/mnt2
Next we have to install the MBR to the thumb drive:
dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of=/dev/sdb # or sdc
Now we need to install syslinux to the thumb drive, making it bootable:
extlinux --install .
Don;t forget the dot at the end of the extlinux command.
There should now be an ldlinux.sys file in the /tmp/mnt1/arch/boot/syslinux directory.
At this point the thumb drive is bootable and will run as a non-persistent live image.
To add persistence, we now have to edit 2 files in /tmp/mnt1/arch/boot/syslinux - archiso_sys32.cfg and archiso_sys32_netbook.cfg (or their sys64 equivalents in the case of x86_64 images).
Open the files and find the APPEND line - it should be the last line. We're going to replace "cowspace_size=25% cowfile_size=25%" with 'cow_label="MYLABEL"' (or with whatever label you gave to the second USB partition). Leave cow_persistent="P" as is, or add it if you're installing an older version.
The first part of the APPEND lines should now look something like this:
APPEND archisobasedir=%INSTALL_DIR% archisolabel=%ARCHISO_LABEL% cow_label="MYLABEL" cow_persistent="P"
Write out the files and unmount the thumb drive:
rm -rf /tmp/mnt1
The next time you boot from your thumb drive you should have persistence.
1. DO NOT PERFORM FULL SYSTEM UPGRADES - you can update any software that has nothing to do with the kernel or any kernel modules. However, performing updates that affect the kernel will trash your Live system. Luckily, if this happens, solving it requires nothing more than re-formatting and re-labeling the persistence partition (sdb2/sdc2).
2. DO NOT LABEL THE FIRST LINUX PARTITION AS ARCHISO_2013XX (where XX is month) - if you do, the bootloader will mount the partition as the root device instead of the SFS file, which is the real root device, and will crash not knowing how to proceed.
Some users may want to introduce a FAT partition for exchanging files between Windows and Linux. To do this, create 3 partitions instead of 2, formatting the first partition to FAT32 (the FAT partition must be the first partition or Windows won't recognize it). The second and 3rd partitions, in this case, would map to the instructions above. So, you would therefore make sdx2 the boot partition and sdx3 the labeled persistence partition.
Rating: This article has not been rated yet.