Re: btrfs with multiple subvolumes in one partition

2022-12-12 Diskussionsfäden Christoph Pleger
Hello,

> > > when setting up btrfs with setup-storage,
> > > is it possible to configure multiple subvolumes
> > > in one partition, like I tried to configure
> > > with
> > 
> > > disk_config btrfs fstabkey:uuid
> > > btrfs single / disk1.3 subvol=@root
> > > btrfs single /var disk1.3 subvol=@root/var
> > > btrfs single /usr disk1.3 subvol=@root/usr
> > I think this is related to https://bugs.debian.org/964761
> > The output of format.log would help for the bug report.
> 
> The bug can be solved with the attached patch.

There is another bug in setup-storage that strikes with almost the same
configuration as above, but when using for example raid1 instead of
single. In that case, mkfs.btrfs is called several times on the same
raid devices, so that previously created subvolumes get lost. This is
because, in contrast to single device btrfs filesystems, setup-storage
does not check for raid if the highest level filesystem already exists.
This can be solved by the attached patch.

I discovered that surprisingly it can happen that, though the output of
setup-storage says that for example /dev/sdb3 is going to be mounted on
/mnt and that /dev/sdb3 is going to be unmounted, in reality /dev/sda3
is mounted, but /dev/sdb3 is tried to be unmounted, what of course
fails. That is why I also changed from unmounting the device to
unmounting the mountpoint.

Regards
  Christoph



Index: fai-5.10.3/lib/setup-storage/Commands.pm
===
--- fai-5.10.3.orig/lib/setup-storage/Commands.pm	2022-12-08 13:52:35.0 +0100
+++ fai-5.10.3/lib/setup-storage/Commands.pm	2022-12-12 14:06:26.532431415 +0100
@@ -384,7 +384,12 @@
 	$mkfs_done{join(" ", @devs)} = '1';
   }
 } else {
-  $btrfs_tool = "mkfs.btrfs -d raid$raidlevel $createopts ".join(" ",@devs);
+  if (exists $mkfs_done{join(" ", sort @devs)}) {
+	$btrfs_tool = "true";
+  } else {
+  $btrfs_tool = "mkfs.btrfs -d raid$raidlevel $createopts ".join(" ", sort @devs);
+  $mkfs_done{join(" ", sort @devs)} = '1';
+  }
 }
 
 # nothing more to do if we need to proserve this volume. No mkfs, no subvolume
@@ -404,7 +409,7 @@
"btrfs_created_$initial_subvolume");
 
 # unmounting the device itself
-::push_command("umount $devs[0]",
+::push_command("umount /mnt",
"btrfs_created_$initial_subvolume",
"");
 }


signature.asc
Description: This is a digitally signed message part


Re: btrfs with multiple subvolumes in one partition

2022-12-08 Diskussionsfäden Christoph Pleger
Hello,

>> when setting up btrfs with setup-storage,
>> is it possible to configure multiple subvolumes
>> in one partition, like I tried to configure
>> with
> 
> > disk_config btrfs fstabkey:uuid
> > btrfs single / disk1.3 subvol=@root
> > btrfs single /var disk1.3 subvol=@root/var
> > btrfs single /usr disk1.3 subvol=@root/usr
> I think this is related to https://bugs.debian.org/964761
> The output of format.log would help for the bug report.

The bug can be solved with the attached patch.

Regards
  Christoph
