2

I have a script which uses the following command to add a partition to /dev/sda

cat <<-EOF |fdisk /dev/sda                                                                                           
    n                                                                                                             


    w                                                                                                             
    EOF

I want to use parted instead of fdisk (fdisk is not compatible with my Linux). Can i use simply parted instead of fdisk in the above script or how can achieve this?

1 Answer 1

3

You can use the same script logic for parted, but parted has to be invoked via parted -s (don't run interactively). Wheter you can use the exact same commands in your HEREDOC is unknown to me as I don't use parted. Try a manual dry run, note the commands, and put them in the HEREDOC part of your script.

5
  • another question. How can i create a partition using all the free space in parted. is there a begin end option like parted -s /dev/sda logical begin end? Commented Jul 24, 2013 at 13:18
  • I mean without fixing the size, just assigning all the available free space to the new partition? Commented Jul 24, 2013 at 13:22
  • @Coffe_Mug you probably want to start with info parted... Commented Jul 24, 2013 at 14:08
  • @derobert I could not find anything other than specifying the start and end in numbers! For example fdisk can determine the start of the next partition automatically and I am wondering if there is a way to do it in parted as well. Commented Jul 24, 2013 at 14:23
  • @Coffe_Mug "Running Parted" in that manual says you can use negative numbers to count from end, with "-1s" being the end. Haven't tried it myself... Commented Jul 24, 2013 at 14:24

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.