0

I made a bash script that was working in Ubuntu mate but now it won't work in Manjaro. It fails on this method:

#!/bin/bash

dev_block="/dev/sdb"

createPartitions(){
    
        echo "Creating Partitions on "$dev_block"..."
        sfdisk $dev_block -uS <<-EOF
        start=63, size=409600, type=c, bootable
        start=411648, type=af
        EOF
    }

createPartitions

I get this output...

Creating Partitions on /dev/sdb...
Checking that no-one is using this disk right now ... OK

Disk /dev/sdb: 28.84 GiB, 30966546432 bytes, 60481536 sectors
Disk model: USB FLASH DRIVE 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: EB88C926-F304-6D45-82C8-0BAC5E73A2CB

Old situation:

Device      Start      End  Sectors  Size Type
/dev/sdb1    2048   411585   409538  200M EFI System
/dev/sdb2  413633 60481502 60067870 28.6G Apple HFS/HFS+

>>> Created a new GPT disklabel (GUID: 0EBA642D-3CB5-8841-A150-D18AC387D65F).
/dev/sdb1: Failed to add #1 partition: Invalid argument
Leaving.

I also tried moving the EOF back so there is no tab before it.

createPartitions(){

    echo "Creating Partitions on "$dev_block"..."
    sfdisk $dev_block -uS <<-EOF
    start=63, size=409600, type=c, bootable
    start=411648, type=af
EOF
}

I checked and there is no tab or whitespace AFTER the closing EOF. But also in Ubuntu I didn't have to move that closing EOF back.

How do I debug this? Maybe sfdisk behaves differently in Arch?

Cheers.

1 Answer 1

0

I found the answer... while I was testing the code in Manjaro I had commented out this necessary method that deletes the partitions and filesystems on the drive before each run of the sfdisk command:

wipeFilesystems(){

echo "Wiping filesystems on "$dev_block"..."
sfdisk --delete $dev_block
wipefs --all $dev_block

}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.