Hello,
On Oct 17 14:32 Carlos E. R. wrote (excerpt):
It would be nice if there were a script or something
to create all those volumes, used during installation,
so that the admin could recreate them easily.
There is something like that but only to create a single
subvolume and currently its usefulness is limited on SLE12
and Leap 42.1 (perhaps it gets better on Tumbleweed):
/usr/sbin/mksubvolume (it belongs to the snapper RPM)
See "man mksubvolume".
What is currently missing is that mksubvolume creates
parent directories as needed:
---------------------------------------------------------
# mksubvolume /var/mystuff/mysubvol
failure (parent of target does not exist)
---------------------------------------------------------
In this case a manual "mkdir /var/mystuff/" is needed:
---------------------------------------------------------
# mkdir /var/mystuff
# mksubvolume /var/mystuff/mysubvol
---------------------------------------------------------
What is currently also missing is that mksubvolume
can correctly remove such a subvolume because
only something like
"btrfs subvolume delete /var/mystuff/mysubvol"
is insufficient and it does not work this way:
---------------------------------------------------------------
# btrfs subvolume delete /var/mystuff/mysubvol
Delete subvolume (no-commit): '/var/mystuff/mysubvol'
ERROR: cannot delete '/var/mystuff/mysubvol': Invalid argument
---------------------------------------------------------------
It is more complicated to delete such a subvolume, cf:
-------------------------------------------------------------------
# btrfs subvolume list -a / | grep mystuff
ID 306 gen 5933 top level 257 path /@/var/mystuff/mysubvol
-------------------------------------------------------------------
I leave it to the reader to find out how to delete
such a subvolume (hint: inspect my script below ;-)
But if only the subvolume is deleted it leads to
"interesting effects" during the next reboot:
You will find yourself in systemd's emergency mode
because the /var/mystuff/mysubvol entry in /etc/fstab
is still there but that one cannot be mounted (because
the subvolume is deleted). Solution is to manually remove
the /var/mystuff/mysubvol entry from /etc/fstab.
Caution:
What results totally wrongly created subvolumes for
the SLE12 default btrfs subvolume structure is:
--------------------------------------------------------------------------------
# btrfs subvolume create /var/mystuff/mysubvol2
Create subvolume '/var/mystuff/mysubvol2'
# btrfs subvolume list -a / | grep mystuff
ID 307 gen 5945 top level 259 path @/.snapshots/1/snapshot/var/mystuff/mysubvol2
--------------------------------------------------------------------------------
It is created under @/.snapshots/1/snapshot/ which is plain wrong.
Better delete that subvolume right now:
----------------------------------------------------------
# btrfs subvolume delete /var/mystuff/mysubvol2
Delete subvolume (no-commit): '/var/mystuff/mysubvol2'
----------------------------------------------------------
FYI:
Mainly for documentation here my selfmade script that I used
on SLE12 before I learned that /usr/sbin/mksubvolume exits.
This script shows how complicate it is to cerate a subvolume
in compliance with the SLE12 default btrfs subvolume structure
(long lines may get shown wrapped via e-mail):
-------------------------------------------------------------------------
#!/bin/bash
set -u -e -o pipefail
# the code below fails if there is a leading slash:
mysubvol=${1#/}
# find out what subvolume on what device node is mounted at '/':
output=( $(findmnt -nrv -t btrfs -o TARGET,SOURCE,FSROOT | grep '^/ ' ) )
# TARGET is '/' (by grep)
# SOURCE is the device node that is mounted at the target '/':
device=${output[1]}
# FSROOT is the subvolume that is mounted at the target '/':
fsroot=${output[2]}
# if a '/@/.snapshots/...' subvolume is mounted at the target '/'
# we assume the SLE12 btrfs default structure is used:
if [[ $fsroot == "/@/.snapshots/"* ]] ; then
# mount btrfs at its root subvolume:
btrfsroot=$( mktemp -d /tmp/btrfsroot.XXXXXXXXXX )
mount -t btrfs -o subvolid=0 $device $btrfsroot
# create subvolume under /@/:
mkdir -p $btrfsroot/@/$( dirname $mysubvol )
btrfs subvolume create $btrfsroot/@/$mysubvol
# btrfs at its root subvolume is no longer needed:
umount $btrfsroot
rmdir $btrfsroot
# mount subvolume:
output=( $( btrfs subvolume list -a / | grep "/@/$mysubvol" ) )
id=${output[1]}
mkdir -p /$mysubvol
mount -t btrfs -o subvolid=$id $device /$mysubvol
# make entry in /etc/fstab:
if ! grep -q "subvol=@/$mysubvol" /etc/fstab ; then
uuid=$( for l in /dev/disk/by-uuid/* ; do readlink -e $l | grep -q $device
&& basename $l ; done )
echo "UUID=$uuid /$mysubvol btrfs subvol=@/$mysubvol 0 0" >>/etc/fstab
fi
else
echo "Unexpected exit: No '/@/.snapshots/...' subvolume mounted at '/'."
exit 99
fi
-------------------------------------------------------------------------
This script is only my personal hack that I used for SLE12.
It seemed to work for me on SLE12 but I have not at all tested
it thoroughly and I never used it on Leap or Tumbleweed.
Kind Regards
Johannes Meixner
--
SUSE LINUX GmbH - GF: Felix Imendoerffer, Jane Smithard,
Graham Norton - HRB 21284 (AG Nuernberg)
--
To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org
To contact the owner, e-mail: opensuse-factory+owner@opensuse.org