diff mbox series

[PATCHv3] wic-imager-direct.py: use fstab update also for root device

Message ID 20230207124456.6091-1-f_l_k@t-online.de
State New
Headers show
Series [PATCHv3] wic-imager-direct.py: use fstab update also for root device | expand

Commit Message

Markus Volk Feb. 7, 2023, 12:44 p.m. UTC
wic imager is able to add entries for the partitions to fstab. This patch also
creates an entry for the root device, which was previously ignored. The root
device entry can now optionally be uuid or label based.

The stock fstab file provided by base-files.bb already contains an entry for the
root device. To avoid a duplicate entry in fstab, this  '/dev/root' line is removed
during the fstab update.

The default /dev/root entry in base-files adds the value '1' for dump and passno. Add an
argument to set dump, which formerly has been hardcoded to '0'. Like this we can provide the
same settings if using the fstab_update.

The result looks something like this:

proc /proc proc defaults 0 0
devpts /dev/pts devpts mode=0620,ptmxmode=0666,gid=5 0 0
tmpfs /run tmpfs mode=0755,nodev,nosuid,strictatime 0 0
tmpfs /var/volatile tmpfs defaults 0 0

UUID=055A-69B5 /boot vfat defaults 0 0
UUID=0eb2df23-3638-4bbf-b045-9a425cb45954 / ext4 defaults 1 1

If neither '--on-disk' nor '--use-label' nor '--use-uuid' are set in the wks file, wic falls
back to '/dev/sda' as the default device entry, which may or may not be valid.
Avoid starting to guess if we don't know anything and just skip the partition in that case,
except for the root partition where we add back '/dev/root' as a reasonable default,
because we can rely on it in the yocto/oe environment.

The result is now like this:

proc                 /proc                proc       defaults              0  0
devpts               /dev/pts             devpts     mode=0620,ptmxmode=0666,gid=5      0  0
tmpfs                /run                 tmpfs      mode=0755,nodev,nosuid,strictatime 0  0
tmpfs                /var/volatile        tmpfs      defaults              0  0

/dev/root	/	ext4	defaults	1	1

Signed-off-by: Markus Volk <f_l_k@t-online.de>
---
 scripts/lib/wic/ksparser.py              |  3 ++-
 scripts/lib/wic/partition.py             |  1 +
 scripts/lib/wic/plugins/imager/direct.py | 20 +++++++++++++++++---
 3 files changed, 20 insertions(+), 4 deletions(-)

Comments

Luca Ceresoli Feb. 8, 2023, 12:49 p.m. UTC | #1
Hello Markus,

On Tue,  7 Feb 2023 13:44:56 +0100
"Markus Volk" <f_l_k@t-online.de> wrote:

> wic imager is able to add entries for the partitions to fstab. This patch also
> creates an entry for the root device, which was previously ignored. The root
> device entry can now optionally be uuid or label based.
> 
> The stock fstab file provided by base-files.bb already contains an entry for the
> root device. To avoid a duplicate entry in fstab, this  '/dev/root' line is removed
> during the fstab update.
> 
> The default /dev/root entry in base-files adds the value '1' for dump and passno. Add an
> argument to set dump, which formerly has been hardcoded to '0'. Like this we can provide the
> same settings if using the fstab_update.
> 
> The result looks something like this:
> 
> proc /proc proc defaults 0 0
> devpts /dev/pts devpts mode=0620,ptmxmode=0666,gid=5 0 0
> tmpfs /run tmpfs mode=0755,nodev,nosuid,strictatime 0 0
> tmpfs /var/volatile tmpfs defaults 0 0
> 
> UUID=055A-69B5 /boot vfat defaults 0 0
> UUID=0eb2df23-3638-4bbf-b045-9a425cb45954 / ext4 defaults 1 1
> 
> If neither '--on-disk' nor '--use-label' nor '--use-uuid' are set in the wks file, wic falls
> back to '/dev/sda' as the default device entry, which may or may not be valid.
> Avoid starting to guess if we don't know anything and just skip the partition in that case,
> except for the root partition where we add back '/dev/root' as a reasonable default,
> because we can rely on it in the yocto/oe environment.
> 
> The result is now like this:
> 
> proc                 /proc                proc       defaults              0  0
> devpts               /dev/pts             devpts     mode=0620,ptmxmode=0666,gid=5      0  0
> tmpfs                /run                 tmpfs      mode=0755,nodev,nosuid,strictatime 0  0
> tmpfs                /var/volatile        tmpfs      defaults              0  0
> 
> /dev/root	/	ext4	defaults	1	1
> 
> Signed-off-by: Markus Volk <f_l_k@t-online.de>

