11

I want to install Maverick onto a BTRFS root partition. Not for fun or testing, but because I need compression due to a small flash disk (4GB).

Now the 10.10 installer finally supports btrfs, but there is no way to enable the compress flag in it. Can I trick the installer somehow? For old versions and getting LUKS you could pre-mount partitions. Or is there an easy monkeypatch possible to enable btrfs+compress pre install?

2
  • Have you tried the alternative (text-mode installer) disk?
    – Oli
    Oct 11, 2010 at 23:21
  • @Oli: Just tried it now. The -alternate Debian installer is more elaborate. But it only lists standard filesystem flags (noatime,nodev,noexec). It prevents setting btrfs-specific options like compress or ssd. No luck.
    – mario
    Oct 12, 2010 at 8:57

10 Answers 10

12

An easier way to do this is to alter the mount command of the live environment.

  1. Boot as usual to the live session.
  2. Move the mount executable to another location:

    sudo mv /bin/mount /bin/mount.bin
    
  3. Edit a new file using sudoedit /bin/mount and save the following script into it (alter the options as you like; here we have added compress):

    #!/bin/sh
    if echo "$@" | grep -q -- "-t btrfs"; then
        /bin/mount.bin "$@" -o compress
    else
        /bin/mount.bin "$@"
    fi
    

    You can also match block devices like /dev/sda1 instead of -t btrfs and chain elifs to use different mount options for different devices and filesystems.

  4. Copy the original permissions over to the new script:

    sudo chmod --reference=/bin/mount.bin /bin/mount
    
  5. Install as usual and your btrfs partition will be mounted with the specified options (here, compress).

  6. After the installation is finished, before exiting the live envirement, alter the /etc/fstab of the newly installed system to match the specified options, so it will use the same options on new boots.

I used: defaults,noatime,compress-force=lzo,space_cache as mount options.

This works with quantal daily (30/6/12).

I used the btrfs partition as / and a swap partition.

Credits go to this post (in this thread), which in turn cites this blog post.

1
  • I wish I could triple-upvote this, because this is now the third time I forget how to do this properly, and this is still where I end up googling for it intensively. Though you need to use sudo on most points, of course, which might not be obvious to less experienced users. So cool! May 2, 2014 at 21:59
5

Just after the installer mounts your partition, you could try to switch to a shell and do a mount -o remount,compress /target, this might work.

2
  • 1
    That seemed to work! (Though I screwed something else up..) But it required the full command mount -o remount,compress,ssd /dev/mapper/target /target -t btrfs with source device.
    – mario
    Oct 12, 2010 at 12:35
  • Most excellent. After some testing, the remount trick worked flawlessly. 1.2G instead of 2.6G used, noticable speed gain.
    – mario
    Oct 12, 2010 at 12:54
3

I came across this thread as because I was looking to install Linux Mint Debian Edition on a flash drive and installing on compressed btrfs from the get-go. Although these solutions were not directly applicable to reaching my results I used some of this information to reach my target.

The problem was that the point of the installer formatting and mounting the partition and starting copying files was right next to each other, as so I was unable to perform the "remount" option mentioned by others above.

The LMDE version of the installer script was in python (usr/lib/live-installer/installer.py). I'm not sure if it is the same with Ubuntu, but if it is, this will be directly applicable. This allowed me to edit the script and add this line right under the line that origionally mounted the partition for "/"

os.system("mount -o remount,compress /dev/sda3 /target -t btrfs")

of coures the "/dev/sda3" will vary depending on your device.

I understand this is an Ubuntu forum, but like I said it came up with the search and this solution would be directly relevant if the installer is python based. We are all Debian here anyways, right!?

3

More recent distributions use busybox for most commands, including mount. In these releases, /bin/mount is a symlink to /bin/busybox and the symlink must be named "mount", and not "mount.bin" in order to work correctly. As such, the above answer by Mskje can be changed to the following:

  1. Boot as normal to the live session.
  2. sudo rm /bin/mount
  3. sudo mkdir /bin/orig
  4. sudo ln -s /bin/busybox /bin/orig/mount
  5. sudo nano /bin/mount - this will create a new script.
  6. Copy this to the script and save (alter the options as you like, here compress):

    #!/bin/sh  
    if echo $@ | grep "btrfs" >/dev/null; then  
        /bin/orig/mount $@ -o compress  
    else  
        /bin/orig/mount $@  
    fi
    
  7. sudo chmod 755 /bin/mount to make it executable.

  8. Install as normal and your btrfs partition will be mounted with the specified options (here compress).
  9. After the installation is finished, before exiting the live envirement, alter the fstab of the newly installed system to match the specified options, so it will use the same options on new boots.
