Skip to contentSkip to conversation

wic: direct: Use stock fstab in partitions

RFC PATCH In review Daniel Gomez 3 participants 7 messages Aug 5, 2021 – Aug 6, 2021

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 wic: direct: Use stock fstab in partitions

Be able to get the stock fstab in partitions.

Functionality reverted at commit id:
ce682a73b7447652f898ce1d1d0416a456df5416

---

Hi,

I'm trying to get back the stock fstab file in a rootfs partition image (wic plugin) and I'd like to know what you think about it.

Functionality was included before commit-id ce682a73b7447652f898ce1d1d0416a456df5416 and removed afterwards. Would it be possible to add it again? What would be needed to re-add it?

Thanks in advance,
Daniel

Here the relevant information:

wks definition:
part /boot/bootloader --source qbootimg-pcbios --active --align 1024 --use-uuid --fsoptions defaults,ro
part /export --source rootfs --rootfs-dir=hockeycam-image --fstype=ext4 --label export --align 1024 --use-uuid --fsoptions defaults,ro --extra-space 400M part /media/rw --fstype=ext4 --label rwfs --align 1024 --use-uuid --size 200
part / --source rootfs --fstype=ext4 --label rootfs --align 1024 --use-uuid --fsoptions defaults,ro --extra-space 400M

bootloader --timeout=1 --append="ro rootfstype=ext4 qtec_mem.size=64" --source qbootimg-pcbios

/export/etc/fstab before:

# stock fstab - you probably want to override this with a machine specific one
/dev/root            /                    auto       ro              1  0
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
# uncomment this if your device has a SD/MMC/Transflash slot
#/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

/dev/sdb /mnt auto defaults 0 0

UUID=D339-7B77  /boot/bootloader        vfat    defaults,ro     0       0
UUID=31f46be1-d9fb-4081-bd53-2c2727e7854b       /export ext4    defaults,ro     0       0
UUID=d8e8f5d4-897e-48cd-9188-33598363f706       /media/rw       ext4    defaults        0       0

/export/etc/fstab after:

# stock fstab - you probably want to override this with a machine specific one
/dev/root            /                    auto       ro              1  0
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
# uncomment this if your device has a SD/MMC/Transflash slot
#/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

10.100.10.100:/mnt/rw /media/rw nfs defaults 0 0

 scripts/lib/wic/plugins/imager/direct.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +16 -4
index 7e1c1c03ab..1bb9d38524 100644
@@ -111,7 +111,15 @@ class DirectPlugin(ImagerPlugin):
 
         with open(fstab_path) as fstab:
             fstab_lines = fstab.readlines()
+            self.original_fstab = fstab_lines.copy()
 
+        if self._update_fstab(fstab_lines, self.parts):
+            with open(fstab_path, "w") as fstab:
+                fstab.writelines(fstab_lines)
+        else:
+            self.original_fstab = None
+
+    def _update_fstab(self, fstab_lines, parts):
         updated = False
         for part in self.parts:
             if not part.realnum or not part.mountpoint \
@@ -142,10 +150,7 @@ class DirectPlugin(ImagerPlugin):
             fstab_lines.append(line)
             updated = True
 
-        if updated:
-            self.updated_fstab_path = os.path.join(self.workdir, "fstab")
-            with open(self.updated_fstab_path, "w") as f:
-                f.writelines(fstab_lines)
+        return updated
 
     def _full_path(self, path, name, extention):
         """ Construct full file path to a file we generate. """
@@ -274,6 +279,13 @@ class DirectPlugin(ImagerPlugin):
             if os.path.isfile(path):
                 shutil.move(path, os.path.join(self.outdir, fname))
 
+
+        # Restore original fstab
+        if self.original_fstab:
+            fstab_path = self.rootfs_dir.get("ROOTFS_DIR") + "/etc/fstab"
+            with open(fstab_path, "w") as fstab:
+                fstab.writelines(self.original_fstab)
+
         # remove work directory
         shutil.rmtree(self.workdir, ignore_errors=True)
 