This patch is failing on the autobuilders:

  AssertionError: False is not true : /dev/sda2 on / type ext4 (rw,relatime)

and also this, even though I'm not sure how it relates to your changes:

  AssertionError: None is not true : diff: can't stat '/data/overlay-etc/lower/lower-layer-test.txt': No such file or directory

Logs:

https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/4780/steps/15/logs/stdio
https://autobuilder.yoctoproject.org/typhoon/#/builders/80/builds/4725/steps/14/logs/stdio
Markus Volk Feb. 8, 2023, 5:38 p.m. UTC | #2
Hello Luca,

unfortunately I still have a qemu issue if running this test but I had 
a look at the files it creates and the entry for the root partition in 
/etc/fstab looks like this:

 /dev/root            /                    auto       ro              1 
 0

Reasonable because it wants to check for read-only filesystem

if using the fstab-update this would be replaced by the default:

/dev/root	/	ext4	defaults	1	1

This is rw and i guess thats what makes the test fail.

Following this theory it should be a valid fix to just not use the 
fstab update here ?

diff --git a/meta/lib/oeqa/selftest/cases/overlayfs.py 
b/meta/lib/oeqa/selftest/cases/overlayfs.py
index dfd9f1486d..9b1538a16b 100644
--- a/meta/lib/oeqa/selftest/cases/overlayfs.py
+++ b/meta/lib/oeqa/selftest/cases/overlayfs.py
@@ -438,6 +438,7 @@ OVERLAYFS_ETC_DEVICE = "/dev/sda3"
         configLower = """
 OVERLAYFS_ETC_EXPOSE_LOWER = "1"
 IMAGE_INSTALL:append = " overlayfs-user"
+WIC_CREATE_EXTRA_ARGS = "--no-fstab-update"
 """
         testFile = "lower-layer-test.txt"



Am Mi, 8. Feb 2023 um 13:49:50 +0100 schrieb Luca Ceresoli via 
lists.openembedded.org 
<luca.ceresoli=bootlin.com@lists.openembedded.org>:
> Hello Markus,
> 
> On Tue,  7 Feb 2023 13:44:56 +0100
> "Markus Volk" <f_l_k@t-online.de <mailto:f_l_k@t-online.de>> wrote:
> 
>>  wic imager is able to add entries for the partitions to fstab. This 
>> patch also
>>  creates an entry for the root device, which was previously ignored. 
>> The root
>>  device entry can now optionally be uuid or label based.
>> 
>>  The stock fstab file provided by base-files.bb already contains an 
>> entry for the
>>  root device. To avoid a duplicate entry in fstab, this  '/dev/root' 
>> line is removed
>>  during the fstab update.
>> 
>>  The default /dev/root entry in base-files adds the value '1' for 
>> dump and passno. Add an
>>  argument to set dump, which formerly has been hardcoded to '0'. 
>> Like this we can provide the
>>  same settings if using the fstab_update.
>> 
>>  The result looks something like this:
>> 
>>  proc /proc proc defaults 0 0
>>  devpts /dev/pts devpts mode=0620,ptmxmode=0666,gid=5 0 0
>>  tmpfs /run tmpfs mode=0755,nodev,nosuid,strictatime 0 0
>>  tmpfs /var/volatile tmpfs defaults 0 0
>> 
>>  UUID=055A-69B5 /boot vfat defaults 0 0
>>  UUID=0eb2df23-3638-4bbf-b045-9a425cb45954 / ext4 defaults 1 1
>> 
>>  If neither '--on-disk' nor '--use-label' nor '--use-uuid' are set 
>> in the wks file, wic falls
>>  back to '/dev/sda' as the default device entry, which may or may 
>> not be valid.
>>  Avoid starting to guess if we don't know anything and just skip the 
>> partition in that case,
>>  except for the root partition where we add back '/dev/root' as a 
>> reasonable default,
>>  because we can rely on it in the yocto/oe environment.
>> 
>>  The result is now like this:
>> 
>>  proc                 /proc                proc       defaults       
>>        0  0
>>  devpts               /dev/pts             devpts     
>> mode=0620,ptmxmode=0666,gid=5      0  0
>>  tmpfs                /run                 tmpfs      
>> mode=0755,nodev,nosuid,strictatime 0  0
>>  tmpfs                /var/volatile        tmpfs      defaults       
>>        0  0
>> 
>>  /dev/root	/	ext4	defaults	1	1
>> 
>>  Signed-off-by: Markus Volk <f_l_k@t-online.de 
>> <mailto:f_l_k@t-online.de>>
> 
> This patch is failing on the autobuilders:
> 
>   AssertionError: False is not true : /dev/sda2 on / type ext4 
> (rw,relatime)
> 
> and also this, even though I'm not sure how it relates to your 
> changes:
> 
>   AssertionError: None is not true : diff: can't stat 
> '/data/overlay-etc/lower/lower-layer-test.txt': No such file or 
> directory
> 
> Logs:
> 
> <https://autobuilder.yoctoproject.org/typhoon/#/builders/79/builds/4780/steps/15/logs/stdio>
> <https://autobuilder.yoctoproject.org/typhoon/#/builders/80/builds/4725/steps/14/logs/stdio>
> 
> --
> Luca Ceresoli, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com <https://bootlin.com/>
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#176905): 
> <https://lists.openembedded.org/g/openembedded-core/message/176905>
> Mute This Topic: <https://lists.openembedded.org/mt/96806003/3618223>
> Group Owner: openembedded-core+owner@lists.openembedded.org 
> <mailto:openembedded-core+owner@lists.openembedded.org>
> Unsubscribe: 
> <https://lists.openembedded.org/g/openembedded-core/unsub> 
> [f_l_k@t-online.de <mailto:f_l_k@t-online.de>]
> -=-=-=-=-=-=-=-=-=-=-=-
>
diff mbox series