--- fai-5.10.3.orig/lib/setup-storage/Commands.pm
+++ fai-5.10.3/lib/setup-storage/Commands.pm
@@ -349,7 +349,7 @@ sub build_btrfs_commands {
 next unless ($config eq "BTRFS");
 
 #create BTRFS RAIDs
-foreach my $id (keys %{ $FAI::configs{$config}{volumes} }) {
+foreach my $id (::numsort(keys %{ $FAI::configs{$config}{volumes} })) {
 #reference to current btrfs volume
 my $vol = (\%FAI::configs)->{$config}->{volumes}->{$id};
 


signature.asc
Description: This is a digitally signed message part


Re: btrfs with multiple subvolumes in one partition

2022-12-07 Diskussionsfäden Christoph Pleger
Hello,

> I believe that it is a better solution to let setup-storage create
> btrfs subvolumes in the same order as they occur in the config file
> (leaving the responsibility to define a correct order to the user).
> Unfortunately, I do not know how to do that.


It seems to me that the problem already occurs in the parser. At least,
when setup-storage succeeds with my config file, @root is the first
listed btrfs subvolume in the %FAI::configs part of my log file, while
one of the other two is listed first when setup-storage fails.
Surprisingly, the numbering of the subvolumes is correct in every run
of setup-storage; @root has 0, @root/var has 1 und @root/usr has 2. But
somehow the order in which the subvolumes are handled by the parser
does not follow the numbering order. Does anyone know why this is the
case?

Regards
  Christoph


signature.asc
Description: This is a digitally signed message part


Re: [SUSPECTED SPAM] Re: btrfs with multiple subvolumes in one partition

2022-12-07 Diskussionsfäden Christoph Pleger
Hello,

> > The log in short: It is a really a race condition; setup-storage tries
> > to create @root/usr before @root exists. And like described in the
> > link, sometimes the order is correct.
> 
> You can use a "mountdisks"-hook and manually create all subvolumes 
> yourself. This way, you gain complete control over your btrfs setup.

I believe that it is a better solution to let setup-storage create
btrfs subvolumes in the same order as they occur in the config file
(leaving the responsibility to define a correct order to the user).
Unfortunately, I do not know how to do that.

Regards
  Christoph 


signature.asc
Description: This is a digitally signed message part


Re: btrfs with multiple subvolumes in one partition

2022-12-06 Diskussionsfäden Robert Markula

Am 06.12.22 um 15:48 schrieb Christoph Pleger:

The log in short: It is a really a race condition; setup-storage tries
to create @root/usr before @root exists. And like described in the
link, sometimes the order is correct.


You can use a "mountdisks"-hook and manually create all subvolumes 
yourself. This way, you gain complete control over your btrfs setup.


Robert


Re: btrfs with multiple subvolumes in one partition

2022-12-06 Diskussionsfäden Christoph Pleger
Hello,

> > > > > 
> > when setting up btrfs with setup-storage, is it possible to
> configure
> > multiple subvolumes in one partition, like I tried to configure
> with
> 
> > disk_config btrfs fstabkey:uuid
> > btrfs single / disk1.3 subvol=@root
> > btrfs single /var disk1.3 subvol=@root/var
> > btrfs single /usr disk1.3 subvol=@root/usr
> I think this is related to https://bugs.debian.org/964761
> The output of format.log would help for the bug report.

I guess that you mean the debug output of setup-storage. I attached
that.

The log in short: It is a really a race condition; setup-storage tries
to create @root/usr before @root exists. And like described in the
link, sometimes the order is correct.

Regards
  Christoph
disklist: sda
Starting setup-storage 2.3
Using config file: aspects.cfg
Input was:
disk_config disk1 disklabel:gpt bootable:1 fstabkey:uuid
primary /boot/efi 512 vfat umask=0077
primary swap 4096 swap sw
primary - 65536- - -

disk_config btrfs fstabkey:uuid
btrfs single / disk1.3 subvol=@root
btrfs single /var disk1.3 subvol=@root/var
btrfs single /usr disk1.3 subvol=@root/usr

disk_config tmpfs
tmpfs /tmp RAM:25% defaults
(CMD) parted -s /dev/sda unit TiB print 1> /tmp/sH5Y_Bu5i3 2> /tmp/5ZJKpPciQC
Executing: parted -s /dev/sda unit TiB print
(STDOUT) Model: ATA WDC WD2500AAKX-0 (scsi)
(STDOUT) Disk /dev/sda: 0.23TiB
(STDOUT) Sector size (logical/physical): 512B/512B
(STDOUT) Partition Table: gpt
(STDOUT) Disk Flags: 
(STDOUT) 
(STDOUT) Number  StartEnd  Size File system  Name Flags
(STDOUT)  1  0.00TiB  0.00TiB  0.00TiB   primary  boot, esp
(STDOUT)  2  0.00TiB  0.00TiB  0.00TiB   primary  swap
(STDOUT)  3  0.00TiB  0.23TiB  0.22TiB  btrfsprimary
(STDOUT) 
(CMD) parted -s /dev/sda unit B print free 1> /tmp/JXWHkB6oiD 2> /tmp/HoiKTawqBr
Executing: parted -s /dev/sda unit B print free
(STDOUT) Model: ATA WDC WD2500AAKX-0 (scsi)
(STDOUT) Disk /dev/sda: 250059350016B
(STDOUT) Sector size (logical/physical): 512B/512B
(STDOUT) Partition Table: gpt
(STDOUT) Disk Flags: 
(STDOUT) 
(STDOUT) Number  StartEndSize   File system  Name Flags
(STDOUT) 17408B   1048575B   1031168B   Free Space
(STDOUT)  1  1048576B 537919487B 536870912B  primary  boot, esp
(STDOUT)  2  537919488B   4832886783B4294967296B primary  swap
(STDOUT)  3  4832886784B  250059333119B  245226446336B  btrfsprimary
(STDOUT) 
(CMD) parted -s /dev/sda unit chs print free 1> /tmp/i8RLXYq9HE 2> /tmp/2V0fN3Ia4N
Executing: parted -s /dev/sda unit chs print free
(STDOUT) Model: ATA WDC WD2500AAKX-0 (scsi)
(STDOUT) Disk /dev/sda: 957641,128,1
(STDOUT) Sector size (logical/physical): 512B/512B
(STDOUT) BIOS cylinder,head,sector geometry: 957641,255,2.  Each cylinder is 261kB.
(STDOUT) Partition Table: gpt
(STDOUT) Disk Flags: 
(STDOUT) 
(STDOUT) Number  Start   End   File system  Name Flags
(STDOUT) 0,17,0  4,3,1 Free Space
(STDOUT)  1  4,4,0   2060,11,1  primary  boot, esp
(STDOUT)  2  2060,12,0   18508,75,1 primary  swap
(STDOUT)  3  18508,76,0  957641,112,0  btrfsprimary
(STDOUT) 
Current disk layout in %current_config
$VAR1 = {
  '/dev/sda' => {
  'sector_size' => '512',
  'end_byte' => '250059350015',
  'partitions' => {
'1' => {
 'filesystem' => '',
 'is_extended' => 0,
 'flags' => 'boot,esp',
 'end_byte' => '537919487',
 'begin_byte' => '1048576',
 'count_byte' => '536870912'
   },
'2' => {
 'count_byte' => '4294967296',
 'begin_byte' => '537919488',
 'end_byte' => '4832886783',
 'flags' => 'swap',
 'is_extended' => 0,
 'filesystem' => ''
   },
'3' => {
 'filesystem' => 'btrfs',
 'is_extended' => 0,
 'flags' => '',
 

Re: btrfs with multiple subvolumes in one partition

2022-12-06 Diskussionsfäden Thomas Lange
> On Tue, 06 Dec 2022 14:50:18 +0100, Christoph Pleger 
>  said:

> Hello,
> when setting up btrfs with setup-storage, is it possible to configure
> multiple subvolumes in one partition, like I tried to configure with

> disk_config btrfs fstabkey:uuid
> btrfs single / disk1.3 subvol=@root
> btrfs single /var disk1.3 subvol=@root/var
> btrfs single /usr disk1.3 subvol=@root/usr
I think this is related to https://bugs.debian.org/964761
The output of format.log would help for the bug report.

I do not know if the btrfs implementation in setup-storage is intended
to support this.
-- 
regards Thomas