--
2.30.2

#1 lore raw
Quoted 8 lines · Daniel Gomez

Be able to get the stock fstab in partitions.

Functionality reverted at commit id:
ce682a73b7447652f898ce1d1d0416a456df5416

---

Quoted 9 lines

Hi,

I'm trying to get back the stock fstab file in a rootfs partition image (wic plugin) and I'd like to know what you think about it.

Functionality was included before commit-id ce682a73b7447652f898ce1d1d0416a456df5416 and removed afterwards. Would it be possible to add it again? What would be needed to re-add it?

The commit you mention above shouldn't have changed the output, it just used a different method to replace the fstab file. The question becomes why isn't the modified file being used in the way you're generating an image. I don't know wic well enough to know the answer to that though.

Cheers,

Richard

Quoted 99 lines

Thanks in advance,
Daniel

Here the relevant information:

wks definition:
part /boot/bootloader --source qbootimg-pcbios --active --align 1024 --use-uuid --fsoptions defaults,ro
part /export --source rootfs --rootfs-dir=hockeycam-image --fstype=ext4 --label export --align 1024 --use-uuid --fsoptions defaults,ro --extra-space 400M part /media/rw --fstype=ext4 --label rwfs --align 1024 --use-uuid --size 200
part / --source rootfs --fstype=ext4 --label rootfs --align 1024 --use-uuid --fsoptions defaults,ro --extra-space 400M

bootloader --timeout=1 --append="ro rootfstype=ext4 qtec_mem.size=64" --source qbootimg-pcbios

/export/etc/fstab before:

# stock fstab - you probably want to override this with a machine specific one
/dev/root            /                    auto       ro              1  0
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
# uncomment this if your device has a SD/MMC/Transflash slot
#/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

/dev/sdb /mnt auto defaults 0 0

UUID=D339-7B77  /boot/bootloader        vfat    defaults,ro     0       0
UUID=31f46be1-d9fb-4081-bd53-2c2727e7854b       /export ext4    defaults,ro     0       0
UUID=d8e8f5d4-897e-48cd-9188-33598363f706       /media/rw       ext4    defaults        0       0

/export/etc/fstab after:

# stock fstab - you probably want to override this with a machine specific one
/dev/root            /                    auto       ro              1  0
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
# uncomment this if your device has a SD/MMC/Transflash slot
#/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

10.100.10.100:/mnt/rw /media/rw nfs defaults 0 0

 scripts/lib/wic/plugins/imager/direct.py | 20 ++++++++++++++++----

 1 file changed, 16 insertions(+), 4 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +0 -0
index 7e1c1c03ab..1bb9d38524 100644
@@ -111,7 +111,15 @@ class DirectPlugin(ImagerPlugin):
 

         with open(fstab_path) as fstab:
             fstab_lines = fstab.readlines()

scripts/lib/wic/plugins/imager/direct.py +8 -0
+            self.original_fstab = fstab_lines.copy()
 
+        if self._update_fstab(fstab_lines, self.parts):
+            with open(fstab_path, "w") as fstab:
+                fstab.writelines(fstab_lines)
+        else:
+            self.original_fstab = None
+
+    def _update_fstab(self, fstab_lines, parts):

         updated = False
         for part in self.parts:
             if not part.realnum or not part.mountpoint \

scripts/lib/wic/plugins/imager/direct.py +0 -0
@@ -142,10 +150,7 @@ class DirectPlugin(ImagerPlugin):
              fstab_lines.append(line)

             updated = True

scripts/lib/wic/plugins/imager/direct.py +1 -4
-        if updated:
-            self.updated_fstab_path = os.path.join(self.workdir, "fstab")
-            with open(self.updated_fstab_path, "w") as f:
-                f.writelines(fstab_lines)
+        return updated

     def _full_path(self, path, name, extention):
         """ Construct full file path to a file we generate. """

