Skip to content

Debian usb Live with Persistent

fonte

After several attempts to create a waldorf liveUSB with persistence I finally bumped into this post “The Correct Way for Persistence on a LiveUSB for WALDORF” by kyeshi98 [1], who I would like to thanks again for the great tips.

I guess Kye’s guide should work fine, but I don’t use unetbootin-like programs, as I like to use fdisk and dd to deal with the partitions and copying the ISO. There’s a portuguese version [2] if you prefer. So in this guide I’ll explain how:

  1. Setup the USB drive with fdisk
  2. “Burn” the ISO to a partition with dd
  3. Setup and configure the persistence
  4. Install GRUB2 to the USB drive
  5. Troubleshoot the persistence #! environment
ADVISE

Be advised that ALL DATA on your USB drive will be erased! And be extremely careful providing the correct path for the USB drive as you might erase ALL your HARD DRIVE DATA! You’ve been advise, check twice and only run the commands when you understand what they are doing!

 

Setup the USB drive

Setup the partitions with fdisk
I assume there is no partition on the USB drive and in this case will be a 4GB device.

fdisk will create two ext2 primary partitions: one labeled persistence, with the boot flag on, and the size of the USB drive minus the size of the ISO (as I roundup the ISO to 1GB), in this case 3GB; the other with the remaining 1GB and no other special care.

$ sudo fdisk /dev/sdX

n – create the first partition
p – indicate it will be a primary partition
[enter] – accept the start of the first partition (zero)
+3GB – size of the partition
a – activate the boot flag so it can be booted from

n – create the second partition
p – indicate it will be a primary partition
[enter] – accept the start of the second partition (usually safe)
[enter] – accept the ending of the second partition (usually the last one of the drive)
w – write all changes
q – exit

 

“Burn” the ISO to a partition

After the partition setup you should guarantee that the second partition is unmounted before “burning” the ISO.

$ dd if=crunchbang-11-20130506-amd64.iso of=/dev/sdX2; sync

The sync will guarantee that it finishes only after all data is written on the drive

 

Setup and configure the persistence

Create the filesystem for persistence

$ mkfs.ext2 -L persistence /dev/sdX1

This will format the first partition of the drive with an ext2 filesystem and label it persistence

Configure the persistence
Unfortunately CrunchBang is built up a very old debian live system so the official debian live documentation can’t be fully used to configure the persistence. As explained to me there was a very short period of time long ago that the debian live project used the filename “live-persistence.conf”, but that was discontinued and almost all versions use the filename “persistence.conf”.

So to run #! CrunchBang waldorf with persistence the live-persistence.conf file must exist on the persistence partition. So make sure the persistence partition is mounted, usually in /media/persistence.

$ nano /media/persistence/live-persistence.conf

In it you should define what folders should be persistence and in what manners. You should read the debian live documentation [3] to get a better idea. Don’t forget that it still states the persistence configuration file as being persistence.conf!

For quick and simple persistence you should add

/ union

It’s a [slash] [space] union stating the root filesystem / will be a union of the files on the liveUSB with the files persistent on the USB drive, so each time it boots it will merge together these files.

My live-persistence.conf is little bit different

/home
/opt
/boot/grub
/etc union
/usr union
/var union
/bin union
/sbin union

I changed it a little bit, mainly for saving some space on the drive, being able to edit the GRUB from inside the liveUSB and to get all /home files and /opt programs on the USB drive directly.
The other folders are still in test but handled well updates, upgrades and program installations using apt-get.
If you need more folders (/root or /srv) just add them with the union option.

If you know more about this please contribute in the comments!

Install GRUB2

You can play a lot with grub and if you need you can check out the CrunchBang ISO configuration boot files like /isolinux/live.cfg.
Also there’s a great deal of documentation to the GRUB2, please check the ubuntu community [4] and the dedoimedo documentation [5].

Make sure the persistence partition is mounted, usually in /media/persistence.
To install GRUB2, version 1.99 you should:

$ grub-install --force --no-floppy --root-directory=/media/persistence /dev/sdX

Next setup the menu entries with:

$ nano /media/persistence/boot/grub/grub.cfg

In this case I want two menu entries: one for the persistence environment; and another just to start the live environment as a regular #! CrunchBang liveUSB.

set timeout=5
set default=0

menuentry "#! 11 - waldorf 64bits - Persistence" {
  linux (hd0,2)/live/vmlinuz boot=live config persistence
  initrd (hd0,2)/live/initrd.img
}

menuentry "#! 11 - waldorf 64bits - Live" {
  linux (hd0,2)/live/vmlinuz boot=live config            
  initrd (hd0,2)/live/initrd.img
}

This will boot the first menu entry if no key is pressed within 5 seconds.
Also the first entry launches the kernel and initrd from the second partition (hd0,2) and adds the boot flag persistence to the kernel.
The second entry is used to launch the live environment as a regular waldorf liveUSB.

EDIT
This entry boots #! into install mode.

menuentry "#! 11 - waldorf 64bits - Install" {
  linux (hd0,2)/install/gtk/vmlinuz video=vesa:ywrap,mtrr vga=788 file=/cdrom/install/crunchbang.cfg
  initrd (hd0,2)/install/gtk/initrd.gz
}
Troubleshoot the persistence environment

Users
Add your user and remove the crunchbang user, by the way the crunchbang user has password live.

$ sudo adduser user
$ sudo adduser user sudo
$ sudo su
$ passwd

Logout and login with your user to test if it worked.
Next, change the login options in the System > User Login Settings to comply with your setup.

Test your persistence
Now if you want you might reboot just to check everything works fine!
If so just update, upgrade and install all you need!

Update and upgrade

$ sudo apt-get update
$ sudo apt-get upgrade

UPDATE:
I think it’s not possibly to delete crunchbang user as all tty terminals (accessed with CTRL+ALT+F1…F4) are always with crunchbang already logged in…

Please comment!
If you have any issues, i’ll try to help you out.

 

References

[1] – http://crunchbang.org/forums/viewtopic.php?id=25489
[2] – http://librehacks.blogspot.pt/2014/06/c … veusb.html
[3] – http://live.debian.net/manual/current/h … n.html#549
[4] – https://help.ubuntu.com/community/Grub2
[5] – http://www.dedoimedo.com/computers/grub-2.html


Last updated: 5 Ottobre 2015 by Pierluigi Minati