Wouldn't it be great if after you did a apt-get dist-upgrade on your rolling (or semi-rolling) LMDE, and it hosed your install, you could undo it in a matter of seconds?
This article is a How-To to do a fresh LMDE install using the new "experimental" BTRFS and it's "Snapshot" (similar to Windows System Restore) feature. After we install LMDE, we'll also install the apt-btrfs-snapshot scripts from Ubuntu. It will automatically make snapshots when apt installs or uninstalls debs, and makes it easy to restore the file system to an earlier snapshot.
Disclaimer: If you lose all your data, your PC and house catches on fire, and/or your dog passes on... it's not my fault! Use this article at your own risk!
How-To Revision History
25-May-2012: Added apt-get purge of live-* packages.
26-Apr-2012: Initial Release
About BTRFS
BTRFS is still considered an "experimental" file system, but as of April 2012, the file system design itself, and how it is implemented in the Linux kernel is complete. Work is still being done on the utilities to work with BTRFS, especially a FSCK program. BTRFS has matured enough that it is now an option in the OpenSUSE 12.1 installer and it may become the default file system for Fedora 17. OpenSUSE has even developed Snapper which does exactly what we are doing here... making it easy to rollback your install to a previous snapshot.
As this file system is experimental, please have a backup plan in place. If the file system crashes, and you lose your data, do you have a backup?
Also, from my research it seems that most errors in BTRFS are from power failures. I highly recommend and to reduce the risk of data loss that you have an Uninterruptable Power Supply (UPS) or battery backup for your PC.
BTRFS also supports RAID 0, 1, and 10, as well as shrinkable and growable volumes. Here's some great web sites to find out more about the features of BTRFS:
Weekend Project: Get to Know Btrfs
BTRFS Fun - Funtoo Linux
BTRFS Wiki
Prerequisites
LMDE 201204 Cinnamon/Mate or LMDE 201204 XFCE DVD
Some or all of the information in this article may or may not apply to other distros.
Linux Kernel 3.2 or newer
Older kernels, especially the one that originally came with Debian Squeeze has issues with BTRFS
GRUB 2 and btrfs-tools
Already installed on the LMDE Live DVD.
Boot from the Live DVD and let's get started...
1. Partitioning/Make File System
You can use GParted included on the DVD to create a new BTRFS file system. If you want to create a BTRFS using RAID, reference the links above, especially BTRFS Fun - Funtoo Linux to find out how to use the btrfs command from the terminal.
2. Create an "@" and "home" subvolumes
The apt-btrfs-snapshot tool that we are going to install at the end of this How-To, expects the root file system to be in a subvolume called "@". To create it from a root terminal (Replace sda1 with the name of your BTRFS partition):
- Code: Select all
mount /dev/sda1 /mnt/
btrfs subvolume create /mnt/@
[Optional] You can also create a subvolume that you will mount /home to. You may want to create subvolumes for any directories that you do not want included in the Snapshot and Rollback feature (like MySQL databases, for example) to mount in their respective locations:
- Code: Select all
btrfs subvolume create /mnt/home
To verify what subvolumes are created:
- Code: Select all
btrfs subvolume list /mnt
Unmount when done:
- Code: Select all
unmount /mnt
3. Copy the Live DVD filesystem to the new "@" subvolume
(Credit: The steps to do a manual LMDE install I got from AkiraYB's HOWTO: Install LMDE on a system with a Fake RAID (dmraid) post.)
Mount the Live DVD filesystem.squashfs:
- Code: Select all
mkdir /mnt/source
mount -o -loop -t squashfs /live/image/casper/filesystem.squashfs /mnt/source
Mount the "@" Subvolume:
- Code: Select all
mkdir /mnt/target
mount -o subvol=@ /dev/sda1 /mnt/target
(Optional) Mount the "home" and any other subvolumes you created:
- Code: Select all
mkdir /mnt/target/home
mount -o subvol=home /dev/sda1 /mnt/target/home
Copy the DVD file system (must be exactly like this, with slashes at the end of directories):
- Code: Select all
rsync -avz /mnt/source/ /mnt/target/
Copying could take 5-10 minutes to complete.
4. CHROOT to the new "@" subvolume
- Code: Select all
mount --bind /dev /mnt/target/dev
mount --bind /dev/pts /mnt/target/dev/pts
mount --bind /dev/shm /mnt/target/dev/shm
mount --bind /proc /mnt/target/proc
mount --bind /sys /mnt/target/sys
mount --bind /tmp /mnt/target/tmp
cp -f /etc/resolv.conf /mnt/target/etc/resolv.conf
chroot /mnt/target
5. Create your FSTAB
- Code: Select all
nano /etc/fstab
Enter the following entries as follows in the file. Substitute sda1 for your BTRFS file system:
proc /proc proc defaults 0 0
/dev/sda1 / btrfs defaults,subvol=@ 0 0
(Optiional) Add entires for /home and any other subvolumes and mount points you want:
/dev/sda1 /home btrfs defaults,subvol=home 0 0
Save and Exit.
6. Remove the Live configuration
This removes the specific configuration used by the Live DVD from your install.
Remove the "live" environment specific packages:
- Code: Select all
apt-get remove --purge live-initramfs live-config live-config-sysvinit live-installer live-installer-slideshow
To remove the auto-login to the mint account, use nano to remove all entries under [daemon] in /etc/mdm/mdm.conf:
- Code: Select all
nano /etc/mdm/mdm.conf
Remove the following lines:
TimedLoginEnable=false
AutomaticLoginEnabled=true
TimedLogin=mint
AutomaticLogin=mint
TimedLoginDelay=30
Save and exit.
Delete the "mint" user:
- Code: Select all
userdel -rf mint
Set a password for "root":
- Code: Select all
passwd
Add your user account. Substitute crossroadstech for the username you want:
- Code: Select all
adduser crossroadstech
Assign groups to your account:
- Code: Select all
usermod -a --groups=sudo,cdrom,floppy,audio,dip,video,plugdev crossroadstech
Set your hostname. Substitute LMDE-PC for whatever you want:
- Code: Select all
echo LMDE-PC > /etc/hostname
Fix the /etc/hosts file for your hostname. Substitute LMDE-PC for what you entered for your hostname.
- Code: Select all
sed -e 's/mint/LMDE-PC/' -i /etc/hosts
7. Setup GRUB
Enter the following command from the root terminal:
- Code: Select all
dpkg-reconfigure grub-pc
On the second box that appears, "Linux Default Command Line" change the entry from:
quiet
to:
quiet rootflags=subvol=@
Now from the root terminal enter:
- Code: Select all
grub-install /dev/sda
Substitute sda for the name of the device your BTRFS file system is installed on. Notice no number at the end.
Now exit and reboot:
- Code: Select all
exit
shutdown -r now
Your system should reboot and LMDE should load from your hard drive.
8. Install apt-btrfs-snapshot from Ubuntu
Once you are logged in and at the MATE or XFCE desktop, open Firefox and go to the following URL:
http://packages.ubuntu.com/precise/all/apt-btrfs-snapshot/download
Click on one of the mirror links and open the file with GDebi.
Click Install Package.
9. Testing and using apt-btrfs-snapshot
You should be ready to go! Now to make sure apt-btrfs-snapshot is installed and working, go to a root terminal and enter the following command:
- Code: Select all
apt-btrfs-snapshot supported
It should return "supported." If it returns "unsupported", verify that your /etc/fstab has defaults,subvol=@ for the / mount point.
Now, let's install something and rollback...
- Code: Select all
apt-get update
apt-get install iceweasel
Once the file completes downloading and before unpacking the debs you should see something like this...
Create a snapshot of '/tmp/apt-btrfs-snapshot-mp-xSHqD9/@' in '/tmp/apt-btrfs-snapshot-mp-xSHqD9/@apt-snapshot-2012-04-26_16:37:12'
This means a snapshot was created automatically! Notice in your menu, there is now Iceweasel.
Now let's undo it...
To see what snapshots are available, enter the following command:
- Code: Select all
apt-btrfs-snapshot list
You should see something like this:
Available snapshots:
@apt-snapshot-2012-04-26_16:37:12
Now to roll back to how our filesystem was before Iceweasel was installed, enter the following command. Change the @apt-snapshot to match the exact name of the snapshot on your system.
- Code: Select all
apt-btrfs-snapshot set-default @apt-snapshot-2012-04-26_16:37:12
Now reboot and magically Iceweasel never happened.
Conclusion
I hope you found this how-to useful and interesting. If you have any suggestions for improvement, please share. Happy testing!



