Script that formats a drive in a very specific way

Multi tool use
Multi tool use


Script that formats a drive in a very specific way



I want to format a drive using a script in Ubuntu.



The required specs are:



Partition table: Master Boot Record



Partition Type: Linux



File System: Ext2



Screenshot of the desired result





My current problems:


sudo parted mklablel msdos



Doesn't change the Partition type to "Linux"


sudo mkfs.ext2



Doesn't work without existing filesystem



All help is appreciated! Thanks.





I think this question will be better received over on askubuntu.com since it's not programming related and is a little off topic here at SO.
– JNevill
Jul 2 at 12:55





Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask.
– jww
Jul 3 at 11:56




1 Answer
1



Sure.


echo -ne 'onwn' | fdisk /dev/sdc # not needed on clean disc
echo -ne 'onnnnntn83nwn' | fdisk /dev/sdc
partprobe
mkfs.ext2 /dev/sdc1



The first line is there only to write clean dos partition table, so fdisk will not ask warning questions on the next run.
Then we create new clean dos parition table with on, create one partition that takes the whole disc with nnnn, change partition type to linux with tn83n and write that to disc with wn.
Then we need to rescan /dev/sdc to discover newly created partitions (fdisk should do that, but on some systems it fails).
Then we format /dev/sdc1 to ext2.
Script not tested. Use at your own risk.


on


nnnn


tn83n


wn





Thank you for your reply! Quick question: If i change "/dev/sdc" and "/dev/sdc1" to "/dev/sdd" and "/dev/sdd1" it changes the device, right?
– jdnkr
Jul 2 at 13:03





Yes, see here for example. So don't make a typo ; )
– Kamil Cuk
Jul 2 at 13:34







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

1597,fGWlw,U19Z q cgQkCFZ,o7o7
UOiXhICGs0UgLLNxmvRW7Anp,d,P7ry3BhuXTDI4GnT8fkJrhqP 4jWp

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications