[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: selectively delete partitions

I've used sfdisk to do this in the past, if you want to keep only the
first partition, you can do something like this in a %pre:

sfdisk -d /dev/sda > /tmp/sfdisk.sda
egrep '^(unit|/dev/sda1 )' /tmp/sfdisk.sda | sfdisk

Note that in this example there is a space after sda1, which may be
important if you have a lot of partitions and don't want it to keep
sda10 or sda11 for example.  You can also replace the egrep with
whatever you want to do to keep the correct partitions.  For example,
if you want to just keep the Linux partitions (type 83), you could do

(egrep '^units' /tmp/sfdisk.sda; egrep 'ID=( 5|83)' /tmp/sfdisk.sda) | sfdisk

You may or may not need the 5 (the extended partition) depending on
your requirements.

I've also setup systems to keep the first linux partition and the
first swap partition like this:

sfdisk -d /dev/sda > /tmp/sfdisk.sda
   head -3 /tmp/sfdisk.sda
       grep Id=82 /tmp/sfdisk.sda | head -1
       grep Id=83 /tmp/sfdisk.sda | head -1
   ) | sort
) | sfdisk

(These systems didn't have anything I wanted to keep on the extended
partition, so keep that in mind.)
thank you, I'll try that later. That's exactly what I was looking for.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]