repart 25.6 KB
Newer Older
Rafael Monnerat's avatar
Rafael Monnerat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
#!/bin/bash
#================
# FILE          : linuxrc
#----------------
# PROJECT       : OpenSuSE KIWI Image System
# COPYRIGHT     : (c) 2006 SUSE LINUX Products GmbH. All rights reserved
#               :
# AUTHOR        : Marcus Schaefer <ms@suse.de>
#               :
# BELONGS TO    : Operating System images
#               :
# DESCRIPTION   : OEM repartition code functions. This file is used
#               : to setup the partition table according to the OEM
#               : specifications
#               :
# STATUS        : BETA
#----------------
#======================================
# OEMRepartInit 
#--------------------------------------
function OEMRepartInit {
	# /.../
	# calculate memory based swapsize amount and initialize
	# size of recovery archive
	# ----
	mem_size=`grep MemTotal: /proc/meminfo | tr -dc '[0-9]'`
	swapsize=$(( $mem_size *2 / 1024 ))
	recoMByte=0
	if [ ! -z "$OEM_SWAPSIZE" ];then
		swapsize=$OEM_SWAPSIZE
	fi
	if [ ! -z "$OEM_WITHOUTSWAP" ];then
		swapsize=0
	fi
	if [ ! -z "$OEM_RECOVERY" ];then
		mkdir -p /reco-root
		if ! mount $imageRootDevice /reco-root >/dev/null;then
			systemException "Failed to mount root device" "reboot"
		fi
		if [ ! -f /reco-root/recovery.partition.size ];then
			systemException "Can't find recovery part size info" "reboot"
		fi
		recoMByte=$(cat /reco-root/recovery.partition.size)
		recoID=83
		if [ ! -z "$OEM_RECOVERY_ID" ];then
			recoID=$OEM_RECOVERY_ID
		fi
		umount /reco-root && rmdir /reco-root
	fi
	export input=/part.input
	rm -f $input
}

