HOW-TO: Install LMDE with BTRFS and Snapshots

Archived topics about LMDE 1 and LMDE 2
Locked
crossroadstech

HOW-TO: Install LMDE with BTRFS and Snapshots

Post by crossroadstech »

Introduction
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? :shock:

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/ ... 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
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. :shock: :D

Conclusion
I hope you found this how-to useful and interesting. If you have any suggestions for improvement, please share. Happy testing! :wink:
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
crossroadstech

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by crossroadstech »

I'm not sure why or how, but after several package installs, snapshot restores, and reboots, I received the following error on a reboot and after GRUB tried to load the kernel...
Initramfs unpacking failed: LZMA data is corrupt
Kernel panic - not syncing: VFS: Unable to mount rootfs on unknown-block(0,0)
...
My theory is something is happening with GRUB. I was able to fix and boot again by booting with the Live DVD, doing the CHROOT section above, and dpkg-reconfigure grub-pc and grub-install /dev/sda. If anyone else sees this or has any idea what is happening, please share.

I'm confident it is not the filesystem. I ran btrfsck offline from the live DVD shell and it didn't find any errors.

**UPDATE**
This would randomly occur on reboots. And if I keep rebooting or power-cycling, it eventually would stop erroring and boot. :?:

I did find this Can 12.04 be installed using Btrfs only? and it mentioned that gzip is the default decompression tool in /etc/initramfs-tools/initramfs.conf in Ubuntu 12.04. I changed the following in /etc/initramfs-tools/initramfs.conf...

COMPRESS=gzip

...and did a dpkg-reconfigure initramfs-tools. So far so good. I'll keep this post "posted" if my system stops booting again!
melbo

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by melbo »

Thanks for this tutorial.

I followed it and then tweaked my mount settings in fstab based on a few other recommendations.

Interestingly, I borked my grub (and other things) while attempting to use SMXI to install 3.3 liquorix kernel and could not get back into my system at all. I booted from the LMDE Live CD and went into Computer on my desktop. I saw my @ directory and a bunch of snapshot folders on the install SSD. As root, I deleted my @ directory and then renamed my most recent snapshot folder to @.

Rebooted and it was like the Liquorix kernel install failure never happened!

I may be able to stop those time consuming clonezilla sessions now that I've tried btrfs and realized the awesomeness of the snapshot restore feature.
melbo

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by melbo »

Interesting. By placing /boot into the btrfs volume like suggested in the tutorial, any 'other' kernel I try (want to grab the latest btrfs stuff!), I get a grub error on reboot.
Perhaps this is not the ideal install solution for btrfs?

On a side not, I've been able to use a fallback snapshot each time it failed so I'm not so worried, just want to try the btrfs options in the latest kernel
crossroadstech

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by crossroadstech »

melbo wrote:Interesting. By placing /boot into the btrfs volume like suggested in the tutorial, any 'other' kernel I try (want to grab the latest btrfs stuff!), I get a grub error on reboot.
Perhaps this is not the ideal install solution for btrfs?

On a side not, I've been able to use a fallback snapshot each time it failed so I'm not so worried, just want to try the btrfs options in the latest kernel
After you install a new kernel, have you tried to manually run "grub-install /dev/sdx" before you reboot?

You could put /boot on its own ext4 partition, but keep in mind you will probably hose your install if you rollback your root filesystem to a snapshot created before the new kernel install. That's why I included /boot in @ in my tutorial. As long as you don't rollback to before a kernel upgrade, putting /boot in its own partition should be fine.
melbo

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by melbo »

Thank you for the tip. I have not tried this.
I did add Sid sources, upgraded grub to latest (1.99?) and tried again and am now testing 3.4.X with no problems.
I think the default grub2 included with LMDE 201204 didn't like the grub probe on compile.

I'll keep playing and report back any problems.

I have used the Live DVD/rename @ from snapshots about 50 times over the past few days... this alone has me sold on btrfs!
crossroadstech

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by crossroadstech »

