Re: Don't delete a partition, if it doesn't exist...create it.

686f6c6d <[email protected]> Wed, 23 Jul 2014 14:42:19 +0200
Newsgroups gmane.linux.suse.autoinstall
Message-ID <CAMEHyeE-HPLDeAci5CKa8ib1enJvfXZxsv5zKWoeCJt1Ua84uw@mail.gmail.com>
On Wed, Jul 23, 2014 at 11:53 AM, Daniel Spannbauer <[email protected]> wrote:
> Hmmm,
>
> create=false only works if there was a partition before the installation.
>
> but what if the Disk is brand-new? Or if the disk was partitioned with a
> different way?
> Then I have to wipe the complete disk to get my partitioning on that disk.
>
> So, I have only to reformat my disk if the partitioning is not as I want
> it....

Ok, I misunderstood your initial mail. What you are trying to do isn't
easily possible AFAIK.

1. The brand-new case is pretty simple. In that case, you don't have
to worry about keeping the partition, you just create a complete
layout.
2. The case where you have a known layout and just want to keep that
one partition is our case, I have attached the relevant snippets of
our profile. (You can even decide during install if /scratch should be
kept; the machines get the profile snippets via rules.xml.) A similar
case is the one where in your known partition layout you resize your
existing partitions and then add your permanently-kept partition (I've
never done it, but IIRC it's one of the examples in the docs).
3. The hard case is the whatever-existing layout.
    - I would assume this doesn't work automatically with
non-interactive AutoYAST, because the partitioning is only easy to
keep if the layout is already known (see attached files).
    - So if you only have one or a few existing layouts (f.e. they
were all created from the same AutoYAST profile(s)) then you should be
fine, this is the "easy" (it is a bit of work…) case #2 above.
    - If you have a large number of existing layouts, this becomes
unmanageable and I would assume reinstalling them as case #1 would be
easier. But I might be wrong, this is just how I would try to do it.
Merging/streamlining/converging the different cases might be
beneficial in the long run, if reinstalling and possible downtime is
an option.
    - Another option might be to use the y2confirm boot parameter
during AutoYAST install and then resize and add manually (or to do
that from the installed system).


-- 
HTH
    Christopher 'm4z' Holm / 686f6c6d

"We must respect the other fellow's religion, but only in the sense
and to the extent that we respect his theory that his wife is
beautiful and his children smart." --H. L. Mencken
ask_scratch.xml (text/xml, 2.3 KB)
<?xml version="1.0"?>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
  <general>
    <ask-list config:type="list">
      <listentry>
        <title>Optional /scratch wiping.</title>
        <question>Keep /scratch?</question>
        <help>Keep current partitioning and the data in /scratch? Defaults to KEEP in 30s.</help>
        <stage>initial</stage>
        <timeout config:type="integer">30</timeout>
        <file>/tmp/ask_scratch_result.txt</file>
        <password config:type="boolean">false</password>

        <type>boolean</type>
        <default>true</default>

        <script>
          <debug config:type="boolean">false</debug>
          <environment config:type="boolean">true</environment>
          <feedback config:type="boolean">true</feedback>
          <filename>ask_scratch.sh</filename>
          <rerun_on_error config:type="boolean">false</rerun_on_error>
          <source><![CDATA[#!/bin/bash
if [ "$(cat /tmp/ask_scratch_result.txt)" = "false" ]; then
	# the user wants to wipe /scratch off the face of the planet.
	#
	# patchy-patchy
	# We DO NOT want to directly patch the file to modified.xml because
	# autoyast seems to load it even if it is an empty/corrupt file.

	# IMPORTANT: patch the ask-section from the new file, or else you
	# will be asked the same question again and wonder why.

	# patch the rest of the file with the changes we need to *not* keep
	# /scratch, and move the file over where autoyast can see it.
	sed -e '\#^[ \t]\+<ask-list config:type="list">$#,\#^[ \t]\+</ask-list>$#d' \
		-e 's#<initialize config:type="boolean">false</initialize>#<initialize config:type="boolean">true</initialize>#' \
		-e 's#<create config:type="boolean">false</create>#<create config:type="boolean">true</create>#' \
		-e 's#<format config:type="boolean">false</format>#<format config:type="boolean">true</format>#' \
		-e 's#<filesystem config:type="symbol">btrfs</filesystem>#<filesystem config:type="symbol">btrfs</filesystem>#' \
		-e 's#<use>5,6,7,8,9</use>#<use>all</use>#' \
		</tmp/profile/autoinst.xml >/tmp/new.xml
	mv /tmp/new.xml /tmp/profile/modified.xml

	# not strictly necessary, but we're trying to be verbose here.
	exit 0
fi
]]></source>
        </script>
      </listentry>
    </ask-list>
  </general>
</profile>
partitioning.xml (text/xml, 1.9 KB)
<?xml version="1.0"?>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">

  <partitioning config:type="list">
    <drive>
      <device>/dev/sda</device>
      <initialize config:type="boolean">false</initialize>

      <partitions config:type="list">
        <partition>
          <partition_nr config:type="integer">5</partition_nr>
          <format config:type="boolean">true</format>
          <create config:type="boolean">false</create>
          <!-- … -->
        </partition>

        <partition>
          <partition_nr config:type="integer">6</partition_nr>
          <!-- … -->
          <format config:type="boolean">true</format>
          <create config:type="boolean">false</create>
        </partition>

        <partition>
          <partition_nr config:type="integer">7</partition_nr>
          <format config:type="boolean">true</format>
          <create config:type="boolean">false</create>
          <!-- … -->
        </partition>

        <partition>
          <partition_nr config:type="integer">8</partition_nr>
          <format config:type="boolean">true</format>
          <create config:type="boolean">false</create>
          <!-- … -->
        </partition>

        <partition>
          <partition_nr config:type="integer">9</partition_nr>
          <format config:type="boolean">true</format>
          <create config:type="boolean">false</create>
          <!-- … -->
        </partition>

        <partition>
          <size>max</size>
          <mount>/scratch</mount>
          <partition_nr config:type="integer">10</partition_nr>
          <format config:type="boolean">false</format>
          <create config:type="boolean">false</create>
        </partition>
      </partitions>

      <type config:type="symbol">CT_DISK</type>
      <use>5,6,7,8,9</use>
    </drive>
  </partitioning>
</profile>