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?

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.

  • 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? – coffeMug Jul 24 '13 at 13:18
  • I mean without fixing the size, just assigning all the available free space to the new partition? – coffeMug Jul 24 '13 at 13:22
  • @Coffe_Mug you probably want to start with info parted... – derobert Jul 24 '13 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. – coffeMug Jul 24 '13 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... – derobert Jul 24 '13 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.