How to move /var to another disk

I have Leap Micro 5.5 installation.
btrfs subvolume list / looks like:

ID 257 gen 19 top level 5 path @
ID 258 gen 1925 top level 257 path @/.snapshots
ID 259 gen 55 top level 258 path @/.snapshots/1/snapshot
ID 260 gen 36 top level 257 path @/home
ID 261 gen 269 top level 257 path @/opt
ID 262 gen 2118 top level 257 path @/root
ID 263 gen 36 top level 257 path @/srv
ID 264 gen 2130 top level 257 path @/var
ID 265 gen 183 top level 257 path @/boot/writable
ID 266 gen 1922 top level 257 path @/usr/local
ID 267 gen 36 top level 257 path @/boot/grub2/i386-pc
ID 268 gen 36 top level 257 path @/boot/grub2/x86_64-efi

I would like to move @/var to /dev/sdb1 which is formatted to btrfs.

So I did these steps:

mount /dev/sdb1 /mnt
btrfs subvolume snapshot -r /var ~/var-snapshot 	# create snapshot
btrfs send ~/var-snapshot | sudo btrfs receive /mnt/ # send/receive
mv /mnt/var-snapshot/ /mnt/var # rename to var

Then on new disk it looks like this:

btrfs subvolume list -at /mnt
ID      gen     top level       path
--      ---     ---------       ----
263     21      5               var
# blkid
/dev/sdb1: UUID="d5587051-e693-42ca-8613-ef05df025ae9" UUID_SUB="94e46dca-e464-4e31-a0ad-fa6dedff3eca" BLOCK_SIZE="4096" TYPE="btrfs" PARTUUID="e66c2d4b-3eba-ff41-9fc7-8979a59bd3d3"
/dev/sda2: SEC_TYPE="msdos" LABEL_FATBOOT="EFI" LABEL="EFI" UUID="818C-BFF8" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="p.UEFI" PARTUUID="883c911a-a5cd-4a7d-be1f-14fc87e48bb9"
/dev/sda3: LABEL="ROOT" UUID="c34d4609-6926-422c-8351-175febfc296f" UUID_SUB="6bdeedf3-e03d-402e-975f-b0545f26070d" BLOCK_SIZE="4096" TYPE="btrfs" PARTLABEL="p.lxroot" PARTUUID="63ada34e-13dd-4d5a-9b55-964a45a83c3d"
/dev/sda1: PARTLABEL="p.legacy" PARTUUID="8d6bc9aa-27ad-4f93-8cb7-9a5948c9804c"

But when I change /etc/fstab from:

UUID=c34d4609-6926-422c-8351-175febfc296f /var btrfs defaults,subvol=@/var,x-initrd.mount 0 0


UUID=d5587051-e693-42ca-8613-ef05df025ae9 /var btrfs defaults,subvol=var,x-initrd.mount 0 0

and reboot nothing changes.

Am I doing something wrong? Is it even possible?
Thank you.

1 Like

It is possible that /var is mounted in initrd already. Actually it is most certainly the case because writeable /etc is kept on /var, so /var must be available before system can transition from initrd to the real root. You likely need to rebuild initrd after changing /etc/fstab.

There was recently exactly the same question, you may want to check this topic.

I searched the forum but did not find the topic until now.
Your answer and that topic were super useful.

This is the way how to do it:

mkfs.btrfs /dev/sdb1 -f
mount /dev/sdb1 /mnt/
btrfs su create /mnt/@
vim /etc/fstab
transactional-update initrd
btrfs subvolume snapshot -r /var ~/backup
btrfs send ~/backup | btrfs receive /mnt
btrfs subvolume snapshot /mnt/backup /mnt/@/var
btrfs subvolume delete /mnt/backup ~/backup

The important thing in this is to change the /etc/fstab and rebuild initrd before the snapshot. Because this will generate new snapshot/overlay with the changes and you want to have it on new disk.
If you do it the other way it will not boot with /sysroot/etc mount error.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.