| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | type getarg >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/dracut-lib.shscip-shell source . . `/lib/dracut-lib.sh`. |
| 4 | type udev_pending >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-lib.shscip-shell source . . `/lib/kiwi-lib.sh`. |
| 5 | |
| 6 | function lvm_systemscip-shell shell shell-project 0.0.0 lvm_system(). { |
| 7 | declare kiwi_lvm=${kiwi_lvm} |
| 8 | if [scip-shell system . . `[`. "${kiwi_lvm}" = "true" ];then |
| 9 | return 0 |
| 10 | fi |
| 11 | return 1 |
| 12 | } |
| 13 | |
| 14 | function setup_lvm_configscip-shell shell shell-project 0.0.0 setup_lvm_config(). { |
| 15 | mkdirscip-shell system . . mkdir. -p /etc/lvmscip-shell filesystem . . `/etc/lvm`. |
| 16 | catscip-shell system . . cat. > /etc/lvm/lvm.confscip-shell filesystem . . `/etc/lvm/lvm.conf`. <<- EOF |
| 17 | global { |
| 18 | locking_type = 0 |
| 19 | use_lvmetad = 0 |
| 20 | } |
| 21 | EOF |
| 22 | } |
| 23 | |
| 24 | function activate_volume_groupscip-shell shell shell-project 0.0.0 activate_volume_group(). { |
| 25 | declare kiwi_lvmgroup=${kiwi_lvmgroup} |
| 26 | local vg_count=0 |
| 27 | local vg_name |
| 28 | if lvm_systemscip-shell shell shell-project 0.0.0 lvm_system().;then |
| 29 | for vg_name in $(vgs --noheadings -o vg_name 2>/dev/nullscip-shell filesystem . . `/dev/null`.);do |
| 30 | if [scip-shell system . . `[`. "${vg_name}" = "${kiwi_lvmgroup}" ];then |
| 31 | vg_count=$((vg_count + 1)) |
| 32 | fi |
| 33 | done |
| 34 | if [scip-shell system . . `[`. ${vg_count} -gt 1 ];then |
| 35 | die "Duplicate VolumeGroup name ${kiwi_lvmgroup} found !" |
| 36 | fi |
| 37 | vgchange -a y "${kiwi_lvmgroup}" |
| 38 | udev_pending |
| 39 | fi |
| 40 | } |
| 41 | |
| 42 | function deactivate_volume_groupscip-shell shell shell-project 0.0.0 deactivate_volume_group(). { |
| 43 | declare kiwi_lvmgroup=${kiwi_lvmgroup} |
| 44 | vgchange -a n "${kiwi_lvmgroup}" |
| 45 | udev_pending |
| 46 | } |
| 47 | |
| 48 | function create_volumescip-shell shell shell-project 0.0.0 create_volume(). { |
| 49 | declare kiwi_lvmgroup=${kiwi_lvmgroup} |
| 50 | local volume_name=$1 |
| 51 | local volume_mb_size=$2 |
| 52 | if [scip-shell system . . `[`. ! -f "$(get_volume_path_for_volume "${volume_name}")" ];then |
| 53 | lvcreate --yes --wipesignatures y \ |
| 54 | --size "${volume_mb_size}M" -n "${volume_name}" "${kiwi_lvmgroup}" |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | function get_volume_path_for_volumescip-shell shell shell-project 0.0.0 get_volume_path_for_volume(). { |
| 59 | declare kiwi_lvmgroup=${kiwi_lvmgroup} |
| 60 | echoscip-shell system . . echo. "/dev/${kiwi_lvmgroup}/$1" |
| 61 | } |
| 62 | |
| 63 | function resize_pyhiscal_volumesscip-shell shell shell-project 0.0.0 resize_pyhiscal_volumes(). { |
| 64 | local device |
| 65 | device=$(get_root_map) |
| 66 | set_device_lock "${device}" pvresize "${device}" |
| 67 | } |
| 68 | |
| 69 | function resize_lvm_volumes_and_filesystemsscip-shell shell shell-project 0.0.0 resize_lvm_volumes_and_filesystems(). { |
| 70 | declare kiwi_lvmgroup=${kiwi_lvmgroup} |
| 71 | local volume_name |
| 72 | local resize_mode |
| 73 | local resize_prefix |
| 74 | local volume_size |
| 75 | local volspec |
| 76 | local all_free_volume |
| 77 | for volspec in $(read_volume_setup "/.profilescip-shell filesystem . . `/.profile`." "skip_all_free_volume");do |
| 78 | resize_prefix='' |
| 79 | volume_name=$(get_volume_name "${volspec}") |
| 80 | resize_mode=$(get_volume_size_mode "${volspec}") |
| 81 | volume_size=$(get_volume_size "${volspec}") |
| 82 | info "Resizing volume ${volume_name}..." |
| 83 | if [scip-shell system . . `[`. ! "${resize_mode}" = "size" ];then |
| 84 | resize_prefix=+ |
| 85 | fi |
| 86 | if lvextend -L "${resize_prefix}${volume_size}M" \ |
| 87 | "/dev/${kiwi_lvmgroup}/${volume_name}" |
| 88 | then |
| 89 | resize_filesystem "/dev/${kiwi_lvmgroup}/${volume_name}" |
| 90 | else |
| 91 | warn "Warning: requested size cannot be reached !" |
| 92 | fi |
| 93 | done |
| 94 | all_free_volume=$(get_all_free_volume) |
| 95 | if [scip-shell system . . `[`. -n "${all_free_volume}" ];then |
| 96 | if lvextend -l +100%FREE "/dev/${kiwi_lvmgroup}/${all_free_volume}";then |
| 97 | resize_filesystem "/dev/${kiwi_lvmgroup}/${all_free_volume}" |
| 98 | fi |
| 99 | fi |
| 100 | } |
| 101 | |
| 102 | function read_volume_setupscip-shell shell shell-project 0.0.0 read_volume_setup(). { |
| 103 | # """ |
| 104 | # read the volume setup from the profile file and return |
| 105 | # a list with the following values: |
| 106 | # |
| 107 | # volume_name,resize_mode,requested_size,mount_point ... |
| 108 | # """ |
| 109 | local profile=$1 |
| 110 | local skip_all_free_volume=$2 |
| 111 | local volume |
| 112 | local name |
| 113 | local mode |
| 114 | local size |
| 115 | local mpoint |
| 116 | local result |
| 117 | local volspec |
| 118 | result=$( |
| 119 | while read -r volspec;do |
| 120 | if ! [[ "${volspec}" =~ "kiwi_Volume_" ]];then |
| 121 | continue |
| 122 | fi |
| 123 | volume=$(echoscip-shell system . . echo. "${volspec}" | cutscip-shell system . . cut. -f2 -d= | trscip-shell system . . tr. -d \' | trscip-shell system . . tr. -d \") |
| 124 | size=$(echoscip-shell system . . echo. "${volume}" | cutscip-shell system . . cut. -f2 -d\| | cutscip-shell system . . cut. -f2 -d:) |
| 125 | if [scip-shell system . . `[`. "${size}" = "all" ] && [scip-shell system . . `[`. -n "${skip_all_free_volume}" ];then |
| 126 | continue |
| 127 | fi |
| 128 | mode=$(echoscip-shell system . . echo. "${volume}" | cutscip-shell system . . cut. -f2 -d\| | cutscip-shell system . . cut. -f1 -d:) |
| 129 | name=$(echoscip-shell system . . echo. "${volume}" | cutscip-shell system . . cut. -f1 -d\|) |
| 130 | mpoint=$(echoscip-shell system . . echo. "${volume}" | cutscip-shell system . . cut. -f3 -d\|) |
| 131 | if [scip-shell system . . `[`. -z "${mpoint}" ];then |
| 132 | mpoint=noop |
| 133 | fi |
| 134 | echoscip-shell system . . echo. "${name},${mode},${size},${mpoint}" |
| 135 | done < "${profile}" |
| 136 | ) |
| 137 | echoscip-shell system . . echo. "${result}" |
| 138 | } |
| 139 | |
| 140 | function read_volume_setup_all_freescip-shell shell shell-project 0.0.0 read_volume_setup_all_free(). { |
| 141 | # """ |
| 142 | # read the volume setup from the profile file and |
| 143 | # lookup the volume that should take the rest space |
| 144 | # available in the volume group. |
| 145 | # |
| 146 | # return a list with the following values: |
| 147 | # |
| 148 | # volume_name,mount_point |
| 149 | # |
| 150 | # If no @root volume is configured in the kiwi XML |
| 151 | # description the default LVRoot volume will be used |
| 152 | # to take the rest space. |
| 153 | # """ |
| 154 | local profile=$1 |
| 155 | local size |
| 156 | local volume |
| 157 | local name |
| 158 | local mpoint |
| 159 | while read -r volspec;do |
| 160 | if ! [[ "${volspec}" =~ "kiwi_Volume_" ]];then |
| 161 | continue |
| 162 | fi |
| 163 | volume=$(echoscip-shell system . . echo. "${volspec}" | cutscip-shell system . . cut. -f2 -d= | trscip-shell system . . tr. -d \' | trscip-shell system . . tr. -d \") |
| 164 | size=$(echoscip-shell system . . echo. "${volume}" | cutscip-shell system . . cut. -f2 -d\| | cutscip-shell system . . cut. -f2 -d:) |
| 165 | name=$(echoscip-shell system . . echo. "${volume}" | cutscip-shell system . . cut. -f1 -d\|) |
| 166 | if [scip-shell system . . `[`. "${size}" = "all" ];then |
| 167 | mpoint=$(echoscip-shell system . . echo. "${volume}" | cutscip-shell system . . cut. -f3 -d\|) |
| 168 | echoscip-shell system . . echo. "${name},${mpoint}" |
| 169 | return |
| 170 | fi |
| 171 | done < "${profile}" |
| 172 | } |
| 173 | |
| 174 | function get_all_free_volumescip-shell shell shell-project 0.0.0 get_all_free_volume(). { |
| 175 | read_volume_setup_all_freescip-shell shell shell-project 0.0.0 read_volume_setup_all_free(). "/.profilescip-shell filesystem . . `/.profile`." | cutscip-shell system . . cut. -f1 -d, |
| 176 | } |
| 177 | |
| 178 | function get_volume_namescip-shell shell shell-project 0.0.0 get_volume_name(). { |
| 179 | echoscip-shell system . . echo. "$1" | cutscip-shell system . . cut. -f1 -d, |
| 180 | } |
| 181 | |
| 182 | function get_volume_mount_pointscip-shell shell shell-project 0.0.0 get_volume_mount_point(). { |
| 183 | echoscip-shell system . . echo. "$1" | cutscip-shell system . . cut. -f4 -d, |
| 184 | } |
| 185 | |
| 186 | function get_volume_size_modescip-shell shell shell-project 0.0.0 get_volume_size_mode(). { |
| 187 | echoscip-shell system . . echo. "$1" | cutscip-shell system . . cut. -f2 -d, |
| 188 | } |
| 189 | |
| 190 | function get_volume_sizescip-shell shell shell-project 0.0.0 get_volume_size(). { |
| 191 | echoscip-shell system . . echo. "$1" | cutscip-shell system . . cut. -f3 -d, |
| 192 | } |