scripts/lib/wic/plugins/imager/direct.py +0 -0
@@ -274,6 +279,13 @@ class DirectPlugin(ImagerPlugin):

             if os.path.isfile(path):
                 shutil.move(path, os.path.join(self.outdir, fname))

scripts/lib/wic/plugins/imager/direct.py +7 -0
+
+        # Restore original fstab
+        if self.original_fstab:
+            fstab_path = self.rootfs_dir.get("ROOTFS_DIR") + "/etc/fstab"
+            with open(fstab_path, "w") as fstab:
+                fstab.writelines(self.original_fstab)
+
         # remove work directory
         shutil.rmtree(self.workdir, ignore_errors=True)

--
2.30.2

#2 lore raw

RFC PATCH 1/1 wic: Add --use-stock-fstab option

When embeddding rootfs image (e.g. 'rootfs-dir') as a partition we might want to keep the stock fstab for that image. In such case, use this option to not update the fstab and use the stock one instead.

This option allows to specify which partitions get the updated fstab and which get the stock fstab.

Example:

    part /export --source rootfs --rootfs-dir=hockeycam-image
    --fstype=ext4 --label export --align 1024 --use-stock-fstab

    part / --source rootfs --fstype=ext4 --label rootfs --align 1024

---

The commit-id ce682a73b7447652f898ce1d1d0416a456df5416 reverted the functionality to restore the stock/original fstab file in a rootfs partition image (wic plugin).

Add back such functionality with an option to the user to select which fstab will be used for each partition by adding the --use-stock-fstab. In this case, the user will select whether or not the stock fstab will be updated or kept.

If you agree with the patch I'll adapt it to the master branch.

Daniel

 scripts/lib/wic/ksparser.py  | 1 +
 scripts/lib/wic/partition.py | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
scripts/lib/wic/ksparser.py +1 -0
index 452a160232..64933e0a5b 100644
@@ -184,6 +184,7 @@ class KickStart():
         part.add_argument('--use-uuid', action='store_true')
         part.add_argument('--uuid')
         part.add_argument('--fsuuid')
+        part.add_argument('--use-stock-fstab', action='store_true')
 
         bootloader = subparsers.add_parser('bootloader')
         bootloader.add_argument('--append')
scripts/lib/wic/partition.py +2 -1
index 85f9847047..c9e45773de 100644
@@ -54,6 +54,7 @@ class Partition():
         self.uuid = args.uuid
         self.fsuuid = args.fsuuid
         self.type = args.type
+        self.use_stock_fstab = args.use_stock_fstab
         self.updated_fstab_path = None
         self.has_fstab = False
         self.update_fstab_in_rootfs = False