Patch

diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index d1e546b12d..7cf53b3b4a 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -155,6 +155,7 @@  class KickStart():
         part.add_argument('--change-directory')
         part.add_argument("--extra-space", type=sizetype("M"))
         part.add_argument('--fsoptions', dest='fsopts')
+        part.add_argument('--fsdump', dest='fsdump')
         part.add_argument('--fspassno', dest='fspassno')
         part.add_argument('--fstype', default='vfat',
                           choices=('ext2', 'ext3', 'ext4', 'btrfs',
@@ -164,7 +165,7 @@  class KickStart():
         part.add_argument('--label')
         part.add_argument('--use-label', action='store_true')
         part.add_argument('--no-table', action='store_true')
-        part.add_argument('--ondisk', '--ondrive', dest='disk', default='sda')
+        part.add_argument('--ondisk', '--ondrive', dest='disk')
         part.add_argument("--overhead-factor", type=overheadtype)
         part.add_argument('--part-name')
         part.add_argument('--part-type')
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 2a916e077c..113713cf16 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -33,6 +33,7 @@  class Partition():
         self.include_path = args.include_path
         self.change_directory = args.change_directory
         self.fsopts = args.fsopts
+        self.fsdump = args.fsdump
         self.fspassno = args.fspassno
         self.fstype = args.fstype
         self.label = args.label
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index dfaa901567..ff626b8109 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -114,12 +114,20 @@  class DirectPlugin(ImagerPlugin):
         with open(fstab_path) as fstab:
             fstab_lines = fstab.readlines()
 
+        for line in fstab_lines:
+            if '/dev/root' in line:
+                fstab_lines.remove(line)
+
         updated = False
         for part in self.parts:
             if not part.realnum or not part.mountpoint \
-               or part.mountpoint == "/" or not (part.mountpoint.startswith('/') or part.mountpoint == "swap"):
+               or not (part.mountpoint.startswith('/') or part.mountpoint == "swap"):
                 continue
 
+            if part.mountpoint == "/":
+                part.fsdump = part.fsdump if part.fsdump else "1"
+                part.fspassno = part.fspassno if part.fspassno else "1"
+
             if part.use_uuid:
                 if part.fsuuid:
                     # FAT UUID is different from others
@@ -132,15 +140,21 @@  class DirectPlugin(ImagerPlugin):
                     device_name = "PARTUUID=%s" % part.uuid
             elif part.use_label:
                 device_name = "LABEL=%s" % part.label
-            else:
+            elif part.disk:
                 # mmc device partitions are named mmcblk0p1, mmcblk0p2..
                 prefix = 'p' if  part.disk.startswith('mmcblk') else ''
                 device_name = "/dev/%s%s%d" % (part.disk, prefix, part.realnum)
+            elif part.mountpoint == "/":
+                # use /dev/root as fallback device
+                device_name = "/dev/root"
+            else:
+                continue
 
             opts = part.fsopts if part.fsopts else "defaults"
+            dump = part.fsdump if part.fsdump else "0"
             passno = part.fspassno if part.fspassno else "0"
             line = "\t".join([device_name, part.mountpoint, part.fstype,
-                              opts, "0", passno]) + "\n"
+                              opts, dump, passno]) + "\n"
 
             fstab_lines.append(line)
             updated = True