#======================================
# OEMRepartStandard
#--------------------------------------
function OEMRepartStandard {
	# /.../
	# repartition disk with read/write root filesystem
	# Initial partition table layout is:
	# =====================================
	# p1: ( root )  +luks
	# p2: [ boot ]
	# -------------------------------------
	local newparts=0
	local partsize=0
	#======================================
	# check for boot partition
	#--------------------------------------
	createBootDeviceData 2
	#======================================
	# deactivate features if required
	#--------------------------------------
	if [ "$haveBootPartition" = "yes" ];then
		export OEM_WITHOUTHOME=1
	fi
	#======================================
	# setup initial boot device ID
	#--------------------------------------
	export bootid=1
	if [ "$haveBootPartition" = "yes" ];then
		bootid=2
	fi
	#======================================
	# calculate partition sizes
	#--------------------------------------
	minhome=0
	if [ -z "$OEM_WITHOUTHOME" ];then
		minhome=500
	fi
	diskXMBytes=$(($(partitionSize $imageDiskDevice) / 1024))
	diskP1MByte=$(($(partitionSize $(ddn $imageDiskDevice 1)) / 1024))
	diskRMBytes=$((
		diskXMBytes - diskP1MByte - swapsize - recoMByte - bootXMBytes - minhome
	))
	disk1MBytes=$((diskP1MByte + diskRMBytes))
	if [ ! -z "$OEM_SYSTEMSIZE" ];then
		if [ $OEM_SYSTEMSIZE -le $disk1MBytes ];then
			disk1MBytes=$OEM_SYSTEMSIZE
		fi
	fi
	#======================================
	# check repart operation
	#--------------------------------------
	if [ $disk1MBytes -lt $diskP1MByte ];then
		# /.../
		# Requested system partition size is smaller than
		# existing partition, will not re-partition
		# ----
		Echo "Current system partition is bigger than requested size"
		Echo "Disk won't be re-partitioned"
		disableOEMParameters
		disableRepart
	fi
	#======================================
	# write new partition table
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		pID=1
		bootParam=1
		recoParam=no
		swapParam=no
		homeParam=no
		#======================================
		# clean/backup boot partition
		#--------------------------------------
		if [ "$haveBootPartition" = "yes" ];then
			createPartitionerInput \
				d 2
		fi
		#======================================
		# count partitions to be created
		#--------------------------------------
		if [ -z "$OEM_WITHOUTSWAP" ];then
			newparts=$((newparts + 1))
		fi
		if [ ! -z "$OEM_RECOVERY" ];then
			newparts=$((newparts + 1))
		fi
		if [ ! -z "$bootXMBytes" ];then
			newparts=$((newparts + 1))
		fi
		if [ -z "$OEM_WITHOUTHOME" ];then
			newparts=$((newparts + 1))
		fi
		#======================================
		# repart root partition
		#--------------------------------------
		partsize=+"$disk1MBytes"M
		if [ -z "$OEM_SYSTEMSIZE" ] && [ $newparts -eq 0 ];then
			partsize=.
		fi
		createPartitionerInput \
			d n p $pID . $partsize
		#======================================
		# add swap partition
		#--------------------------------------
		if [ -z "$OEM_WITHOUTSWAP" ];then
			pID=$((pID + 1))
			partsize=+"$swapsize"M
			if [ -z "$OEM_SYSTEMSIZE" ] && [ $newparts -eq 1 ];then
				partsize=.
			fi
			createPartitionerInput \
				n p $pID . $partsize t 2 82
			newparts=$((newparts - 1))
			swapParam=$pID
		fi
		#======================================
		# add recovery partition
		#--------------------------------------
		if [ ! -z "$OEM_RECOVERY" ];then
			pID=$((pID + 1))
			partsize=+"$recoMByte"M
			createPartitionerInput \
				n p $pID . $partsize t $pID $recoID
			newparts=$((newparts - 1))
			recoParam=$pID
		fi
		#======================================
		# add boot partition
		#--------------------------------------
		if [ ! -z "$bootXMBytes" ];then
			pID=$((pID + 1))
			partsize=+"$bootXMBytes"M
			createPartitionerInput \
				n p $pID . $partsize t $pID $bootpartID
			newparts=$((newparts - 1))
			bootParam=$pID
		fi
		#======================================
		# add home partition
		#--------------------------------------
		if [ -z "$OEM_WITHOUTHOME" ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . .
			newparts=$((newparts - 1))
			homeParam=$pID
		fi
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam no
		callPartitioner $input
	fi
	#======================================
	# post repart actions
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		#======================================
		# Activate boot partition
		#--------------------------------------
		activateBootPartition
		#======================================
		# Create boot filesystem if required
		#--------------------------------------
		createBootDeviceFilesystem
	fi
}

#======================================
# OEMRepartSplit
#--------------------------------------
function OEMRepartSplit {
	# /.../
	# repartition disk for overlay systems with aufs, clicfs
	# and friends and also systems of image type split.
	# Initial partition table layout is:
	# =====================================
	# p1: ( compressed )
	# p2: ( write area ) +luks
	# p3: [ boot ]
	# -------------------------------------
	#====================================== 
	# no recovery support in union mode
	#--------------------------------------
	unset OEM_RECOVERY
	#====================================== 
	# no homepart support for union mode
	#--------------------------------------
	export OEM_WITHOUTHOME=1
	#======================================
	# check for boot partition
	#--------------------------------------
	createBootDeviceData 3
	#======================================
	# setup initial boot device ID
	#--------------------------------------
	export bootid=2
	if [ "$haveBootPartition" = "yes" ];then
		bootid=3
	fi
	#====================================== 
	# check for read-write partition
	#--------------------------------------
	if ! partitionSize $(ddn $imageDiskDevice 2) &>/dev/null;then
		Echo "No read-write partition in this split/overlay image"
		disableOEMParameters
		disableRepart
	fi
	if [ -z "$DONT_PARTITION" ];then
		#======================================
		# calculate partition sizes
		#--------------------------------------
		diskXMBytes=$(($(partitionSize $imageDiskDevice) / 1024))
		diskP1MByte=$(($(partitionSize $(ddn $imageDiskDevice 1)) / 1024))
		diskP2MByte=$(($(partitionSize $(ddn $imageDiskDevice 2)) / 1024))
		diskRMBytes=$((
			diskXMBytes - diskP1MByte - diskP2MByte - swapsize - bootXMBytes
		))
		disk2MBytes=$((diskP2MByte + diskRMBytes))
		if [ ! -z "$OEM_SYSTEMSIZE" ];then
			if [ $OEM_SYSTEMSIZE -le $disk2MBytes ];then
				disk2MBytes=$OEM_SYSTEMSIZE
			fi
		fi
		#======================================
		# check repart operation
		#--------------------------------------
		if [ $disk2MBytes -lt $diskP2MByte ];then
			# /.../
			# Requested read/write partition size is smaller than
			# existing partition, will not re-partition
			# ----
			Echo "Current read/write partition is bigger than requested size"
			Echo "Disk won't be re-partitioned"
			disableOEMParameters
			disableRepart
		fi
	fi
	#======================================
	# write new partition table
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		pID=2
		bootParam=2
		recoParam=no
		swapParam=no
		homeParam=no
		#======================================
		# clean/backup boot partition
		#--------------------------------------
		if [ "$haveBootPartition" = "yes" ];then
			createPartitionerInput \
				d 3
		fi
		#======================================
		# repart cow partition
		#--------------------------------------
		createPartitionerInput \
			d $pID n p $pID . +"$disk2MBytes"M
		#======================================
		# add swap partition
		#--------------------------------------
		if [ ! $swapsize = 0 ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . +"$swapsize"M t $pID 82
			swapParam=$pID
		fi
		#======================================
		# add boot partition
		#--------------------------------------
		if [ "$haveBootPartition" = "yes" ];then
			pID=$((pID + 1))
			createPartitionerInput \
				n p $pID . +"$bootXMBytes"M t $pID $bootpartID
			bootParam=$pID
		fi
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam 2
		callPartitioner $input
	fi
	#======================================
	# post repart actions
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		#======================================
		# Activate boot partition
		#--------------------------------------
		activateBootPartition
		#======================================
		# Create boot filesystem if required
		#--------------------------------------
		createBootDeviceFilesystem
	fi
}

#======================================
# OEMRepartLVM
#--------------------------------------
function OEMRepartLVM {
	# /.../
	# repartition disk if LVM partition plus boot partition
	# is used. Initial partition table layout is:
	# =====================================
	# p1: ( LVM  )  +luks
	# p2: ( boot )
	# -------------------------------------
	#======================================
	# setup initial boot device ID
	#--------------------------------------
	export bootid=2
	#======================================
	# calculate partition sizes
	#--------------------------------------
	local extendID
	local VOverHeadMB=300
	local diskXMBytes=$(($(partitionSize $imageDiskDevice) / 1024))
	local disk1MBytes=$(($(partitionSize $(ddn $imageDiskDevice 1)) / 1024))
	local disk2MBytes=$(($(partitionSize $(ddn $imageDiskDevice 2)) / 1024))
	if [ ! -z "$OEM_SYSTEMSIZE" ];then
		disk1MBytes=$OEM_SYSTEMSIZE
	fi
	local diskRMBytes=$((
		recoMByte + disk1MBytes + disk2MBytes + swapsize + VOverHeadMB
	))
	#======================================
	# check repart operation
	#--------------------------------------
	if [ $diskRMBytes -gt $diskXMBytes ];then
		Echo "Disk is too small, will not re-partition it"
		disableOEMParameters
		disableRepart
	fi
	#======================================
	# write new partition table
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ];then
		pID=3
		bootParam=2
		recoParam=no
		swapParam=no
		homeParam=no
		#======================================
		# close open device mappings
		#--------------------------------------
		if [ "$haveLuks" = "yes" ];then
			luksClose
		fi
		vgchange -an
		#======================================
		# add recovery partition
		#--------------------------------------
		if [ ! -z "$OEM_RECOVERY" ];then
			createPartitionerInput \
				n p $pID . +"$recoMByte"M t $pID $recoID
			recoParam=$pID
			pID=$((pID + 1))
		fi
		#======================================
		# add rest space LVM partition
		#--------------------------------------
		createPartitionerInput \
			n p $pID . . t $pID 8e
		extendID=$pID
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam yes $VGROUP
		callPartitioner $input
		waitForStorageDevice $(ddn $imageDiskDevice $extendID)
		dd if=/dev/zero of=$(ddn $imageDiskDevice $extendID) bs=1024 count=5
		vgchange -an
		activateBootPartition
		#======================================
		# extend volume group with rest space
		#--------------------------------------
		vgchange -a y $VGROUP
		pvcreate $(ddn $imageDiskDevice $extendID)
		vgextend $VGROUP $(ddn $imageDiskDevice $extendID)
		#======================================
		# Extend LVRoot to requested size
		#--------------------------------------
		lvextend --size $disk1MBytes"M" /dev/$VGROUP/LVRoot
		#======================================
		# Add LVSwap if requested.
		#--------------------------------------
		if [ -z "$OEM_WITHOUTSWAP" ];then
			lvcreate --size $swapsize"M" -n LVSwap $VGROUP
			swapParam=yes
		fi
		#======================================
		# Add LVHome if requested
		#--------------------------------------
		if [ -z "$OEM_WITHOUTHOME" ];then
			lvcreate -l 100%FREE -n LVHome $VGROUP
			homeParam=yes
		elif [ -z "$OEM_SYSTEMSIZE" ];then
			lvextend -l 100%FREE /dev/$VGROUP/LVRoot
		fi
		#======================================
		# setup new device names
		#--------------------------------------
		setupDeviceNames \
			1 $swapParam $homeParam $recoParam $bootParam yes $VGROUP
	fi
}

#======================================
# OEMPartitionInstall
#--------------------------------------
function OEMPartitionInstall {
	# /.../
	# don't repart the disk but prepare it for use with
	# the existing partition table
	# ----
	#======================================
	# no recovery support for part install
	#--------------------------------------
	unset OEM_RECOVERY
	#======================================
	# no homepart support for part install
	#--------------------------------------
	export OEM_WITHOUTHOME=1
	#======================================
	# check for LVM, resize to full space
	#--------------------------------------
	if searchVolumeGroup;then
		#======================================
		# resize PV's
		#--------------------------------------
		pvresize $(ddn $imageDiskDevice $rID)
		#======================================
		# resize LV's
		#--------------------------------------
		lvresize -l 100%FREE $imageRootDevice
	fi
	#======================================
	# resize boot filesystem if needed
	#--------------------------------------
	if [ ! $imageBootDevice = $imageRootDevice ];then
		resizeFilesystem $imageBootDevice
	fi
	#======================================
	# cleanup temporary flags
	#--------------------------------------
	unset DONT_PARTITION
}

#======================================
# OEMRepart
#--------------------------------------
function OEMRepart {
	# /.../
	# call the appropriate repartition functions
	# ----
	if [ ! $LOCAL_BOOT = "no" ];then
		return
	fi
	#======================================
	# check for luks extension
	#--------------------------------------
	if [ "$haveLuks" = "yes" ];then
		unset  OEM_RECOVERY
		export OEM_WITHOUTHOME=1
	fi
	#======================================
	# Initialize
	#--------------------------------------
	OEMRepartInit
	#======================================
	# Do the repartitioning
	#--------------------------------------
	if [ ! -z "$OEM_PARTITION_INSTALL" ];then
		OEMPartitionInstall
	elif [ ! -z "$haveLVM" ];then
		OEMRepartLVM
	elif isFSTypeReadOnly;then
		OEMRepartSplit
	else
		OEMRepartStandard
	fi
	sleep 1
	#======================================
	# setup luks maps
	#--------------------------------------
	if [ "$haveLuks" = "yes" ];then
		createLuksMaps
	fi
	#======================================
	# find fstype for root partition
	#--------------------------------------
	probeFileSystem $imageRootDevice
	#======================================
	# Activate swap space
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ $swapsize -gt 0 ]; then
		if partitionSize $imageSwapDevice &>/dev/null;then
			Echo "Activating swap space on $imageSwapDevice"
			if ! mkswap $imageSwapDevice 1>&2;then
				systemException "Failed to create swap signature" "reboot"
			fi
		fi
	fi
	#======================================
	# Create home file system
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ -z "$OEM_WITHOUTHOME" ];then
		Echo "Creating Home filesystem on $imageHomeDevice"
		createFilesystem $imageHomeDevice
	fi
	#======================================
	# Create recovery file system
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ ! -z "$OEM_RECOVERY" ];then
		Echo "Creating Recovery filesystem on $imageRecoveryDevice"
		if ! mke2fs -T ext2 -q -L recovery $imageRecoveryDevice 1>&2;then
			systemException "Failed to create Recovery fs" "reboot"
		fi
	fi
	#======================================
	# Setup recovery contents
	#--------------------------------------
	if [ -z "$DONT_PARTITION" ] && [ ! -z "$OEM_RECOVERY" ];then
		Echo "Setting up recovery archive..."
		mkdir -p /reco-root
		if ! mount $imageRootDevice /reco-root >/dev/null;then
			systemException "Failed to mount root device" "reboot"
		fi
		if [ ! -z "$haveLVM" ];then
			mkdir -p /recoboot && mount $imageBootDevice /recoboot
			mount --bind /recoboot/boot /reco-root/boot
		fi
		mkdir -p /reco-save
		if ! mount $imageRecoveryDevice /reco-save >/dev/null;then
			systemException "Failed to mount recovery device" "reboot"
		fi
		if ! mv /reco-root/recovery.tar.files /reco-save >/dev/null;then
			systemException "Failed to move recovery file count" "reboot"
		fi
		if ! mv /reco-root/recovery.tar.filesystem /reco-save >/dev/null;then
			systemException "Failed to move recovery filesystem info" "reboot"
		fi
		if ! mv /reco-root/recovery.tar.size /reco-save >/dev/null;then
			systemException "Failed to move recovery size info" "reboot"
		fi
		if ! mv /reco-root/recovery.partition.size /reco-save >/dev/null;then
			systemException "Failed to move recovery part size info" "reboot"
		fi
		if [ -f /reco-root/recovery.tar.gz ];then
			if ! mv /reco-root/recovery.tar.gz /reco-save >/dev/null;then
				systemException "Failed to move recovery archive" "reboot"
			fi
		else
			pushd /reco-root
			Echo "Creating recovery root tarball..."
			tar --numeric-owner -czpf /reco-save/recovery.tar.gz . \
				--exclude "./dev" \
				--exclude "./proc" \
				--exclude "./sys" \
				--exclude "./recovery.*"
			popd
		fi
		mkdir /reco-save/boot
		if [ "$loader" = "grub" ];then
			if ! cp /reco-root/boot/initrd.vmx /reco-save/boot/initrd;then
				systemException "Failed to copy recovery initrd" "reboot"
			fi
			if ! cp /reco-root/boot/linux.vmx /reco-save/boot/vmlinuz;then
				systemException "Failed to copy recovery kernel" "reboot"
			fi
			if ! cp /reco-root/boot/message /reco-save/boot/message;then
				systemException "Failed to copy recovery gfx message" "reboot"
			fi
		fi
		if [ -f /boot.tgz ];then
			if ! tar -xf /boot.tgz -C /reco-save;then
				systemException "Failed to extract recovery boot files" "reboot"
			fi
		fi
		if ! dd if=$imageDiskDevice of=/reco-save/mbr bs=1 count=512;then
			systemException "Failed to store MBR" "reboot"
		fi
		if [ ! -z "$haveLVM" ];then
			if ! vgcfgbackup -f /reco-save/lvm $VGROUP;then
				systemException "Failed to store LVM metadata" "reboot"
			fi
		fi
		if [ ! -z "$haveLVM" ];then
			umount /reco-root/boot
			umount /recoboot && rmdir /recoboot
		fi
		umount /reco-save && rmdir /reco-save
		umount /reco-root && rmdir /reco-root
	fi
}

#======================================
# activateBootPartition
#--------------------------------------
function activateBootPartition {
	# /.../
	# set boot flag to current value of $bootid
	# ----
	Echo "Set boot flag to partition ID: $bootid [ $imageDiskDevice ]"
	parted $imageDiskDevice set $bootid boot on
	if test $? != 0; then
		systemException "Failed to set boot flag" "reboot"
	fi
	blockdev --rereadpt $imageDiskDevice
	local deviceTest=$(ddn $imageDiskDevice 1)
	if ! waitForStorageDevice $deviceTest;then
		systemException \
			"Partition $deviceTest doesn't appear... fatal !" \
		"reboot"
	fi
}

#======================================
# setupDeviceNames
#--------------------------------------
function setupDeviceNames {
	local rootID=$1
	local swapID=$2
	local homeID=$3
	local recoID=$4
	local bootID=$5
	local iorwID=$6
	local vgroup=$7
	if [ -z "$vgroup" ];then
		#======================================
		# set root device name
		#--------------------------------------
		export imageRootDevice=$(ddn $imageDiskDevice $rootID)
		#======================================
		# set swap device name
		#--------------------------------------
		if [ ! $swapID = "no" ];then
			export imageSwapDevice=$(ddn $imageDiskDevice $swapID)
		fi
		#======================================
		# set home device name
		#--------------------------------------
		if [ ! $homeID = "no" ];then
			export imageHomeDevice=$(ddn $imageDiskDevice $homeID)
		fi
		#======================================
		# set recovery device name
		#--------------------------------------
		if [ ! $recoID = "no" ];then
			export imageRecoveryDevice=$(ddn $imageDiskDevice $recoID)
			export recoid=$recoID
		fi
		#======================================
		# set read-write device name
		#--------------------------------------
		if [ ! $iorwID = "no" ];then
			export imageIOWRDevice=$(ddn $imageDiskDevice $iorwID)
			export imageRWDevice=$imageIOWRDevice
			export imageRODevice=$imageRootDevice
		fi
		#======================================
		# set boot device name
		#--------------------------------------
		export imageBootDevice=$(ddn $imageDiskDevice $bootID)
		#======================================
		# set boot partition id
		#--------------------------------------
		export bootid=$bootID
	else
		#======================================
		# set LVM root device name
		#--------------------------------------
		export imageRootDevice=/dev/$vgroup/LVRoot
		#======================================
		# set LVM swap device name
		#--------------------------------------
		if [ ! $swapID = "no" ];then
			export imageSwapDevice=/dev/$vgroup/LVSwap
		fi
		#======================================
		# set LVM home device name
		#--------------------------------------
		if [ ! $homeID = "no" ];then
			export imageHomeDevice=/dev/$vgroup/LVHome
		fi
		#======================================
		# set LVM recovery device name
		#--------------------------------------
		if [ ! $recoID = "no" ];then
			export imageRecoveryDevice=$(ddn $imageDiskDevice $recoID)
			export recoid=$recoID
		fi
		#======================================
		# set LVM read-write device name
		#--------------------------------------
		if [ ! $iorwID = "no" ];then
			if [ -e /dev/$vgroup/LVComp ];then
				export imageRootDevice=/dev/$vgroup/LVComp
			fi
			export imageIOWRDevice=/dev/$vgroup/LVRoot
			export imageRWDevice=$imageIOWRDevice
			export imageRODevice=/dev/$vgroup/LVComp
		fi
		#======================================
		# set LVM boot device name
		#--------------------------------------
		export imageBootDevice=$(ddn $imageDiskDevice $bootID)
		#======================================
		# set LVM boot partition id
		#--------------------------------------
		export bootid=$bootID
	fi
}

