@@ -849,11 +849,19 @@ pub(crate) fn fixup_etc_fstab(root: &Dir) -> Result<()> {
849
849
}
850
850
// If options already contains `ro`, nothing to do
851
851
if options. split ( ',' ) . any ( |s| s == "ro" ) {
852
+ println ! ( "/etc/fstab `/` already contains `ro`, nothing to do" ) ;
852
853
return Ok ( false ) ;
853
854
}
854
855
855
856
writeln ! ( w, "# {}" , crate :: generator:: BOOTC_EDITED_STAMP ) ?;
856
857
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
+
857
865
// SAFETY: we unpacked the options before.
858
866
// This adds `ro` to the option list
859
867
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<()> {
871
879
}
872
880
// And add the trailing newline
873
881
writeln ! ( w) ?;
882
+ println ! ( "Updated /etc/fstab to add `ro` for `/`" ) ;
874
883
Ok ( true )
875
884
}
876
885
@@ -886,7 +895,6 @@ pub(crate) fn fixup_etc_fstab(root: &Dir) -> Result<()> {
886
895
} )
887
896
. context ( "Replacing /etc/fstab" ) ?;
888
897
889
- println ! ( "Updated /etc/fstab to add `ro` for `/`" ) ;
890
898
Ok ( ( ) )
891
899
}
892
900
@@ -934,7 +942,7 @@ mod tests {
934
942
}
935
943
936
944
#[ test]
937
- fn test_fixup_etc_fstab_default ( ) -> Result < ( ) > {
945
+ fn test_fixup_etc_fstab_no_root ( ) -> Result < ( ) > {
938
946
let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
939
947
let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n " ;
940
948
tempdir. create_dir_all ( "etc" ) ?;
@@ -945,7 +953,7 @@ mod tests {
945
953
}
946
954
947
955
#[ test]
948
- fn test_fixup_etc_fstab_multi ( ) -> Result < ( ) > {
956
+ fn test_fixup_etc_fstab_no_root_multi ( ) -> Result < ( ) > {
949
957
let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
950
958
let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
951
959
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
957
965
}
958
966
959
967
#[ test]
960
- fn test_fixup_etc_fstab_ro ( ) -> Result < ( ) > {
968
+ fn test_fixup_etc_fstab_root_ro ( ) -> Result < ( ) > {
961
969
let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
962
970
let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
963
971
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
970
978
}
971
979
972
980
#[ test]
973
- fn test_fixup_etc_fstab_rw ( ) -> Result < ( ) > {
981
+ fn test_fixup_etc_fstab_root_defaults ( ) -> Result < ( ) > {
974
982
let tempdir = cap_std_ext:: cap_tempfile:: tempdir ( cap_std:: ambient_authority ( ) ) ?;
975
983
// This case uses `defaults`
976
984
let default = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
977
985
UUID=1eef9f42-40e3-4bd8-ae20-e9f2325f8b52 / xfs defaults 0 0\n \
978
986
UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
979
987
let modified = "UUID=f7436547-20ac-43cb-aa2f-eac9632183f6 /boot auto ro 0 0\n \
980
988
# 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 \
982
1008
UUID=6907-17CA /boot/efi vfat umask=0077,shortname=winnt 0 2\n ";
983
1009
tempdir. create_dir_all ( "etc" ) ?;
984
1010
tempdir. atomic_write ( "etc/fstab" , default) ?;
0 commit comments