melbo wrote:Thank you for the tip. I have not tried this.
I did add Sid sources, upgraded grub to latest (1.99?) and tried again and am now testing 3.4.X with no problems.
I think the default grub2 included with LMDE 201204 didn't like the grub probe on compile.

I'll keep playing and report back any problems.

I have used the Live DVD/rename @ from snapshots about 50 times over the past few days... this alone has me sold on btrfs!
Can you check and see exactly what package version of grub you upgraded too? I will add that information to this tutorial.

Snapshots are awesome! This past month, I started looking at upgrading to a new distro from Ubuntu 10.10 and when I heard about and saw btrfs, I almost converted to OpenSUSE for btrfs and their snapshot tool, snapper. But I've always used Debian-based distros (since Potato) for my desktop and I just can't wrap my head around the bloat and slowness of YAST.

It was also so easy to setup RAID 1, and love the fact I can add a hard drive and grow my root file system whenever I want. Probably never will, but it sure is nice to have options!
melbo

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by melbo »

My current grub version is 1.99-17
Just upgrade to kernel 3.4 and btrfs 'feels' even faster.

I followed your tutorial using the (optional) /home directory. When viewing my system in various ways, I'm seeing a 2x drive capacity - ie. My / and my /home both display the entire amount of my HDD. I'm sure its just cosmetic but it's not correct.
crossroadstech

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by crossroadstech »

melbo wrote:I followed your tutorial using the (optional) /home directory. When viewing my system in various ways, I'm seeing a 2x drive capacity - ie. My / and my /home both display the entire amount of my HDD. I'm sure its just cosmetic but it's not correct.
That actually is correct... Setting up your subvolumes on the btrfs partition, both / and /home can use up to the entire partition (or drive) capacity. They are not fixed sizes like partitions. It's a little confusing if you are use to partitions, but this is a very cool feature.

In a related note, there is a bug with XFCE Thunar in LMDE where it will show you have infinite free space. :lol:
melbo

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by melbo »

Thank you again for this tutorial! i keep coming back to it as I tweak my system...

If we wanted to place the subvolume /home on a separate HDD (device) and @ is on sda1, would it look something like this?

Code: Select all

mount /dev/sd[b]b[/b]1 /mnt/
btrfs subvolume create /mnt/home
Assume using an SSD for / and wanting /home on the second drive - with no raid.
luis.nando

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by luis.nando »

@crossroadstech

Well, I`ve not seen your post before, but I managed to install LMDE with a BTRFS partition using the LMDE installer. Does this change anything??? Can I follow your how-to from item 8???


thanks
penzoiders

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by penzoiders »

@crossroadstech
I've wrote an easier tutorial, you can check it here if you want:
http://penzoditutto.blogspot.it/2013/02 ... ebian.html

let me know if works for you too.

:)
sammiam

Re: HOW-TO: Install LMDE with BTRFS and Snapshots

Post by sammiam »

Hi... I followed this guide, and it worked just great.... now... I upgraded my kernel to the 3.8.4 kernel, and it won't boot... it panics and states that it cannot read from the root device, and is asking to have the correct 'root=' set. This is set in the /etc/default/grub .. the old kernel boots great... now something strange.... if I boot the new kernel in rescue mode, which it does just fine, and when I exit from rescue mode, it automatically goes into multi-user mode, everything comes up just fine.... I'm just not able to boot directly into multi-user mode... any thoughts???

EDITED...

Well, almost... seems that it does not always boot in single user mode.... for a while it did, now I am getting the panic all the time.... strange.....

UPDATE:.....
OK, so I worked it out..... what I did was just use a standard plain old btrfs, WITHOUT defining any sub-volumes ... everything works well, although I realize this will not allow the Snapshots to work, but with me that's not an issue, as I use rsnapshot to backup all my data, and can live without the btrfs snapshots....

Yet another UPDATE...

So much with my flirting with a new kernel... this am I boot, and get the same old PANIC where the kernel cannot read the root file system..... go figure.... anyway, the 3.8 kernel does not install completely anyway because of a libc6 dependancy... I'll just live with the original kernel and wait for a new one to come along that is sanctioned by LMDE...
Locked

Return to “LMDE Archive”