Skip to content

Commit db95987

Browse files
committed
Tweak disk settings
1 parent 9c79b18 commit db95987

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/images/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ OCI Registry → containers/image → OCI Layout → umoci → rootfs/ → mkfs.
4141
- Works without root when creating filesystem in a regular file (not block device)
4242
- `-d` flag copies directory contents into filesystem
4343

44-
**Alternative tried:** go-diskfs pure Go ext4, got too tricky but could revisit this
44+
**Options:**
45+
- `-b 4096` - 4KB blocks (standard, matches VM page size)
46+
- `-O ^has_journal` - No journal (disks mounted read-only in VMs, saves ~32MB)
47+
- Minimum 10MB size covers ext4 metadata (~5MB for superblock, inodes, bitmaps)
48+
49+
**Alternative tried:** go-diskfs pure Go ext4 - has bugs
4550

4651
**Tradeoff:** Shell command vs pure Go, but mkfs.ext4 is universally available and robust
4752

lib/images/disk.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ func convertToExt4(rootfsDir, diskPath string) (int64, error) {
1515
return 0, fmt.Errorf("calculate dir size: %w", err)
1616
}
1717

18-
// Add 20% overhead for filesystem metadata, minimum 1GB
18+
// Add 20% overhead for filesystem metadata, minimum 10MB
1919
diskSizeBytes := sizeBytes + (sizeBytes / 5)
20-
const minSize = 1024 * 1024 * 1024 // 1GB
20+
const minSize = 10 * 1024 * 1024 // 10MB
2121
if diskSizeBytes < minSize {
2222
diskSizeBytes = minSize
2323
}
@@ -39,8 +39,11 @@ func convertToExt4(rootfsDir, diskPath string) (int64, error) {
3939
f.Close()
4040

4141
// Format as ext4 with rootfs contents using mkfs.ext4
42-
// This works without root when creating filesystem in a regular file
43-
cmd := exec.Command("mkfs.ext4", "-d", rootfsDir, "-F", diskPath)
42+
// -b 4096: 4KB blocks (standard, matches VM page size)
43+
// -O ^has_journal: Disable journal (not needed for read-only VM mounts)
44+
// -d: Copy directory contents into filesystem
45+
// -F: Force creation (file not block device)
46+
cmd := exec.Command("mkfs.ext4", "-b", "4096", "-O", "^has_journal", "-d", rootfsDir, "-F", diskPath)
4447
output, err := cmd.CombinedOutput()
4548
if err != nil {
4649
return 0, fmt.Errorf("mkfs.ext4 failed: %w, output: %s", err, output)

0 commit comments

Comments
 (0)