When I installed the system, I created partitions and generated fstab. Here are its contents:
# /dev/sda3 UUID=abe3b587-3a5f-47d6-8f66-2df758e70665 / ext4 rw,relatime,data=ordered 0 1 # /dev/sda1 UUID=D2C4-B10A /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2 # /dev/sda2 UUID=23349153-86c4-495a-a78d-1034090f3cb1 none swap defaults 0 0 Using device-mapper, I create a virtual device that translates all requests to a real device. For example, let the real device be / dev / sda3, and the virtual / dev / mapper / root_part.
I create it in the udev demon rule. Here are the rules themselves:
KERNEL=="sd*",SUBSYSTEM=="block",ACTION=="add",ENV{ID_FS_UUID}=="abe3b587-3a5f-47d6-8f66-2df758e70665",RUN+="/lib/udev/create_virtual.sh %k" KERNEL=="sd*",SUBSYSTEM=="block",ACTION=="remove",ENV{ID_FS_UUID}=="abe3b587-3a5f-47d6-8f66-2df758e70665",RUN+="/lib/udev/remove_virtual.sh" In turn, scripts are executed there:
create_virtual.sh
#!/bin/bash echo 0 32359055360 basic_target /dev/$1 0 | dmsetup create root_part exit 0 remove_virtual.sh
#!/bin/bash dmsetup remove root_part exit 0 basic_target is a self-written kernel module, copied (with some changes) from this article.
My solution was to fix the fstab so that not the root partition itself was mounted, but its corresponding virtual partition. For this, I needed the udev daemon to create this virtual device before fstab is processed. But then there were problems. Indicating the priority of the rule is too high, it did not work, because, as I later understood, the device receives a UUID in one of the following rules. Gradually reducing the priority, I achieved that this error ceased to occur, but a new one appeared - the device to which I am going to do the virtual one went into the "busy" state. At the same time, similar tricks with a flash drive did not produce this error: a virtual device was created and mounted in accordance with the added line in fstab. From which I concluded that / dev / sda3 was already mounted.
Not having achieved my goal, I decided to simply remove the line with the root partition from fstab and mount the device directly from the create_virtual.sh script. But deleting lines from fstab led to nothing. I even completely cleared the fstab - the system continues to boot normally.
I have a question, how to make the system use other devices when mounting partitions?
In addition, if there are more correct methods for solving my problem, then I would really like to hear them.