@@ -634,11 +634,9 @@ static int add_partition_root_rw(DissectedPartition *p) {
634634 int r ;
635635
636636 assert (p );
637+ assert (!in_initrd ());
637638
638- if (in_initrd ()) {
639- log_debug ("In initrd, not generating drop-in for systemd-remount-fs.service." );
640- return 0 ;
641- }
639+ /* Invoked on the main system (not initrd), to honour GPT flag 60 on the root fs (ro) */
642640
643641 if (arg_root_rw >= 0 ) {
644642 log_debug ("Parameter ro/rw specified on kernel command line, not generating drop-in for systemd-remount-fs.service." );
@@ -650,7 +648,9 @@ static int add_partition_root_rw(DissectedPartition *p) {
650648 return 0 ;
651649 }
652650
653- (void ) generator_enable_remount_fs_service (arg_dest );
651+ r = generator_enable_remount_fs_service (arg_dest );
652+ if (r < 0 )
653+ return r ;
654654
655655 path = strjoina (arg_dest , "/systemd-remount-fs.service.d/50-remount-rw.conf" );
656656
@@ -665,6 +665,33 @@ static int add_partition_root_rw(DissectedPartition *p) {
665665 return 0 ;
666666}
667667
668+ static int add_partition_root_growfs (DissectedPartition * p ) {
669+
670+ assert (p );
671+ assert (!in_initrd ());
672+
673+ /* Invoked on the main system (not initrd), to honour GPT flag 59 on the root fs (growfs) */
674+
675+ if (!p -> growfs ) {
676+ log_debug ("Root partition not marked for growing the file system in the GPT partition table, not generating drop-in for systemd-growfs-root.service." );
677+ return 0 ;
678+ }
679+
680+ return generator_hook_up_growfs (arg_dest , "/" , SPECIAL_LOCAL_FS_TARGET );
681+ }
682+
683+ static int add_partition_root_flags (DissectedPartition * p ) {
684+ int r = 0 ;
685+
686+ assert (p );
687+ assert (!in_initrd ());
688+
689+ RET_GATHER (r , add_partition_root_growfs (p ));
690+ RET_GATHER (r , add_partition_root_rw (p ));
691+
692+ return r ;
693+ }
694+
668695#if ENABLE_EFI
669696static int add_root_cryptsetup (void ) {
670697#if HAVE_LIBCRYPTSETUP
@@ -710,8 +737,9 @@ static int add_root_mount(void) {
710737 return r ;
711738 }
712739
713- /* Note that we do not need to enable systemd-remount-fs.service here. If
714- * /etc/fstab exists, systemd-fstab-generator will pull it in for us. */
740+ /* Note that we do not need to enable systemd-remount-fs.service here. If /etc/fstab exists,
741+ * systemd-fstab-generator will pull it in for us, and otherwise add_partition_root_flags() will do
742+ * it, after the initrd transition. */
715743
716744 r = partition_pick_mount_options (
717745 PARTITION_ROOT ,
@@ -795,6 +823,11 @@ static int enumerate_partitions(dev_t devnum) {
795823 _cleanup_free_ char * devname = NULL ;
796824 int r ;
797825
826+ assert (!in_initrd ());
827+
828+ /* Run on the final root fs (not in the initrd), to mount auxiliary partitions, and hook in rw
829+ * remount and growfs of the root partition */
830+
798831 r = block_get_whole_disk (devnum , & devnum );
799832 if (r < 0 )
800833 return log_debug_errno (r , "Failed to get whole block device for " DEVNUM_FORMAT_STR ": %m" ,
@@ -855,7 +888,7 @@ static int enumerate_partitions(dev_t devnum) {
855888 "var-tmp" , "/var/tmp" , "Temporary Data Partition" ));
856889
857890 if (m -> partitions [PARTITION_ROOT ].found )
858- RET_GATHER (r , add_partition_root_rw (m -> partitions + PARTITION_ROOT ));
891+ RET_GATHER (r , add_partition_root_flags (m -> partitions + PARTITION_ROOT ));
859892
860893 return r ;
861894}
0 commit comments