@@ -49,6 +49,7 @@ typedef enum MountPointFlags {
4949} MountPointFlags ;
5050
5151typedef struct Mount {
52+ bool for_initrd ;
5253 char * what ;
5354 char * where ;
5455 char * fstype ;
@@ -102,7 +103,13 @@ static void mount_array_free(Mount *mounts, size_t n) {
102103 free (mounts );
103104}
104105
105- static int mount_array_add_internal (char * in_what , char * in_where , const char * in_fstype , const char * in_options ) {
106+ static int mount_array_add_internal (
107+ bool for_initrd ,
108+ char * in_what ,
109+ char * in_where ,
110+ const char * in_fstype ,
111+ const char * in_options ) {
112+
106113 _cleanup_free_ char * what = NULL , * where = NULL , * fstype = NULL , * options = NULL ;
107114 int r ;
108115
@@ -135,6 +142,7 @@ static int mount_array_add_internal(char *in_what, char *in_where, const char *i
135142 return - ENOMEM ;
136143
137144 arg_mounts [arg_n_mounts ++ ] = (Mount ) {
145+ .for_initrd = for_initrd ,
138146 .what = TAKE_PTR (what ),
139147 .where = TAKE_PTR (where ),
140148 .fstype = TAKE_PTR (fstype ),
@@ -144,7 +152,7 @@ static int mount_array_add_internal(char *in_what, char *in_where, const char *i
144152 return 0 ;
145153}
146154
147- static int mount_array_add (const char * str ) {
155+ static int mount_array_add (bool for_initrd , const char * str ) {
148156 _cleanup_free_ char * what = NULL , * where = NULL , * fstype = NULL , * options = NULL ;
149157 int r ;
150158
@@ -159,10 +167,10 @@ static int mount_array_add(const char *str) {
159167 if (!isempty (str ))
160168 return - EINVAL ;
161169
162- return mount_array_add_internal (TAKE_PTR (what ), TAKE_PTR (where ), fstype , options );
170+ return mount_array_add_internal (for_initrd , TAKE_PTR (what ), TAKE_PTR (where ), fstype , options );
163171}
164172
165- static int mount_array_add_swap (const char * str ) {
173+ static int mount_array_add_swap (bool for_initrd , const char * str ) {
166174 _cleanup_free_ char * what = NULL , * options = NULL ;
167175 int r ;
168176
@@ -177,7 +185,7 @@ static int mount_array_add_swap(const char *str) {
177185 if (!isempty (str ))
178186 return - EINVAL ;
179187
180- return mount_array_add_internal (TAKE_PTR (what ), NULL , "swap" , options );
188+ return mount_array_add_internal (for_initrd , TAKE_PTR (what ), NULL , "swap" , options );
181189}
182190
183191static int write_options (FILE * f , const char * options ) {
@@ -1282,14 +1290,17 @@ static int add_mounts_from_cmdline(void) {
12821290 /* Handle each entries found in cmdline as a fstab entry. */
12831291
12841292 FOREACH_ARRAY (m , arg_mounts , arg_n_mounts ) {
1293+ if (m -> for_initrd && !in_initrd ())
1294+ continue ;
1295+
12851296 r = parse_fstab_one (
12861297 "/proc/cmdline" ,
12871298 m -> what ,
12881299 m -> where ,
12891300 m -> fstype ,
12901301 m -> options ,
12911302 /* passno = */ 0 ,
1292- /* prefix_sysroot = */ false ,
1303+ /* prefix_sysroot = */ ! m -> for_initrd && in_initrd () ,
12931304 /* use_swap_enabled = */ false);
12941305 if (r < 0 && ret >= 0 )
12951306 ret = r ;
@@ -1437,21 +1448,21 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
14371448 else
14381449 arg_verity = r ;
14391450
1440- } else if (streq (key , "systemd.mount-extra" )) {
1451+ } else if (STR_IN_SET (key , "systemd.mount-extra" , "rd. systemd.mount-extra" )) {
14411452
14421453 if (proc_cmdline_value_missing (key , value ))
14431454 return 0 ;
14441455
1445- r = mount_array_add (value );
1456+ r = mount_array_add (startswith ( key , "rd." ), value );
14461457 if (r < 0 )
14471458 log_warning ("Failed to parse systemd.mount-extra= option, ignoring: %s" , value );
14481459
1449- } else if (streq (key , "systemd.swap-extra" )) {
1460+ } else if (STR_IN_SET (key , "systemd.swap-extra" , "rd. systemd.swap-extra" )) {
14501461
14511462 if (proc_cmdline_value_missing (key , value ))
14521463 return 0 ;
14531464
1454- r = mount_array_add_swap (value );
1465+ r = mount_array_add_swap (startswith ( key , "rd." ), value );
14551466 if (r < 0 )
14561467 log_warning ("Failed to parse systemd.swap-extra= option, ignoring: %s" , value );
14571468 }
0 commit comments