diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-02-20 23:08:44 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-02-20 23:08:44 +0100 |
commit | 1e085cdf67d0162de75e7e511bd011f48e6604c6 (patch) | |
tree | 4164cd84c50913d57ade374e25fdba22a2397c15 | |
parent | 19d735e1611c7d465a1e4ba3bb1d0aa968a0d7cb (diff) |
don't populate root partition B
This is not needed and just wastes time. A future update tool will simply drop the new set of executables on it, switch the kernel to it and reboot. A future init may then switch back to the other partition if errors are detected.
-rw-r--r-- | src/main.rs | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 28cabb6..c6e2300 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,7 +146,7 @@ fn partition( write_mbr(file, &buf["kernel.img"], &buf["cmdline.txt"])?; write_root(&mut root_partition_a, &arch, &crates, &git, &init)?; - write_root(&mut root_partition_b, &arch, &crates, &git, &init)?; + write_empty_root(&mut root_partition_b)?; Ok(()) } @@ -515,6 +515,81 @@ fn write_root( Ok(()) } +fn write_empty_root(partition: &mut StreamSlice<File>) -> anyhow::Result<()> { + let mut tmp_file = tempfile::NamedTempFile::new()?; + io::copy(partition, &mut tmp_file)?; + + let tree = SqsTreeProcessor::new(tmp_file.path())?; + + let bin_inode = tree.add(SqsSourceFile { + path: PathBuf::from("/bin"), + content: SqsSource { + data: SqsSourceData::Dir(Box::new(Vec::new().into_iter())), + uid: 0, + gid: 0, + mode: 0o755, + modified: 0, + xattrs: HashMap::new(), + flags: 0, + }, + })?; + + let dev_inode = tree.add(SqsSourceFile { + path: PathBuf::from("/dev"), + content: SqsSource { + data: SqsSourceData::Dir(Box::new(Vec::new().into_iter())), + uid: 0, + gid: 0, + mode: 0o755, + modified: 0, + xattrs: HashMap::new(), + flags: 0, + }, + })?; + + let boot_inode = tree.add(SqsSourceFile { + path: PathBuf::from("/boot"), + content: SqsSource { + data: SqsSourceData::Dir(Box::new(Vec::new().into_iter())), + uid: 0, + gid: 0, + mode: 0o755, + modified: 0, + xattrs: HashMap::new(), + flags: 0, + }, + })?; + + tree.add(SqsSourceFile { + path: PathBuf::from("/"), + content: SqsSource { + data: SqsSourceData::Dir(Box::new( + vec![ + (OsString::from("bin"), bin_inode), + (OsString::from("dev"), dev_inode), + (OsString::from("boot"), boot_inode), + ] + .into_iter(), + )), + uid: 0, + gid: 0, + mode: 0o755, + modified: 0, + xattrs: HashMap::new(), + flags: 0, + }, + })?; + + tree.finish()?; + + tmp_file.rewind()?; + partition.rewind()?; + io::copy(&mut tmp_file, partition)?; + + println!("Root filesystem B created successfully"); + Ok(()) +} + fn overwrite_device( file: &mut File, overwrite: String, |