@@ -286,7 +287,7 @@ class Partition():
             (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
         exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
 
-        if self.updated_fstab_path and self.has_fstab:
+        if self.updated_fstab_path and self.has_fstab and not self.use_stock_fstab:
             debugfs_script_path = os.path.join(cr_workdir, "debugfs_script")
             with open(debugfs_script_path, "w") as f:
                 f.write("cd etc\n")

--
2.30.2

#3 lore raw

Re: [OE-core][RFC][PATCH][dunfell] wic: Add --use-stock-fstab option

Quoted 20 lines · Daniel Gomez

When embeddding rootfs image (e.g. 'rootfs-dir') as a partition we might want to keep the stock fstab for that image. In such case, use this option to not update the fstab and use the stock one instead.

This option allows to specify which partitions get the updated fstab and which get the stock fstab.

Example:
    part /export --source rootfs --rootfs-dir=hockeycam-image --fstype=ext4 --label export --align 1024 --use-stock-fstab

    part / --source rootfs --fstype=ext4 --label rootfs --align 1024

---

The commit-id ce682a73b7447652f898ce1d1d0416a456df5416 reverted the functionality to restore the stock/original fstab file in a rootfs partition image (wic plugin).

Quoted 6 lines

Add back such functionality with an option to the user to select which fstab will be used for each partition by adding the --use-stock-fstab. In this case, the user will select whether or not the stock fstab will be updated or kept.

If you agree with the patch I'll adapt it to the master branch.

It seems reasonable to me. It would need to go to master first and ideally we'd add some kind of test to oe-selftest -r wic (see meta/lib/oeqa/selftest/cases/wic.py).

Cheers,

Richard

#4 lore raw

Re: [OE-core][RFC][PATCH][dunfell] wic: Add --use-stock-fstab option

In reply to Daniel Gomez
Quoted 67 lines · On Fri, 6 Aug 2021 11:23:37 +0200 Daniel Gomez <[email protected]> wrote:

When embeddding rootfs image (e.g. 'rootfs-dir') as a partition we might want to keep the stock fstab for that image. In such case, use this option to not update the fstab and use the stock one instead.

This option allows to specify which partitions get the updated fstab and which get the stock fstab.

Example:

    part /export --source rootfs --rootfs-dir=hockeycam-image
    --fstype=ext4 --label export --align 1024 --use-stock-fstab

    part / --source rootfs --fstype=ext4 --label rootfs --align 1024

---

The commit-id ce682a73b7447652f898ce1d1d0416a456df5416 reverted the functionality to restore the stock/original fstab file in a rootfs partition image (wic plugin).

Add back such functionality with an option to the user to select which fstab will be used for each partition by adding the --use-stock-fstab. In this case, the user will select whether or not the stock fstab will be updated or kept.

If you agree with the patch I'll adapt it to the master branch.

Daniel

 scripts/lib/wic/ksparser.py  | 1 +
 scripts/lib/wic/partition.py | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
scripts/lib/wic/ksparser.py +1 -0
index 452a160232..64933e0a5b 100644
@@ -184,6 +184,7 @@ class KickStart():
         part.add_argument('--use-uuid', action='store_true')
         part.add_argument('--uuid')
         part.add_argument('--fsuuid')
+        part.add_argument('--use-stock-fstab', action='store_true')
 
         bootloader = subparsers.add_parser('bootloader')
         bootloader.add_argument('--append')
scripts/lib/wic/partition.py +2 -2
index 85f9847047..c9e45773de 100644
@@ -54,6 +54,7 @@ class Partition():
         self.uuid = args.uuid
         self.fsuuid = args.fsuuid
         self.type = args.type
+        self.use_stock_fstab = args.use_stock_fstab
         self.updated_fstab_path = None
         self.has_fstab = False
         self.update_fstab_in_rootfs = False
@@ -286,7 +287,7 @@ class Partition():
             (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
         exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
 
-        if self.updated_fstab_path and self.has_fstab:
+        if self.updated_fstab_path and self.has_fstab and not self.use_stock_fstab:
             debugfs_script_path = os.path.join(cr_workdir, "debugfs_script")
             with open(debugfs_script_path, "w") as f:
                 f.write("cd etc\n")
--
Quoted 2 lines

2.30.2

You're only addressing ext2/3/4 partitions here. The patch needs to be extended to cover the msdos partition case and the update_fstab_in_rootfs case in the rootfs source plugin.

I also recommend changing the option in ksparser to '--no-fstab-update' to match the argument you can pass to wic itself. That way you can pass '--no-fstab-update' to wic to set the option for all partitions, or include it in the wks file to set the option per-partition.

Thanks,

Signature · 2 lines
Paul Barker
https://pbarker.dev/
#5 lore raw

Re: [OE-core][RFC][PATCH][dunfell] wic: Add --use-stock-fstab option

Quoted 78 lines · Paul Barker
Quoted 67 lines · On Fri, 6 Aug 2021 11:23:37 +0200 Daniel Gomez <[email protected]> wrote:

When embeddding rootfs image (e.g. 'rootfs-dir') as a partition we might want to keep the stock fstab for that image. In such case, use this option to not update the fstab and use the stock one instead.

This option allows to specify which partitions get the updated fstab and which get the stock fstab.

Example:

    part /export --source rootfs --rootfs-dir=hockeycam-image
    --fstype=ext4 --label export --align 1024 --use-stock-fstab

    part / --source rootfs --fstype=ext4 --label rootfs --align 1024

---

The commit-id ce682a73b7447652f898ce1d1d0416a456df5416 reverted the functionality to restore the stock/original fstab file in a rootfs partition image (wic plugin).

Add back such functionality with an option to the user to select which fstab will be used for each partition by adding the --use-stock-fstab. In this case, the user will select whether or not the stock fstab will be updated or kept.

If you agree with the patch I'll adapt it to the master branch.

Daniel

 scripts/lib/wic/ksparser.py  | 1 +
 scripts/lib/wic/partition.py | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
scripts/lib/wic/ksparser.py +1 -0
index 452a160232..64933e0a5b 100644
@@ -184,6 +184,7 @@ class KickStart():
         part.add_argument('--use-uuid', action='store_true')
         part.add_argument('--uuid')
         part.add_argument('--fsuuid')
+        part.add_argument('--use-stock-fstab', action='store_true')
 
         bootloader = subparsers.add_parser('bootloader')
         bootloader.add_argument('--append')
scripts/lib/wic/partition.py +2 -2
index 85f9847047..c9e45773de 100644
@@ -54,6 +54,7 @@ class Partition():
         self.uuid = args.uuid
         self.fsuuid = args.fsuuid
         self.type = args.type
+        self.use_stock_fstab = args.use_stock_fstab
         self.updated_fstab_path = None
         self.has_fstab = False
         self.update_fstab_in_rootfs = False
@@ -286,7 +287,7 @@ class Partition():
             (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
         exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
 
-        if self.updated_fstab_path and self.has_fstab:
+        if self.updated_fstab_path and self.has_fstab and not self.use_stock_fstab:
             debugfs_script_path = os.path.join(cr_workdir, "debugfs_script")
             with open(debugfs_script_path, "w") as f:
                 f.write("cd etc\n")
--
Quoted 2 lines

2.30.2

You're only addressing ext2/3/4 partitions here. The patch needs to be extended to cover the msdos partition case and the update_fstab_in_rootfs case in the rootfs source plugin.

Quoted 4 lines

I also recommend changing the option in ksparser to '--no-fstab-update' to match the argument you can pass to wic itself. That way you can pass '--no-fstab-update' to wic to set the option for all partitions, or include it in the wks file to set the option per-partition.

Thanks Richard and Paul for the suggestions and the missing tasks. I'll send a patch as soon as I have all prepared.

Daniel

Quoted 6 lines

Thanks,

--
Paul Barker
https://pbarker.dev/

#6 lore raw
In reply to Richard Purdie

Hi Richard,

Quoted 20 lines · Richard Purdie
Quoted 8 lines · Daniel Gomez

Be able to get the stock fstab in partitions.

Functionality reverted at commit id:
ce682a73b7447652f898ce1d1d0416a456df5416

---

Quoted 9 lines

Hi,

I'm trying to get back the stock fstab file in a rootfs partition image (wic plugin) and I'd like to know what you think about it.

Functionality was included before commit-id ce682a73b7447652f898ce1d1d0416a456df5416 and removed afterwards. Would it be possible to add it again? What would be needed to re-add it?

Quoted 4 lines

The commit you mention above shouldn't have changed the output, it just used a different method to replace the fstab file. The question becomes why isn't the modified file being used in the way you're generating an image. I don't know wic well enough to know the answer to that though.

Thanks for your comments. I did some debugging and the fstab in use for each partition will always be updated/replaced in the 'prepare_rootfs_ext' function (when 'update_fstab' in direct.py updates it):
http://git.openembedded.org/openembedded-core/tree/scripts/lib/wic/partition.py?h=dunfell#n289

To fix it, I made this patch for dunfell so it gets updated if the user wants.
https://lists.openembedded.org/g/openembedded-core/message/154537

The user now decides with --use-stock-fstab if the stock fstab is kept or replaced/updated.

As said in the other patch/message, I'll update it to master if you agree.

Thanks,
Daniel

Quoted 107 lines

Cheers,

Richard

Quoted 99 lines

Thanks in advance,
Daniel

Here the relevant information:

wks definition:
part /boot/bootloader --source qbootimg-pcbios --active --align 1024 --use-uuid --fsoptions defaults,ro
part /export --source rootfs --rootfs-dir=hockeycam-image --fstype=ext4 --label export --align 1024 --use-uuid --fsoptions defaults,ro --extra-space 400M part /media/rw --fstype=ext4 --label rwfs --align 1024 --use-uuid --size 200
part / --source rootfs --fstype=ext4 --label rootfs --align 1024 --use-uuid --fsoptions defaults,ro --extra-space 400M

bootloader --timeout=1 --append="ro rootfstype=ext4 qtec_mem.size=64" --source qbootimg-pcbios

/export/etc/fstab before:

# stock fstab - you probably want to override this with a machine specific one
/dev/root            /                    auto       ro              1  0
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
# uncomment this if your device has a SD/MMC/Transflash slot
#/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

/dev/sdb /mnt auto defaults 0 0

UUID=D339-7B77  /boot/bootloader        vfat    defaults,ro     0       0
UUID=31f46be1-d9fb-4081-bd53-2c2727e7854b       /export ext4    defaults,ro     0       0
UUID=d8e8f5d4-897e-48cd-9188-33598363f706       /media/rw       ext4    defaults        0       0

/export/etc/fstab after:

# stock fstab - you probably want to override this with a machine specific one
/dev/root            /                    auto       ro              1  0
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
# uncomment this if your device has a SD/MMC/Transflash slot
#/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

10.100.10.100:/mnt/rw /media/rw nfs defaults 0 0

 scripts/lib/wic/plugins/imager/direct.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +16 -5
index 7e1c1c03ab..1bb9d38524 100644
@@ -111,7 +111,15 @@ class DirectPlugin(ImagerPlugin):
 
         with open(fstab_path) as fstab:
             fstab_lines = fstab.readlines()
+            self.original_fstab = fstab_lines.copy()
 
+        if self._update_fstab(fstab_lines, self.parts):
+            with open(fstab_path, "w") as fstab:
+                fstab.writelines(fstab_lines)
+        else:
+            self.original_fstab = None
+
+    def _update_fstab(self, fstab_lines, parts):
         updated = False
         for part in self.parts:
             if not part.realnum or not part.mountpoint \
@@ -142,10 +150,7 @@ class DirectPlugin(ImagerPlugin):
             fstab_lines.append(line)
             updated = True
 
-        if updated:
-            self.updated_fstab_path = os.path.join(self.workdir, "fstab")
-            with open(self.updated_fstab_path, "w") as f:
-                f.writelines(fstab_lines)
+        return updated
 
     def _full_path(self, path, name, extention):
         """ Construct full file path to a file we generate. """
@@ -274,6 +279,13 @@ class DirectPlugin(ImagerPlugin):
             if os.path.isfile(path):
                 shutil.move(path, os.path.join(self.outdir, fname))
 
+
+        # Restore original fstab
+        if self.original_fstab:
+            fstab_path = self.rootfs_dir.get("ROOTFS_DIR") + "/etc/fstab"
+            with open(fstab_path, "w") as fstab:
+                fstab.writelines(self.original_fstab)
+
         # remove work directory
         shutil.rmtree(self.workdir, ignore_errors=True)
 
--

2.30.2