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/@
Code: Select all
btrfs subvolume create /mnt/home
Code: Select all
btrfs subvolume list /mnt
Code: Select all
unmount /mnt
(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
Code: Select all
mkdir /mnt/target
mount -o subvol=@ /dev/sda1 /mnt/target
Code: Select all
mkdir /mnt/target/home
mount -o subvol=home /dev/sda1 /mnt/target/home
Code: Select all
rsync -avz /mnt/source/ /mnt/target/
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
Code: Select all
nano /etc/fstab
(Optiional) Add entires for /home and any other subvolumes and mount points you want:proc /proc proc defaults 0 0
/dev/sda1 / btrfs defaults,subvol=@ 0 0
Save and Exit./dev/sda1 /home btrfs defaults,subvol=home 0 0
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
Code: Select all
nano /etc/mdm/mdm.conf
Save and exit.TimedLoginEnable=false
AutomaticLoginEnabled=true
TimedLogin=mint
AutomaticLogin=mint
TimedLoginDelay=30
Delete the "mint" user:
Code: Select all
userdel -rf mint
Code: Select all
passwd
Code: Select all
adduser crossroadstech
Code: Select all
usermod -a --groups=sudo,cdrom,floppy,audio,dip,video,plugdev crossroadstech
Code: Select all
echo LMDE-PC > /etc/hostname
Code: Select all
sed -e 's/mint/LMDE-PC/' -i /etc/hosts
Enter the following command from the root terminal:
Code: Select all
dpkg-reconfigure grub-pc
to:quiet
Now from the root terminal enter:quiet rootflags=subvol=@
Code: Select all
grub-install /dev/sda
Now exit and reboot:
Code: Select all
exit
shutdown -r now
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/ ... t/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
Now, let's install something and rollback...
Code: Select all
apt-get update
apt-get install iceweasel
This means a snapshot was created automatically! Notice in your menu, there is now Iceweasel.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'
Now let's undo it...
To see what snapshots are available, enter the following command:
Code: Select all
apt-btrfs-snapshot list
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.Available snapshots:
@apt-snapshot-2012-04-26_16:37:12
Code: Select all
apt-btrfs-snapshot set-default @apt-snapshot-2012-04-26_16:37:12
Conclusion
I hope you found this how-to useful and interesting. If you have any suggestions for improvement, please share. Happy testing!