#======================================
# createBootDeviceData
#--------------------------------------
function createBootDeviceData {
	local bootPart=$1
	if partitionSize $(ddn $imageDiskDevice $bootPart) &>/dev/null;then
		#======================================
		# Variable setup
		#--------------------------------------
		export haveBootPartition=yes
		export bootXMBytes=60
		export bootpartID=83
		if [ "$loader" = "syslinux" ];then
			bootpartID=6
		fi
		#======================================
		# Store contents in RAM
		#--------------------------------------
		mount $(ddn $imageDiskDevice $bootPart) /mnt
		tar -czf /boot.tgz -C /mnt .
		umount /mnt
	fi
	#====================================== 
	# check for overlay type
	#--------------------------------------
	local unionFST=`echo $UNIONFS_CONFIG | cut -d , -f 3`
	if [ "$unionFST" = "clicfs" ];then
		export haveClicFS=yes
	fi
	sleep 1
}

#======================================
# createBootDeviceFilesystem
#--------------------------------------
function createBootDeviceFilesystem {
	if [ ! "$haveBootPartition" = "yes" ];then
		return
	fi
	if [ "$loader" = "syslinux" ];then
		mkdosfs $imageBootDevice >/dev/null 2>&1
	else
		mke2fs -q $imageBootDevice >/dev/null 2>&1
	fi
	if [ ! $? = 0 ];then
		systemException \
			"Failed to create Boot filesystem" \
		"reboot"
	fi
}

#======================================
# createLuksMaps
#--------------------------------------
function createLuksMaps {
	export imageRootDevice=$(luksOpen $imageRootDevice)
	if isFSTypeReadOnly;then
		export imageIOWRDevice=$(luksOpen $imageIOWRDevice luksReadWrite)
		export imageRWDevice=$imageIOWRDevice
		export imageRODevice=$imageRootDevice
	fi
}

#======================================
# disableOEMParameters
#--------------------------------------
function disableOEMParameters {
	export OEM_WITHOUTHOME=1
	export OEM_WITHOUTSWAP=1
	unset OEM_RECOVERY
	unset OEM_SYSTEMSIZE
}

#======================================
# disableRepart
#--------------------------------------
function disableRepart {
	DONT_PARTITION=1
}