Score:0

Move the root from one subvolume to another in BTRFS

ck flag
Bob

I want to install Ubuntu in the BTRFS @root subvolume, but the Ubuntu installer does not allow changing the default subvolumes and installs in @ and @home.

I'm trying to create a @root subvolume after installation, but I have a problem. I need to edit fstab and GRUB. GRUB needs to know where to find the new root. I've read that the community edits /boot/grub/grub.cfg but some people say it's unsafe because /boot/grub/grub.cfg will be overwritten on the next kernel update or when you run update-grub.

How can I move the root from one subvolume to another?

Pilot6 avatar
cn flag
Do you want to keep separate `@home`? In this case it is much easier.
Bob avatar
ck flag
Bob
@Pilot6 It's not matter. The main goal move root to new subvolume `@root`. In general I think about structure `@root`, `@home`, `@swap`.
Pilot6 avatar
cn flag
So the only point is to change the name. You can simply rename the subvolume and update-grub as mentioned in my answer. No need to copy or move anything. But it makes no sense. You'll have `/home` at `@home`, `/swap` at `@swap` and `/` at `@root`. it makes no sense and is confusing, because there is `/root` too.
Bob avatar
ck flag
Bob
@Pilot6 Not really. I will have [Flat Layout](https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Flat:~:text=in%20the%20filesystem.-,Layout,-There%20are%20several). But it like rename. Thanks.
Score:2
cn flag

It is not very complicated if you know what you are doing.

  1. Boot from a LiveUSB.

  2. Mount the disk to /mnt and create @root subvolume.

  3. Copy using cp -a everything from @ and @home to @root. You can use mv, but it is safer to keep the old subvolumes before all settles.

  4. Update /etc/fstab with subvol=@root option. Don't forget to remove the /home mount if you don't want a separate /home. (Why?)

  5. Mount the disk to e.g. /mnt with -O subvol=@root. Also run

     sudo mount --bind /dev /mnt/dev
     sudo mount --bind /proc /mnt/proc
     sudo mount --bind /sys  /mnt/sys
    
  6. Chroot to /mnt and update grub.

Bob avatar
ck flag
Bob
Do you want to say I don't need edit GRUB file? Only edit `fstab` and use `update-grub` ?
Pilot6 avatar
cn flag
`update-grub` will create a correct file.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.