Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill a disk with an ext4 partition in a script

I tried to use parted for scripted partitionning like so :

parted -a optimal /dev/sda mklabel gpt mkpart primary ext4 1 -1

But it complains about -1 not being a recognized option. Still the same sub-command works in the parted prompt. So my question is how to use the same options in a script ?

like image 218
Nicolas Barbey Avatar asked Oct 16 '12 15:10

Nicolas Barbey


People also ask

How do I allocate a partition in ext4?

In the right-click menu of the Ubuntu partition, select the Resize/Move option. In the window that pops up, drag the partition shown at the top of that little window as far left as it can go. Now, drag the right of the partition as far right as it can go, filling up all the space in that little diagram.

What is MKFS ext4 command in Linux?

mkfs utility is used to create filesystem (ext2, ext3, ext4, etc) on your Linux system. You should specify the device name to mkfs on which the filesystem to be created. WARNING: Executing these commands will destroy all the data on your filesystem.

Can Windows read ext4?

Ext4 is the most common Linux file system and is not supported on Windows by default. However, using a third-party solution, you can read and access Ext4 on Windows 10, 8, or even 7.


2 Answers

Finally found a solution :

parted -s -a optimal /dev/sda mklabel gpt -- mkpart primary ext4 1 -1s

-- is very important for it to work here.

Note the use of ‘--’, to prevent the following ‘-1s’ last-sector indicator from being interpreted as an invalid command-line option.

like image 107
Nicolas Barbey Avatar answered Sep 23 '22 17:09

Nicolas Barbey


You can also use --script option. In this case you should put your script part in single quotes.

Example:

parted --script /dev/sda 'mkpart primary ext4 1 -1'   
like image 27
ᐅdevrimbaris Avatar answered Sep 23 '22 17:09

ᐅdevrimbaris