From a305659134d7a58b86fa1203bf599ee8c1e96007 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 12 Nov 2014 13:59:24 +0100 Subject: [gdisk] prototyp module for gdisk to handle GPT partitions --- .../gdisk/data/inc/prepare_localhd.functions | 163 +++++++++++++++++++++ .../gdisk/data/inc/setup_gpt.differentapproach | 157 ++++++++++++++++++++ remote/modules/gdisk/data/inc/setup_gpt.old | 160 ++++++++++++++++++++ remote/modules/gdisk/module.build | 19 +++ remote/modules/gdisk/module.conf | 94 ++++++++++++ remote/modules/gdisk/module.conf.centos | 5 + 6 files changed, 598 insertions(+) create mode 100755 remote/modules/gdisk/data/inc/prepare_localhd.functions create mode 100755 remote/modules/gdisk/data/inc/setup_gpt.differentapproach create mode 100755 remote/modules/gdisk/data/inc/setup_gpt.old create mode 100644 remote/modules/gdisk/module.build create mode 100644 remote/modules/gdisk/module.conf create mode 100644 remote/modules/gdisk/module.conf.centos diff --git a/remote/modules/gdisk/data/inc/prepare_localhd.functions b/remote/modules/gdisk/data/inc/prepare_localhd.functions new file mode 100755 index 00000000..45075ab0 --- /dev/null +++ b/remote/modules/gdisk/data/inc/prepare_localhd.functions @@ -0,0 +1,163 @@ +#!/bin/ash +# Copyright (c) 2014 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found under http://openslx.org +# +# Local hard disk autodetection script for OpenSLX linux stateless clients, +# detecting special GPT partitions + +############################################################################# + +# Patition IDs +# Prefix for all paritions is 0FC63DAF-8483-4772-8E79-9999999999 +# Suffix: +# 44: non-persistent scratch partition +# 45: persistent partiton +# 46: non-persistent openslx partition for config, overlayfs and qcow images + +# We use special non assigned partition type for harddisk scratch +# space, thus no normal filesystem will be incidentally deleted or +# corrupted + +# Set disks to none +ID44= +ID45= +ID46= + +# General formatter for the /tmp partition on a local harddisk +diskfm () { + mopt="" # Global var! + local target="$1" + local fslist="xfs jfs ext4" + local fs + local path + [ $# -ge 2 ] && fslist="$2" + for fs in $fslist ; do + unset available + case $(cat /proc/filesystems) in + *${fs}*) available=yes;; + *) modprobe "${fs}" && available=yes;; + esac + if [ -n "${available}" ]; then + unset found + if which "mkfs.$fs" >/dev/null; then + found=yes + case "mkfs.$fs" in + mkfs.xfs) + fopt="-fq" + ;; + mkfs.jfs) + fopt="-q" + ;; + mkfs.ext4) + fopt="-Fq" + ;; + esac + mkfs.$fs ${fopt} "${target}" + fi + [ -n "$found" ] && break + fi + done +} + +# function format_pid () +# Formats partition with id 44, 45, 46 +# expects id as parameter +# usage: format_pid [44|45|46] +format_pid () { + local fmtpid=$1 + local target + case $fmtpid in + 44) + target=$ID44 + ;; + 45) + target=$ID45 + ;; + 46) + target=$ID46 + ;; + esac + if echo $target | grep -q '/dev/disk/' + then + # check for supported filesystem and formatter + diskfm $target + else + echo "Could not format partition ID $fmtpid" + fi +} + +# function mount_pid () +# Mounts partition with id 44, 45, 46 +# expects id and mountpoint as parameter +# usage: mount_pid [44|45|46] $MNT +mount_pid () { + local mntpid=$1 + local target=$2 + local source + if [ "x$2" = "x" ] + then + echo "No mountpoint specified dummy!" + else + case $mntpid in + 44) + source=$ID44 + ;; + 45) + source=$ID45 + ;; + 46) + source=$ID46 + ;; + esac + mkdir -p $target + if busybox mount -t auto "$source" "$target" + then + [ "x$mntpid}" = "x44" ] && chmod a+rwxt $target + if echo "$target" | grep -Eq "^mnt/|^/mnt/" + then + fstabtarget=$(echo $target | sed -re "s/[/]{0,1}mnt//") + echo -e "$source\t$fstabtarget\tauto\tnoexec\t0 0" \ + >>/mnt/etc/fstab + fi + else + echo "Could not mount partition ID $mntpid" + fi + fi +} + +# Get partition types +hdisks=$(ls /dev/disk/by-path/*-part[0-9]* \ + | sed -re "s,(.*)-part[0-9]*,\1," \ + | sort -u) + +if echo $hdisks | grep -q '/dev/disk/' + then + for hd in $(echo $hdisks) + do + upartid=$(sgdisk -p $hd 2>/dev/null | awk '$6~/FFFF/ {print $1}') + for upt in $(echo $upartid) + do + echo "${hd}-part${upt} $(sgdisk -i $upt $hd)" \ + | awk '$5 ~ /0FC63DAF-8483-4772-8E79-[0]{10}4[4-6]/ \ + {print $5 "=" $1}' \ + | sed -re "s,0FC63DAF-8483-4772-8E79-[0]{10},ID," \ + >> /etc/hdisks.conf + done + done + if [ -r /etc/hdisks.conf ] + then + . /etc/hdisks.conf + echo -e "Partitions found:\n$(cat /etc/hdisks.conf | cut -d'=' -f1)" + else + echo "No pratition IDs 44, 45 or 46 found" + fi + +fi + diff --git a/remote/modules/gdisk/data/inc/setup_gpt.differentapproach b/remote/modules/gdisk/data/inc/setup_gpt.differentapproach new file mode 100755 index 00000000..25b8dda3 --- /dev/null +++ b/remote/modules/gdisk/data/inc/setup_gpt.differentapproach @@ -0,0 +1,157 @@ +#!/bin/ash +# Copyright (c) 2014 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found under http://openslx.org +# +# Local hard disk autodetection script for OpenSLX linux stateless clients, +# detecting special GPT partitions + +############################################################################# + +# Patition IDs +# Prefix for all paritions is 0FC63DAF-8483-4772-8E79-9999999999 +# Suffix: +# 44: non-persistent scratch partition +# 45: persistent partiton +# 46: non-persistent openslx partition for config, overlayfs and qcow images + +# We use special non assigned partition type for harddisk scratch +# space, thus no normal filesystem will be incidentally deleted or +# corrupted + +PREFIX=/mnt + +# Set disks to none +ID44= +ID45= +ID46= + +# Mountpoints +ID44MNT=/tmp +ID45MNT=/opt/openslx/mnt/persistent +ID46MNT=/opt/openslx/mnt/non-persistent + +# General formatter for the /tmp partition on a local harddisk +diskfm () { + mopt="" # Global var! + local target="$1" + local fslist="xfs jfs ext4" + local fs + local path + [ $# -ge 2 ] && fslist="$2" + for fs in $fslist ; do + unset available + case $(cat /proc/filesystems) in + *${fs}*) available=yes;; + *) modprobe "${fs}" && available=yes;; + esac + if [ -n "${available}" ]; then + unset found + if which "mkfs.$fs" ; then + found=yes + case "mkfs.$fs" in + mkfs.xfs) + fopt="-fq" + ;; + mkfs.jfs) + fopt="-q" + ;; + mkfs.ext4) + fopt="-Fq" + ;; + esac + mkfs.$fs ${fopt} "${target}" + fi + [ -n "$found" ] && break + fi + done +} + +# Format and mount ID44 (/tmp) +mount_id44 () { + HAVE_TMP=no + if echo $ID44 | grep -q '/dev/disk/' + then + # check for supported filesystem and formatter + if diskfm $ID44; then + mkdir -p $PREFIX$ID44MNT + if mount -t auto "$ID44" "$PREFIX$ID44MNT" 2>/dev/null + then + chmod a+rwxt $PREFIX$ID44MNT + echo -e "$ID44\t$ID44MNT\tauto\tnoexec\t0 0" >> "/etc/fstab" + HAVE_TMP=yes + else + echo "Could not mount partition $ID44" + fi + else + echo "Could not format partition $ID44" + fi + fi +} + +# Mount persistent partition 45 +mount_id45 () { + HAVE_PERSISTENT=no + if echo $ID45 | grep -q '/dev/disk/' + then + mkdir -p $PREFIX$ID45MNT + if mount -t auto "$ID45" "$PREFIX$ID45MNT" 2>/dev/null + then + echo -e "$ID45\t$ID45MNT\tauto\tnoauto\t0 0" >> "/etc/fstab" + HAVE_PERSISTENT=yes + else + echo "Could not mount persistent partition $ID45" + fi + fi +} + +# Mount non-persistent partition 46 +mount_id46 () { + HAVE_NONPERSISTENT=no + if echo $ID46 | grep -q '/dev/disk/' + then + # check for supported filesystem and formatter + if diskfm $ID46; then + mkdir -p $PREFIX$ID46MNT + if mount -t auto -o noexec "$ID46" "$PREFIX$ID46MNT" 2>/dev/null + then + echo -e "$ID46\t$ID46MNT\tauto\tnoauto,noexec\t0 0" >> "/etc/fstab" + HAVE_NONPERSISTENT=yes + else + echo "Could not mount non-persistent partition $ID46" + fi + else + echo "Could not format partition $ID44" + fi + fi +} + +# Get partition types +hdisks=$(ls /dev/disk/by-path/*-part[0-9]* \ + | sed -re "s,(.*)-part[0-9]*,\1," \ + | sort -u) + +if echo $hdisks | grep -q '/dev/disk/' + then + for hd in $(echo $hdisks) + do + upartid=$(sgdisk -p $hd 2>/dev/null | awk '$6~/FFFF/ {print $1}') + for upt in $(echo $upartid) + do + echo "${hd}-part${upt} $(sgdisk -i $upt $hd)" \ + | awk '$5 ~ /0FC63DAF-8483-4772-8E79-[0]{10}4[4-6]/ \ + {print $5 "=" $1}' \ + | sed -re "s,0FC63DAF-8483-4772-8E79-[0]{10},ID," \ + >> /etc/hdisks.conf + done + done + [ -r /etc/hdisks.conf ] && . /etc/hdisks.conf + +fi + diff --git a/remote/modules/gdisk/data/inc/setup_gpt.old b/remote/modules/gdisk/data/inc/setup_gpt.old new file mode 100755 index 00000000..a4c971e4 --- /dev/null +++ b/remote/modules/gdisk/data/inc/setup_gpt.old @@ -0,0 +1,160 @@ +#!/bin/ash +# Copyright (c) 2013 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found under http://openslx.org +# +# Local hard disk autodetection script for OpenSLX linux stateless clients, +# detecting swap and special partitions + +############################################################################# + +# Mount point for persistent scratch partition (type 45) +PERSISTENT="/opt/openslx/persistent" + +# General formatter for the /tmp partition on a local harddisk +diskfm () { + mopt="" # Global var! + local target="$1" + local fslist="xfs jfs ext3 ext2 ext4" + local fs + local path + [ $# -ge 2 ] && fslist="$2" + for fs in $fslist ; do + unset available + case $(cat /proc/filesystems) in + *${fs}*) available=yes;; + *) modprobe "${fs}" && available=yes;; + esac + if [ -n "${available}" ]; then + unset found + if which "mkfs.$fs" ; then + found=yes + case "mkfs.$fs" in + mkfs.xfs) + fopt="-f -b size=4k -s size=4k -l size=512b" # fastest formatting possible :) + mopt="-o noexec" + ;; + mkfs.ext2) + fopt="-Fq" + mopt="-o nocheck,noexec" + ;; + mkfs.ext3|mkfs.ext4) + fopt="-Fq" + mopt="-o noexec" + ;; + mkfs.reiserfs) + fopt="-f" + mopt="-o noexec" + ;; + mkfs.jfs) + fopt="-q" + mopt="-o noexec" + ;; + esac + mkfs.$fs ${fopt} "${target}" + fi + [ -n "$found" ] && break + fi + done +} + +mount_temp () { + local PRE=$(pwd) + if ! cd /tmp; then + mount_temp_fallback $@ + return $? + fi + mount $@ /tmp || return 1 + chmod a+rwxt /tmp + # Move stuff from working directory, which is old /tmp, to new /tmp just mounted + mv ./* ./.[!.]* ./..?* /tmp/ 2> /dev/null + local OLD=$(LANG=C ls -alh | grep -v -E ' \.\.?$' | grep -v '^total') + [ -n "$OLD" ] && echo -- "Leftovers:" && echo -- "$OLD" + cd "$PRE" +} + +mount_temp_fallback () { + mkdir -p /tmptmp + mv /tmp/* /tmp/.* /tmptmp/ 2> /dev/null + mount $@ /tmp || return 1 + chmod a+rwxt /tmp + mv /tmptmp/* /tmptmp/.* /tmp/ + rmdir /tmptmp + return 0 +} + +fdisk -l | sed -n "/^\/dev\//p" > "/etc/disk.partition" + +echo "Partitions:" +cat "/etc/disk.partition" + + +# sgdisk -i 1 /dev/sda | grep -o "0FC63DAF-8483-4772-8E79-[4]\{12\}" + +# Check for standard swap partitions and make them available to the system +HAVE_SWAP=no +for hdpartnr in $(sed -n -e "/ 82 /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do + echo -e "$hdpartnr\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab" + swapon "$hdpartnr" -p 10 && HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that) +done + +# We use special non assigned partition type (id44) for harddisk scratch +# space, thus no normal filesystem will be incidentally deleted or +# corrupted +HAVE_TEMP=no +for hdpartnr in $(sed -n -e "/ 44 /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do + # check for supported filesystem and formatter + if diskfm "$hdpartnr"; then + # echo "$hdpartnr is mounted to /mnt/tmp at $(sysup)" >/tmp/tmpready + mount_temp "$mopt" "$hdpartnr" || continue + echo -e "${hdpartnr}\t/tmp\t\tauto\t\tnoexec\t 0 0" >> "/etc/fstab" + HAVE_TEMP=yes + break + else + echo "formatting failed for some reason" + fi # Made this non-forking, systemd should handle it - 2013-05-28 +done + +# Put detected linux partitions (83) into /etc/fstab with "noauto", special +# partition 45 (persistent scratch) to /var/scratch and 46 to /var/openslx +HAVE_PERSISTENT=no +for partid in 83 45 46 ; do + for hdpartnr in $(sed -n -e "/ ${partid} /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do + if [ "${partid}" -eq 83 ]; then + mkdir -p "/media/${hdpartnr#/dev/*}" + echo -e "${hdpartnr}\t/media/${hdpartnr#/dev/*}\tauto\t\tnoauto,noexec\t 0 0" >> "/etc/fstab" + elif [ "${partid}" -eq 45 -a "$HAVE_PERSISTENT" = "no" ]; then + mkdir -p "$PERSISTENT" + if ! mount -t auto -o noexec "${hdpartnr}" "$PERSISTENT"; then + diskfm "$hdpartnr" "jfs xfs ext3" || continue + mount -t auto -o noexec "${hdpartnr}" "$PERSISTENT" || continue + fi + HAVE_PERSISTENT=yes + echo -e "${hdpartnr}\t${PERSISTENT}\tauto\t\tnoauto,noexec\t\t 0 0" >> "/etc/fstab" + elif [ "${partid}" -eq 46 ]; then + mkdir -p "/media/${hdpartnr#/dev/*}" + echo -e "${hdpartnr}\t/media/${hdpartnr#/dev/*}\tauto\t\tnoauto\t\t 0 0" >> "/etc/fstab" + fi + done +done +[ "$HAVE_PERSISTENT" = "no" -a -d "$PERSISTENT" ] && rm -f "$PERSISTENT" + +mount -a + +# Make huge tmpfs if nothing could be mounted for /tmp +if [ "$HAVE_TEMP" = "no" ]; then + mount_temp -t tmpfs -o size=20G none + slxlog "partition-temp" "Running /tmp on tmpfs only!" "/etc/disk.partition" +fi +if [ "$HAVE_SWAP" = "no" ]; then + slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition" +fi + +exit 0 + diff --git a/remote/modules/gdisk/module.build b/remote/modules/gdisk/module.build new file mode 100644 index 00000000..59356ded --- /dev/null +++ b/remote/modules/gdisk/module.build @@ -0,0 +1,19 @@ +#!/bin/bash + +fetch_source() { + : +} + +build() { + COPYLIST="list_dpkg_output" + [ -e "$COPYLIST" ] && rm "$COPYLIST" + + list_packet_files >> "$COPYLIST" + tarcopy "$(cat "$COPYLIST" | sort -u)" "${MODULE_BUILD_DIR}" + +} + +post_copy() { + copy_kernel_modules +} + diff --git a/remote/modules/gdisk/module.conf b/remote/modules/gdisk/module.conf new file mode 100644 index 00000000..3d2254cd --- /dev/null +++ b/remote/modules/gdisk/module.conf @@ -0,0 +1,94 @@ +REQUIRED_MODULES=" + kernel +" +REQUIRED_BINARIES=" + sgdisk + mkfs.xfs + mkfs.ext4 +" +REQUIRED_KERNEL_MODULES=" + kernel/fs/xfs/xfs.ko + kernel/fs/ext4/ext4.ko + kernel/fs/jfs/jfs.ko + kernel/drivers/scsi/3w-9xxx.ko + kernel/drivers/scsi/3w-sas.ko + kernel/drivers/scsi/aacraid/aacraid.ko + kernel/drivers/scsi/aic7xxx/aic79xx.ko + kernel/drivers/scsi/arcmsr/arcmsr.ko + kernel/drivers/scsi/bfa/bfa.ko + kernel/drivers/scsi/bnx2fc/bnx2fc.ko + kernel/drivers/scsi/csiostor/csiostor.ko + kernel/drivers/scsi/fcoe/fcoe.ko + kernel/drivers/scsi/fnic/fnic.ko + kernel/drivers/scsi/hpsa.ko + kernel/drivers/scsi/hptiop.ko + kernel/drivers/scsi/hv_storvsc.ko + kernel/drivers/scsi/initio.ko + kernel/drivers/scsi/isci/isci.ko + kernel/drivers/scsi/libiscsi.ko + kernel/drivers/scsi/lpfc/lpfc.ko + kernel/drivers/scsi/megaraid/megaraid_sas.ko + kernel/drivers/scsi/mpt2sas/mpt2sas.ko + kernel/drivers/scsi/mpt3sas/mpt3sas.ko + kernel/drivers/scsi/mvsas/mvsas.ko + kernel/drivers/scsi/mvumi.ko + kernel/drivers/scsi/pm8001/pm80xx.ko + kernel/drivers/scsi/pmcraid.ko + kernel/drivers/scsi/qla2xxx/qla2xxx.ko + kernel/drivers/scsi/qla4xxx/qla4xxx.ko + kernel/drivers/scsi/scsi_transport_sas.ko + kernel/drivers/scsi/sd_mod.ko + kernel/drivers/scsi/stex.ko + kernel/drivers/scsi/ufs/ufshcd.ko + kernel/drivers/scsi/virtio_scsi.ko + kernel/drivers/scsi/vmw_pvscsi.ko + kernel/drivers/ata/pata_ali.ko + kernel/drivers/ata/pata_it821x.ko + kernel/drivers/ata/pata_acpi.ko + kernel/drivers/ata/pata_atiixp.ko + kernel/drivers/ata/pata_hpt37x.ko + kernel/drivers/ata/pata_ninja32.ko + kernel/drivers/ata/ahci_platform.ko + kernel/drivers/ata/libahci.ko + kernel/drivers/ata/pata_artop.ko + kernel/drivers/ata/pdc_adma.ko + kernel/drivers/ata/pata_marvell.ko + kernel/drivers/ata/sata_promise.ko + kernel/drivers/ata/pata_oldpiix.ko + kernel/drivers/ata/pata_hpt366.ko + kernel/drivers/ata/sata_svw.ko + kernel/drivers/ata/pata_hpt3x3.ko + kernel/drivers/ata/pata_cmd64x.ko + kernel/drivers/ata/pata_sch.ko + kernel/drivers/ata/pata_sis.ko + kernel/drivers/ata/sata_sil.ko + kernel/drivers/ata/pata_it8213.ko + kernel/drivers/ata/pata_pdc202xx_old.ko + kernel/drivers/ata/pata_sil680.ko + kernel/drivers/ata/sata_mv.ko + kernel/drivers/ata/pata_rdc.ko + kernel/drivers/ata/pata_arasan_cf.ko + kernel/drivers/ata/sata_qstor.ko + kernel/drivers/ata/pata_atp867x.ko + kernel/drivers/ata/pata_piccolo.ko + kernel/drivers/ata/ahci.ko + kernel/drivers/ata/sata_sx4.ko + kernel/drivers/ata/libata.ko + kernel/drivers/ata/ata_generic.ko + kernel/drivers/ata/sata_sil24.ko + kernel/drivers/ata/sata_via.ko + kernel/drivers/ata/pata_netcell.ko + kernel/drivers/ata/pata_jmicron.ko + kernel/drivers/ata/sata_nv.ko + kernel/drivers/ata/pata_via.ko + kernel/drivers/ata/acard-ahci.ko + kernel/drivers/ata/sata_vsc.ko + kernel/drivers/ata/pata_hpt3x2n.ko + kernel/drivers/ata/sata_sis.ko + kernel/drivers/ata/sata_uli.ko + kernel/drivers/ata/pata_pdc2027x.ko + kernel/drivers/ata/ata_piix.ko + kernel/drivers/ata/pata_cs5536.ko + kernel/drivers/ata/pata_amd.ko + kernel/drivers/ata/pata_serverworks.ko +" diff --git a/remote/modules/gdisk/module.conf.centos b/remote/modules/gdisk/module.conf.centos new file mode 100644 index 00000000..78fcd634 --- /dev/null +++ b/remote/modules/gdisk/module.conf.centos @@ -0,0 +1,5 @@ +REQUIRED_CONTENT_PACKAGES=" + gdisk + xfsprogs + e2fsprogs +" -- cgit v1.2.3-55-g7522