You are not logged in.
I'm currently trying to make a script for personal use to partition my 500GB nvme ssd as follows using fdisk:
/dev/nvme0n1p1 2048 206847 204800 100M EFI System
/dev/nvme0n1p2 206848 976773134 976566287 465.7G Linux filesystem
I keep the swap partition in another hdd with Windows 10 on it:
/dev/sda4 1108310016 1125087231 16777216 8G Linux swap
However, I'm not sure how I can automate the simulation of option entry that fdisk requires and the assignment of disk space.
I'm new to bash scripting so any help would be appreciated. I've looked online but don't find a simple solution to this.
Last edited by Itzak (2021-03-15 22:05:53)
Offline
I'd suggest not using fdisk for this purpose as it's designed for human interaction. Use the scripting functionality of sfdisk instead.
Offline
Thanks for the reply. I've looked up sfdisk but wasn't able to get much information on how to use it in a script. Can you point me on the right direction to look?
Offline
man sfdisk
contains most of its secrets.
Last edited by hcjl (2021-03-15 18:07:02)
Offline
sgdisk ftw:
# sgdisk -n 1:2048:206847 -t 1:ef00 -n 2:206848:976773134 -t 2:8300 /dev/nvme0n1
# sgdisk -n 4:1108310016:1125087231 -t 4:8200 /dev/sda
EDIT: mixed up swap & Linux partition codes. Oops.
Last edited by Head_on_a_Stick (2021-03-15 18:31:35)
Para todos todo, para nosotros nada
Offline
I think sgdisk will do the trick but can you tell me if this tool is available in the arch ISO since I want to use the script to reinstall my system.
If I understood correctly the man page, I don't need to specify the partition table type since it automatically makes it GPT, right? So, with the commands you provided me would be more than enough to partition the disk.
Also, can you explain me what's the difference between all these tools. I know now that sfdisk is the script version of fdisk, but what about sgdisk, cfdisk, cgdisk, gdisk or parted. Is one better than the others?
Last edited by Itzak (2021-03-15 21:05:19)
Offline
They are all closely related, I will try and explain as best as I understand...
fdisk - originally created to work with only msdos partition tables.
gdisk - originally created to work with only gpt partition tables.
However, they have both been updated over the years to work with both msdos and GPT tables so there is now no real difference except the front-end.
c{f,g}disk - versions of the above that use ncurses as the interface instead of just std{in,out}.
s{f,g}disk - versions of the above that are designed to be scriptable.
parted - a utility from different authors that has the same basic functionality.
This is just my understanding, it might all be incorrect
Waiting for another poster to point out my mistakes...
Offline
That was actually a very clear explanation, thank you. Do you know if the sgdisk utility is available in the default Arch ISO, I want to use the function as part of a script to reinstall my system.
When using sgdisk I don't need to specify the partition table type since it automatically makes it GPT, right?
Offline
sgdisk is part of the gdisk package which is included on the ISO.
When using sgdisk I don't need to specify the partition table type since it automatically makes it GPT, right?
No idea. Read the man page.
Offline
I'll read it. Thanks for the help!
Offline