Skip to content

Commit

Permalink
truncate shit
Browse files Browse the repository at this point in the history
  • Loading branch information
korewaChino committed Sep 24, 2023
1 parent f162966 commit 18f28b2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
25 changes: 24 additions & 1 deletion src/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ pub trait ImageCreator {
self.instpkgs()?;
// self.dracut()?;
self.rootpw()?;
self.postinst_script()?;
self.genfstab()?;
self.postinst_script()?;

// self.squashfs()?;
// self.liveos()?;
Expand Down Expand Up @@ -371,6 +371,29 @@ pub trait ImageCreator {
std::fs::remove_file(dest)?;
// debug!("Unmounting /dev, /proc, /sys");
unmount_chroot(rootname)?;
match cfg.format {
OutputFormat::Disk => {
// Post-process disk image
let image = format!("{}.raw", cfg.out);
// get actual file size by bytes using -du
let size = cmd_lib::run_fun!(du --block-size=1 $image | cut -f1)?;
let size = size.parse::<i64>()? + 1;
// let's truncate the disk image to the actual size
info!(?size, "Truncating disk image");
cmd_lib::run_cmd!(
truncate -s $size $image;
)?;
}
_ => {}
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/katsudon-arm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ packages:

disk:
bootloader: true
root_format: btrfs
root_format: ext4
disk_size: 8G

sys:
Expand Down
2 changes: 1 addition & 1 deletion tests/katsudon-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ sys:

script:
init: init.sh
postinst: postinst.sh
postinst: postinst-live.sh
34 changes: 34 additions & 0 deletions tests/postinst-live.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash -x
echo postinst
systemctl disable systemd-networkd-wait-online systemd-networkd systemd-networkd.socket
systemctl disable chronyd
# systemctl disable polkit
# Add polkitd user manually, weird hack because preinstall script doesn't run
cat << EOF > /usr/lib/sysusers.d/extras.conf
# This is a really weird hack
#Type Name ID Argument
g polkitd 114
u polkitd 114:114 "User for polkitd" - -
g rpc 32
u rpc 32:32 "Rpcbind Daemon" - -
EOF

echo max_parallel_downloads=20 >> /etc/dnf/dnf.conf
echo defaultyes=True >> /etc/dnf/dnf.conf

systemd-sysusers
# dnf -y remove dracut-config-generic

# dracut -vvv --force --regenerate-all -N

rm -f /etc/machine-id
touch /etc/machine-id

rm -f /var/lib/rpm/__db*

echo "Fixing SELinux labels"

setfiles -v -F -e /proc -e /sys -e /dev -e /bin /etc/selinux/targeted/contexts/files/file_contexts /
setfiles -v -F -e /proc -e /sys -e /dev -e /etc/selinux/targeted/contexts/files/file_contexts.bin /bin

0 comments on commit 18f28b2

Please sign in to comment.