Announcement

Collapse
No announcement yet.

How to install Kubuntu 21.10 with BTRFS on root?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to install Kubuntu 21.10 with BTRFS on root?

    I'm looking for some pointers to a how-to. They must exist. I know how to install Archinux on BTRFS so the subvolumes are right for Timeshift and that was pretty easy. Plenty of videos on that. I saw one video on installing Ubuntu with BTRFS, but that required extensive editing of scripts before running ubunbu install.

    I was hoping BTRFS install on root for Kubuntu would be as easy as Ubuntu on ZFS, but there doesn't seem to be an 'Advanced' button in Kubuntu installer.

    #2
    The installation "how to" is in the first part of the top post in the BTRFS subforum.
    https://www.kubuntuforums.net/forum/...guide-to-btrfs

    Choose the manual partition method when the installation gets to the point of selecting the storage medium.
    In the manual mode create the necessary partitions, depending on if you use mbr or gpt.
    Create at least one partition, call it sda1 and for the OS select btrfs. For the mount point select "/". Proceed with the installation.
    The results will be two subvolumes: @ and @home, which will be mounted to "/" and "/home" respectively, as shown in the /etc/fstab file.
    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
    – John F. Kennedy, February 26, 1962.

    Comment


      #3
      Thanks, got it working. What about other subvolumes? I'm used to using one for /var, and if I was using snapper, I'd need one for @snapshots. I currently installed Timeshift and I know it only need @ and @home. Also do I need grub-btrfs installed??

      Comment


        #4
        Originally posted by jfabernathy View Post
        Thanks, got it working. What about other subvolumes? I'm used to using one for /var, and if I was using snapper, I'd need one for @snapshots. I currently installed Timeshift and I know it only need @ and @home. Also do I need grub-btrfs installed??
        What's "grub-btrfs" ? No package showing up in apt-cache search here by that name.

        Once you have the install running, it's simple enough to set up additional subvolumes. Simply create, mount, and populate them.

        For "live" os stuff like /var you could:
        1. boot to a live USB session
        2. mount the root filesystem somewhere
        3. create a @var subvolume
        4. move everything from @/var into @var
        5. edit fstab to mount @var at /var on your next reboot
        6. done
        It is my practice to mount the root filesystem in /mnt/subvol so I can access @ and @home easily for snapshots. I make a folder in the root fs to hold my snapshots, like "/mnt/subvol/snapshots" and send my snaps there to keep the root fs cleaner looking.

        I assume snapper will make whatever it needs (I've never used it). I use a custom cron script to take a daily snapshot and make a weekly backup instead of someone else's tool.

        As far as the "Advanced" button in the installer, it's there, just labeled "Manual" or "Manual Partitioning". I wish you could specify custom subvolume names as well as other configurations like your desire to subvolume out /var.

        Please Read Me

        Comment


          #5
          And, at least with *buntu's, /var et al is "old school" and isn't necessary anymore. At most you need two partitions: root ( / ) and home ( /home). Maybe swap.
          Windows no longer obstructs my view.
          Using Kubuntu Linux since March 23, 2007.
          "It is a capital mistake to theorize before one has data." - Sherlock Holmes

          Comment


            #6
            As to what grub-btrfs is, it's used in Archlinux to make sure when changes are made for system updates or install that grub had those snapshots made before and after the update/install as bootable images just like old versions of the kernel. In Archlinux timeshift when installed provided this same think so you can just point and click to use snapshots for restore from them.

            Comment


              #7
              OK, well, not Arch so...

              As far as /var or whatever else in a separate subvolume, there are some legitimate reasons to do that IMO. For example, on my media server, the catalog (100,000s of entries, many hand-tuned) is held in /var/www. I created a subvolume for www (@www - original, right?) and mount it at /var/www. This allows specific individual backups of the catalog. While it would only take a few minutes to re-install the server OS, it could take WEEKS or longer to recreate the catalog and all of its details.

              Having said that, IMO there's no reason to separate directories anymore as a general practice. It was primarily done in the olden days to allow distribution of the OS across several drives to increase drive space or performance. Especially when you consider that when using BTRFS, you are not restricted to a single device (drive or partition). If more space is needed, simply add the device to your BTRFS file system, done.

              You can still make an argument for a separate /tmp, but with modern RAM sizes, tmpfs in RAM is better anyway.

              SWAP is a singular case as CoW (Copy-on-Write) file systems like BTRFS do not do dynamically allocated files like SWAP files, so a SWAP partition was needed. However, since kernel 5 one can create a no-Cow non-compressed individual subvolume/file for SWAP: https://wiki.archlinux.org/title/Btrfs#Swap_file

              Please Read Me

              Comment


                #8
                What do you use for automatic snapshots, Timeshift? or what.

                Comment


                  #9
                  Originally posted by Snowhog View Post
                  And, at least with *buntu's, /var et al is "old school" and isn't necessary anymore. At most you need two partitions: root ( / ) and home ( /home). Maybe swap.
                  How would you handle a situation where this is your use case:
                  1. "/Home" is fairly stable minimal changes and they need backed up regularly
                  2. "/" needs updating before and after major updates of packages.
                  3. mysql databases in /var/mysql get hammered for both read and write. Also needs backed up daily. Currently done to NAS.
                  3. Need to store media that is recorded from OTA TV tuners. Can be put in any directory and does not need to be backed up or snapshoted.

                  Currently I have all the above conditions solved the old school way. I have Ubuntu 20.04.3 booting from SATA SSD EXT4 file system. I also have Mirrored Hard Drives using mdadm RAID-1. This is where all my media goes as well as a directory I use as a NAS for samba/cifs access from everywhere on the local LAN. All other PC store their critical files on the NAS


                  Comment


                    #10
                    Originally posted by jfabernathy View Post
                    What do you use for automatic snapshots, Timeshift? or what.
                    A script of my own creation.

                    Code:
                    #!/bin/bash
                    #
                    # IMPORTANT:
                    # This script requires the root btrfs file system be mounted somewhere before running.
                    # Alternately, have the mount declared in fstab and the script will mount it.
                    #
                    exec 1> >(logger -s -t $(basename $0)) 2>&1 # Log the script activity
                    
                    ## Set the variables. Edit this section as needed
                    # declare an array variable of all target subvolumes
                    declare -a SUBVLIST=("@KDEneon" "@KDEneon_home")
                    
                    # other variables
                    NOTIFYUSER="stuart"                     # the username to get messages
                    NOTIFYDISPLAY=":0.0"                    # the above user's X session
                    source_folder="/subvol/"                # Root file system mount location
                    backup_folder='/mnt/root_backup/'       # Backup file system mount location
                    snapshot_folder="/subvol/snapshots/"    # Snapshots folder
                    addname="_daily_"                       # This is added to the subvolume name of the daily snapshots
                    lastsnapnum=6                           # Last snapshot number to be saved before moving to backup status
                    
                    # Verify the root BTRFS file system is mounted and mount it if not, or fail;
                    if [ -d "$source_folder" ]; then
                       if ! mountpoint -q "$source_folder"; then
                           mount "$source_folder"
                           if ! mountpoint -q "$source_folder"; then  
                               su $NOTIFYUSER -c "export DISPLAY=${NOTIFYDISPLAY}; /usr/bin/notify-send -i ksnapshot -t 0 'Daily snapshots:' 'Daily snapshot operation failed - no mountable subvolume folder.'"
                               exit 1
                           fi
                       fi
                       else  
                           su $NOTIFYUSER -c "export DISPLAY=${NOTIFYDISPLAY}; /usr/bin/notify-send -i ksnapshot -t 0 'Daily snapshots:' 'Snapshot operation failed - subvolume folder incorrect.'"
                           exit 1
                    fi
                    
                    ## Begin snapshot process
                    # loop through the list of subvolumes
                    for SUBV in "${SUBVLIST[@]}"; do
                       SUBVPATH="$source_folder""$SUBV"
                       SUBVSNAP="$snapshot_folder""$SUBV"
                    
                    # Move last daily snapshot to backup status
                       if [[ -d "$SUBVSNAP""$addname""$lastsnapnum" ]]; then
                           btrfs su de -c "$SUBVSNAP""_backup-new"
                           mv "$SUBVSNAP""$addname""$lastsnapnum" "$SUBVSNAP""_backup-new"
                           btrfs pr set -ts "$SUBVSNAP""_backup-new" ro true
                       fi
                    
                    # Roll the current snapshot names by adding 1 to each trailing number
                       for ((i="$lastsnapnum-1";i>=0;i--)); do
                           if [[ -d "$SUBVSNAP""$addname"$i ]]; then
                               mv "$SUBVSNAP""$addname"$i "$SUBVSNAP""$addname"$(($i+1));  
                           fi
                       done
                    
                    # Take new read-only snapshot
                       btrfs su sn "$SUBVPATH" "$SUBVSNAP""$addname""0"
                       touch "$SUBVSNAP""$addname""0"
                    done
                    
                    # Notify the user that the job is done
                    su $NOTIFYUSER -c "export DISPLAY=${NOTIFYDISPLAY}; /usr/bin/notify-send -i ksnapshot -t 0 'Daily snapshots:' 'Snapshot operation complete.'"
                    
                    # If it's Sunday, do a backup
                    if [[ $(date +%u) -ne 7 ]] ; then
                    # Script complete
                       exit 0
                    fi
                    
                    # Verify the backup file system is mounted and mount it if not, or fail;
                    if [ -d "$backup_folder" ]; then
                       if ! mountpoint -q "$backup_folder"; then
                           mount "$backup_folder"
                           if ! mountpoint -q "$backup_folder"; then  
                               su $NOTIFYUSER -c "export DISPLAY=${NOTIFYDISPLAY}; /usr/bin/notify-send -i ksnapshot -t 0 'Weekly backup:' 'Backup operation failed - no mountable subvolume folder.'"
                               exit 1
                           fi
                       fi
                       else  
                           su $NOTIFYUSER -c "export DISPLAY=${NOTIFYDISPLAY}; /usr/bin/notify-send -i ksnapshot -t 0 'Weekly backup:' 'Backup operation failed - subvolume folder incorrect.'"
                           exit 1
                    fi
                    
                    ## Begin backup process
                    # loop through the list of subvolumes
                    for SUBV in "${SUBVLIST[@]}"; do
                        SUBVSNAPRO="$snapshot_folder""$SUBV""_backup"
                        SUBVBACK="$backup_folder""$SUBV""_backup"
                        
                    # Send incremental backup
                       btrfs send -p "$SUBVSNAPRO" "$SUBVSNAPRO""-new" | btrfs receive "$backup_folder"
                    # Remove old snapshot and backup
                       btrfs su de -c "$SUBVSNAPRO"
                       btrfs su de -c "$SUBVBACK"
                    # Move new backups to old backup status
                    #    if [[ -d "$SUBVBACK" ]]; then
                       mv "$SUBVBACK""-new" "$SUBVBACK"
                    #    fi
                    #    if [[ -d "$SUBVSNAPRO" ]]; then
                       mv "$SUBVSNAPRO""-new" "$SUBVSNAPRO"
                    #    fi
                    done
                    
                    # Notify the user that the job is done
                    su $NOTIFYUSER -c "export DISPLAY=${NOTIFYDISPLAY}; /usr/bin/notify-send -i ksnapshot -t 0 'Weekly backup:' 'Backup operation complete.'"
                    
                    # Script complete
                    exit 0
                    This is set to run everyday a 6:30 am (my computer is usually on and I rarely get up before 7:30). It takes a "rolling" snapshot - keeping the last 7 snapshots and deleting the eldest each time a new one is taken, If it's Sunday, it sends an incremental backup to a different drive and removes the previous one. Even if the computer is off (or running another distro) anacron completes the tasks when the computer is returned to it's normal state.

                    It's saved my bacon more than once!

                    Click image for larger version

Name:	Screenshot_20220113_075959.jpg
Views:	1601
Size:	11.4 KB
ID:	659715

                    Please Read Me

                    Comment


                      #11
                      Originally posted by GreyGeek View Post
                      The installation "how to" is in the first part of the top post in the BTRFS subforum.
                      https://www.kubuntuforums.net/forum/...guide-to-btrfs

                      Choose the manual partition method when the installation gets to the point of selecting the storage medium.
                      In the manual mode create the necessary partitions, depending on if you use mbr or gpt.
                      Create at least one partition, call it sda1 and for the OS select btrfs. For the mount point select "/". Proceed with the installation.
                      The results will be two subvolumes: @ and @home, which will be mounted to "/" and "/home" respectively, as shown in the /etc/fstab file.
                      I finally got the time to completely read the linked post you included. At first I was confused about the mounting process for the BTRFS partition to /mnt. In my mind, that partition is already mounted to / which /mnt is a part of?? So now it's mounted again?? Anyway, without understanding that part I did the mount and the vdir and It seems to work as you already knew it would. I never got to these details on my experiment with BTRFS on Archlinux as there are a few AUR addons that basically do all the pre and post upgrade snapshots for you and fix grub's list of bootable images to reflect that.

                      I've got a lot more reading to do to understand this on Kubuntu.

                      Thanks,

                      Comment


                        #12
                        If you look in your fstab you'll see the mounts include the subvolume name. Something like mine:

                        Code:
                        ## root
                        UUID=<UUID> / btrfs noatime,space_cache,compress=lzo,autodefrag,subvol=@ 0 1
                        ## home
                        UUID=<UUID> /home btrfs noatime,space_cache,compress=lzo,autodefrag,subvol=@home 0 2
                        Note the subvol=@ and subvol=@home at the end of the options.

                        To "expose" the subvolumes, you must mount the root file system. The mount is the same, just without a subvol=, like so

                        Code:
                        ## root BTRFS filesystem
                        UUID=<UUID> /mnt/subvol btrfs auto,users,noatime,space_cache,compress=lzo,autodefrag 0 0
                        Using the above my mounts are:

                        @ mounted at /
                        @home mounted at /home
                        The root file system is mounted at /mnt/subvol

                        So now, when I navigate to /mnt/subvol, I see @ and @home there. As I think I posted earlier, my habit is to create a snapshots folder in /mnt/subvol so I can keep the snapshots neatly in their own folder.

                        I know it seems odd to have a mount in a mount that way, but that's how it's done.

                        Please Read Me

                        Comment


                          #13
                          I was surprised to see my /etc/fstab entry for root no include any options like noatime, space_cache=2 and compress=lzo. Is it too late to add those to my fstab? I wonder what the defaults are
                          Code:
                          UUID=26d5699e-e992-4a60-8d4a-39caa10df08c / btrfs defaults,subvol=@ 0 1

                          Comment


                            #14
                            Originally posted by jfabernathy View Post
                            I was surprised to see my /etc/fstab entry for root no include any options like noatime, space_cache=2 and compress=lzo. Is it too late to add those to my fstab? I wonder what the defaults are
                            Code:
                            UUID=26d5699e-e992-4a60-8d4a-39caa10df08c / btrfs defaults,subvol=@ 0 1
                            Just enter "mount" in a terminal to see all the current options.


                            Please Read Me

                            Comment


                              #15
                              Defaults vary:

                              defaults

                              Use the default options: rw, suid, dev, exec, auto, nouser, and async.

                              Note that the real set of all default mount options depends on kernel and filesystem type. See the beginning of this section for more details.

                              Please Read Me

                              Comment

                              Working...
                              X