All warnings have been removed. This is an experimental project. Please do not use on a disk containing important data unless you know what you're doing
npm i gnu-parted
Pass the disk path, size of disk and command you want to run to parted
.
See for how to get disk size and paths drivelist
import { parted } from 'gnu-parted'
(async () => {
const diskPath = "DISK_PATH" // e.g. /dev/sda or /dev/disks/disk1
const diskSize = 100000 // size in bytes of disk
// print partition table
await parted(diskPath, diskSize, 'print')
// create gpt partition table:
await parted(diskPath, diskSize, "mklabel gpt")
// create new primary fat32 partition, 512MiB:
await parted(diskPath, diskSize, "mkpart fat32 1MiB 512MiB")
})();
Note this does not create the actual file system. It just edits the partition table. You can create a file system with mkfs.