@@ -849,11 +849,19 @@ pub(crate) fn fixup_etc_fstab(root: &Dir) -> Result<()> {
849849 }
850850 // If options already contains `ro`, nothing to do
851851 if options. split ( ',' ) . any ( |s| s == "ro" ) {
852+ println ! ( "/etc/fstab `/` already contains `ro`, nothing to do" ) ;
852853 return Ok ( false ) ;
853854 }
854855
855856 writeln ! ( w, "# {}" , crate :: generator:: BOOTC_EDITED_STAMP ) ?;
856857
858+ // If options == `defaults`, comment the whole line
859+ if options == "defaults" {
860+ writeln ! ( w, "#{line}" ) ?;
861+ println ! ( "Updated /etc/fstab to comment `/` line" ) ;
862+ return Ok ( true ) ;
863+ }
864+
857865 // SAFETY: we unpacked the options before.
858866 // This adds `ro` to the option list
859867 assert ! ( !options. is_empty( ) ) ; // Split wouldn't have turned this up if it was empty
@@ -871,6 +879,7 @@ pub(crate) fn fixup_etc_fstab(root: &Dir) -> Result<()> {
871879 }
872880 // And add the trailing newline
873881 writeln ! ( w) ?;
882+ println ! ( "Updated /etc/fstab to add `ro` for `/`" ) ;
874883 Ok ( true )
875884 }
876885
@@ -886,7 +895,6 @@ pub(crate) fn fixup_etc_fstab(root: &Dir) -> Result<()> {
886895 } )
887896 . context ( "Replacing /etc/fstab" ) ?;
888897
889- println ! ( "Updated /etc/fstab to add `ro` for `/`" ) ;
890898 Ok ( ( ) )
891899}
892900
@@ -934,7 +942,7 @@ mod tests {
934942 }
935943
936944 #[ test]
937- fn test_fixup_etc_fstab_default ( ) -> Result < ( ) > {
945+ fn test_fixup_etc_fstab_no_root ( ) -> Result < ( ) > {
938946 let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
939947 let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n " ;
940948 tempdir. create_dir_all ( "etc" ) ?;
@@ -945,7 +953,7 @@ mod tests {
945953 }
946954
947955 #[ test]
948- fn test_fixup_etc_fstab_multi ( ) -> Result < ( ) > {
956+ fn test_fixup_etc_fstab_no_root_multi ( ) -> Result < ( ) > {
949957 let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
950958 let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
951959 UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
@@ -957,7 +965,7 @@ UUID=6907-17CA /boot/efi vfat umask=0077,shortname=win
957965 }
958966
959967 #[ test]
960- fn test_fixup_etc_fstab_ro ( ) -> Result < ( ) > {
968+ fn test_fixup_etc_fstab_root_ro ( ) -> Result < ( ) > {
961969 let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
962970 let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
963971 UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs ro 0 0\n \
@@ -970,15 +978,33 @@ UUID=6907-17CA /boot/efi vfat umask=0077,shortname=win
970978 }
971979
972980 #[ test]
973- fn test_fixup_etc_fstab_rw ( ) -> Result < ( ) > {
981+ fn test_fixup_etc_fstab_root_defaults ( ) -> Result < ( ) > {
974982 let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
975983 // This case uses `defaults`
976984 let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
977985 UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults 0 0\n \
978986 UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
979987 let modified = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
980988 # Updated by bootc-fstab-edit.service\n \
981- UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults,ro 0 0\n \
989+ #UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults 0 0\n \
990+ UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
991+ tempdir. create_dir_all ( "etc" ) ?;
992+ tempdir. atomic_write ( "etc/fstab" , default) ?;
993+ fixup_etc_fstab ( & tempdir) . unwrap ( ) ;
994+ assert_eq ! ( tempdir. read_to_string( "etc/fstab" ) ?, modified) ;
995+ Ok ( ( ) )
996+ }
997+
998+ #[ test]
999+ fn test_fixup_etc_fstab_root_non_defaults ( ) -> Result < ( ) > {
1000+ let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
1001+ // This case uses `defaults`
1002+ let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
1003+ UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults,x-systemd.device-timeout=0 0 0\n \
1004+ UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
1005+ let modified = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
1006+ # Updated by bootc-fstab-edit.service\n \
1007+ UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults,x-systemd.device-timeout=0,ro 0 0\n \
9821008 UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
9831009 tempdir. create_dir_all ( "etc" ) ?;
9841010 tempdir. atomic_write ( "etc/fstab" , default) ?;
0 commit comments