Bugfix/gpt reflash (#2266)

* debug entry

* update magic numbers

* remove dbg

* fix hostname

* fix reinstall logic
This commit is contained in:
Aiden McClelland
2023-05-11 14:16:19 -06:00
committed by GitHub
parent 068b861edc
commit c7d82102ed
5 changed files with 23 additions and 22 deletions

View File

@@ -55,6 +55,8 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<(), Error> {
.await .await
.is_err() .is_err()
{ {
embassy::hostname::sync_hostname(&embassy::hostname::Hostname("embassy".into())).await?;
let ctx = SetupContext::init(cfg_path).await?; let ctx = SetupContext::init(cfg_path).await?;
let server = WebServer::setup(([0, 0, 0, 0], 80).into(), ctx.clone()).await?; let server = WebServer::setup(([0, 0, 0, 0], 80).into(), ctx.clone()).await?;

View File

@@ -13,6 +13,7 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result<OsPartitionIn
let efi = { let efi = {
let disk = disk.clone(); let disk = disk.clone();
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
let use_efi = Path::new("/sys/firmware/efi").exists();
let mut device = Box::new( let mut device = Box::new(
std::fs::File::options() std::fs::File::options()
.read(true) .read(true)
@@ -46,18 +47,16 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result<OsPartitionIn
.map(|(idx, x)| (idx + 1, x)) .map(|(idx, x)| (idx + 1, x))
{ {
if let Some(entry) = gpt.partitions().get(&(idx as u32)) { if let Some(entry) = gpt.partitions().get(&(idx as u32)) {
if entry.first_lba >= 33556480 {
if idx < 3 {
guid_part = Some(entry.clone())
}
break;
}
if part_info.guid.is_some() { if part_info.guid.is_some() {
if entry.first_lba < if use_efi { 33759266 } else { 33570850 } {
return Err(Error::new( return Err(Error::new(
eyre!("Not enough space before embassy data"), eyre!("Not enough space before embassy data"),
crate::ErrorKind::InvalidRequest, crate::ErrorKind::InvalidRequest,
)); ));
} }
guid_part = Some(entry.clone());
break;
}
} }
} }
(gpt, guid_part) (gpt, guid_part)
@@ -65,7 +64,7 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result<OsPartitionIn
gpt.update_partitions(Default::default())?; 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)?; gpt.add_partition("efi", 100 * 1024 * 1024, gpt::partition_types::EFI, 0, None)?;
true true
} else { } else {

View File

@@ -27,19 +27,15 @@ pub async fn partition(disk: &DiskInfo, overwrite: bool) -> Result<OsPartitionIn
.map(|(idx, x)| (idx + 1, x)) .map(|(idx, x)| (idx + 1, x))
{ {
if let Some(entry) = mbr.get_mut(idx) { 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() { if part_info.guid.is_some() {
if entry.starting_lba < 33556480 {
return Err(Error::new( return Err(Error::new(
eyre!("Not enough space before embassy data"), eyre!("Not enough space before embassy data"),
crate::ErrorKind::InvalidRequest, crate::ErrorKind::InvalidRequest,
)); ));
} }
guid_part = Some(std::mem::replace(entry, MBRPartitionEntry::empty()));
}
*entry = MBRPartitionEntry::empty(); *entry = MBRPartitionEntry::empty();
} }
} }

View File

@@ -232,6 +232,8 @@ pub async fn execute(
.invoke(crate::ErrorKind::OpenSsh) .invoke(crate::ErrorKind::OpenSsh)
.await?; .await?;
tokio::fs::write(current.join("etc/hostname"), "embassy\n").await?;
Command::new("chroot") Command::new("chroot")
.arg(&current) .arg(&current)
.arg("ln") .arg("ln")

View File

@@ -104,6 +104,8 @@ main () {
return 1 return 1
fi fi
echo embassy > /etc/hostname
ln -sf /usr/lib/embassy/scripts/fake-apt /usr/local/bin/apt-get ln -sf /usr/lib/embassy/scripts/fake-apt /usr/local/bin/apt-get
return 0 return 0