Skip to content

Commit

Permalink
Bugfix/gpt reflash (#2266)
Browse files Browse the repository at this point in the history
* debug entry

* update magic numbers

* remove dbg

* fix hostname

* fix reinstall logic
  • Loading branch information
dr-bonez authored May 11, 2023
1 parent 068b861 commit c7d8210
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 2 additions & 0 deletions backend/src/bin/embassy-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
.await
.is_err()
{
embassy::hostname::sync_hostname(&embassy::hostname::Hostname("embassy".into())).await?;

let ctx = SetupContext::init(cfg_path).await?;

let server = WebServer::setup(([0, 0, 0, 0], 80).into(), ctx.clone()).await?;
Expand Down
19 changes: 9 additions & 10 deletions backend/src/os_install/gpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result<OsPartitionIn
let efi = {
let disk = disk.clone();
tokio::task::spawn_blocking(move || {
let use_efi = Path::new("/sys/firmware/efi").exists();
let mut device = Box::new(
std::fs::File::options()
.read(true)
Expand Down Expand Up @@ -46,26 +47,24 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result<OsPartitionIn
.map(|(idx, x)| (idx + 1, x))
{
if let Some(entry) = gpt.partitions().get(&(idx as u32)) {
if entry.first_lba >= 33556480 {
if idx < 3 {
guid_part = Some(entry.clone())
if part_info.guid.is_some() {
if entry.first_lba < if use_efi { 33759266 } else { 33570850 } {
return Err(Error::new(
eyre!("Not enough space before embassy data"),
crate::ErrorKind::InvalidRequest,
));
}
guid_part = Some(entry.clone());
break;
}
if part_info.guid.is_some() {
return Err(Error::new(
eyre!("Not enough space before embassy data"),
crate::ErrorKind::InvalidRequest,
));
}
}
}
(gpt, guid_part)
};

gpt.update_partitions(Default::default())?;

let efi = if Path::new("/sys/firmware/efi").exists() {
let efi = if use_efi {
gpt.add_partition("efi", 100 * 1024 * 1024, gpt::partition_types::EFI, 0, None)?;
true
} else {
Expand Down
18 changes: 7 additions & 11 deletions backend/src/os_install/mbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result<OsPartitionIn
.map(|(idx, x)| (idx + 1, x))
{
if let Some(entry) = mbr.get_mut(idx) {
if entry.starting_lba >= 33556480 {
if idx < 3 {
guid_part =
Some(std::mem::replace(entry, MBRPartitionEntry::empty()))
}
break;
}
if part_info.guid.is_some() {
return Err(Error::new(
eyre!("Not enough space before embassy data"),
crate::ErrorKind::InvalidRequest,
));
if entry.starting_lba < 33556480 {
return Err(Error::new(
eyre!("Not enough space before embassy data"),
crate::ErrorKind::InvalidRequest,
));
}
guid_part = Some(std::mem::replace(entry, MBRPartitionEntry::empty()));
}
*entry = MBRPartitionEntry::empty();
}
Expand Down
2 changes: 2 additions & 0 deletions backend/src/os_install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ pub async fn execute(
.invoke(crate::ErrorKind::OpenSsh)
.await?;

tokio::fs::write(current.join("etc/hostname"), "embassy\n").await?;

Command::new("chroot")
.arg(&current)
.arg("ln")
Expand Down
2 changes: 2 additions & 0 deletions build/raspberrypi/init_resize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ main () {
return 1
fi

echo embassy > /etc/hostname

ln -sf /usr/lib/embassy/scripts/fake-apt /usr/local/bin/apt-get

return 0
Expand Down

0 comments on commit c7d8210

Please sign in to comment.