2

As of 13.04 (Raring Ringtail), you should be able to install on a btrfs volume without compression and then compress every file on the whole volume once you're booted up to the new installation.

According to Oracle's documentation, you can compress existing files on an existing filesystem by defragmenting it with the -clzo option.

sudo btrfs filesystem defragment -clzo /

Passing it the single slash tells btrfs to defragment all files and directories on your root volume.

See: http://docs.oracle.com/cd/E37670_01/E37355/html/ol_use_case1_btrfs.html

Once you're done, add the compress=lzo (or compress=zlib if you prefer, but lzo is recommended for speed) to your volume's line in /etc/fstab and reboot so any further files written to the disk will be compressed.

1

Selecting manually: /dev/sda1 as btrfs for / some ext? /boot some swap

In a terminal: sudo bash

Press install

Press enter on the terminal line: (sudo done) mount -t btrfs -o remount,compress /dev/sda1 /target

1

You can get any or all of the cool new Btrfs features by running the mkfs.btrfs command manually. The alternate installer has an option at any point to go back to a previous step of your choice. you can use this to, after the installer creates the btrfs, make your own btrfs and then start the installer at the previous step so your fs gets used.

  1. run the installer until after the partition phase.
  2. let it install the base system.

  3. alt-F2 go to the terminal and run mkfs.btrfs - /dev/sdXY

  4. go back to the installer alt-F1
  5. hit the "go back button" then choose the partition option again. the defaults will be to not reformat so you can just hit continue. it will re-install the base system. say yes to the warning about not re-formatting.

  6. enjoy.

1

I got it working by replacing the ext4 partition on the stick with a compressed btrfs partition. This can be done using another computer.

  1. Copying everything via

    sudo cp -ar /ext4Partition/* /backupspace/
  2. Replace partion using gparted with btrfs one

  3. Mount new partion using sudo mount mount -o compress /dev/yourdevice /btrfsPartition
  4. Copy back everything

    sudo cp -ar /backupspace/* /btrfsPartition/
  5. Update /btrfsPartition/etc/fstab to new device uuids and to new partition type. Remove remount Option, as btrfs does not have this.
  6. reinstall boot loader (e.g. via BootRepair)

Note: the directories /btrfsParition, /ext4Partition and /backupspace can be set as you want.

0

You can just add compression later. Open /etc/fstab and edit the line for your root filesystem. Add compress to the mount-options like this:

UUID=0c8e6d48-e6b3-425a-ab33-24205a9cb586 / btrfs defaults,compress 0 1

Now either remount or reboot and don't forget that /boot can't live on btrfs, yet, since GRUB2 doesn't support it.

3
  • 2
    As far as I know, adding compress in fstab has no effect on existing files (which will be a large part of that 4 GB SSD already when you only add it after install!). I think creating & mounting the partitions pre-install is the best option when using the live-CD.
    – JanC
    Oct 12, 2010 at 1:37
  • Yes, adding the option later doesn't compress the files. Last time I did a complete file backup, then changed the filesystem flags, and afterwards overwrote everything. Very cumbersome. And it's just that tar sometimes forgets a few file attributes, not sure if I used pax or rsync in lieu.
    – mario
    Oct 12, 2010 at 8:11
  • What if you just install ubuntu-minimal and install the rest later?
    – mniess
    Oct 12, 2010 at 22:42
0

You could always follow the ancient Chinese proverb:

If you don't like what the installer partitioner does, partition it yourself and tell the installer to install onto those partitions.

3
  • Who am I to question old chinese proverbs? But does the new 10.10 installer honor a mounted /target? If it insists on remounting, all my precious manual partitioning would be in vain.
    – mario
    Oct 12, 2010 at 10:37
  • Pass. If I had the ISO still, I'd test it out in VirtualBox but again, I think you'll probably have better luck with the alternate installer (it tends to react better to user-interference)
    – Oli
    Oct 12, 2010 at 10:45
  • Just gave it another whirl. Both installers are pretty unmount-happy. Manual partitioning still is a solution for LUKS, but manual mount options don't persist for btrfs. The alternate install wizard seems generally less happy with non-standard options, but at least you can see what's going on. The desktop installer unmounts the target two or three times.
    – mario
    Oct 12, 2010 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .