mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
Bugfix/gpt reflash (#2266)
* debug entry * update magic numbers * remove dbg * fix hostname * fix reinstall logic
This commit is contained in:
@@ -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?;
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(¤t)
|
.arg(¤t)
|
||||||
.arg("ln")
|
.arg("ln")
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user