Trick installer to use btrfs root with compression

13,739

Solution 1

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!?

Solution 2

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.

Solution 3

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.

Solution 4

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.

Solution 5

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.

Share:
13,739

Related videos on Youtube

mario
Author by

mario

http://freshcode.club/

Updated on September 17, 2022

Comments

  • mario
    mario almost 2 years

    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?

    • Oli
      Oli over 13 years
      Have you tried the alternative (text-mode installer) disk?
    • mario
      mario over 13 years
      @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.
  • JanC
    JanC over 13 years
    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.
  • mario
    mario over 13 years
    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
    mario over 13 years
    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.
  • Oli
    Oli over 13 years
    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)
  • mario
    mario over 13 years
    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
    mario over 13 years
    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
    mario over 13 years
    Most excellent. After some testing, the remount trick worked flawlessly. 1.2G instead of 2.6G used, noticable speed gain.
  • mniess
    mniess over 13 years
    What if you just install ubuntu-minimal and install the rest later?
  • DanielSmedegaardBuus
    DanielSmedegaardBuus about 10 years
    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!