From 353a9e16d88bcb4afdab0fcb9b7a317a02e2803e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 17:10:37 +0100 Subject: [PATCH 01/14] Add script to remove all partitions --- remove-all-partitions | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 remove-all-partitions diff --git a/remove-all-partitions b/remove-all-partitions new file mode 100644 index 0000000..798d0a6 --- /dev/null +++ b/remove-all-partitions @@ -0,0 +1,10 @@ +#!/bin/sh + +if [ $# -ne 1 ]; then + echo $0 disk-to-be-deleted + exit 1 +fi + +disk=$1 + +sgdisk -Z "$disk" From 5ff9b7a985728c81738b6dfb11155e2b187ba806 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 17:20:03 +0100 Subject: [PATCH 02/14] ++ chmod --- ceph-pool-create | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ceph-pool-create diff --git a/ceph-pool-create b/ceph-pool-create old mode 100644 new mode 100755 From 0fe06a7f714d5ee05854bc47248056d70e5630aa Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 17:28:44 +0100 Subject: [PATCH 03/14] Also give remove it's x bit --- remove-all-partitions | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 remove-all-partitions diff --git a/remove-all-partitions b/remove-all-partitions old mode 100644 new mode 100755 From 5595038016a76513aff3cbce29fe66e8875e9f3a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 17:36:30 +0100 Subject: [PATCH 04/14] ++ new dangerous script :-) --- remove-all-partitions-from-all-disks | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 remove-all-partitions-from-all-disks diff --git a/remove-all-partitions-from-all-disks b/remove-all-partitions-from-all-disks new file mode 100755 index 0000000..7df5220 --- /dev/null +++ b/remove-all-partitions-from-all-disks @@ -0,0 +1,5 @@ +#!/bin/sh + +for disk in $(fdisk -l | grep "^Disk /dev" | sed -e 's/Disk //' -e 's/:.*//'); do + sgdisk -Z "$disk" +done From c849d319b401a983cb8ef9ea49cda2064de5eec4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 18:54:19 +0100 Subject: [PATCH 05/14] Add script to create osds for all disks --- ceph-osd-create-on-all-disks | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ceph-osd-create-on-all-disks diff --git a/ceph-osd-create-on-all-disks b/ceph-osd-create-on-all-disks new file mode 100644 index 0000000..ebc932d --- /dev/null +++ b/ceph-osd-create-on-all-disks @@ -0,0 +1,9 @@ +#!/bin/sh + +lsblk -b | awk '/^sd/ { print $1 " " $4/(1024^4) }' | +( + while read disk size; do + /opt/ungleich-tools/ceph-osd-create-start /dev/$disk hdd $size + + done +) From a92f1f798d78dab2b4d62ccff0266f3e14694ba1 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 19:51:48 +0100 Subject: [PATCH 06/14] Add automatic weight detection --- ceph-osd-create-start | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ceph-osd-create-start b/ceph-osd-create-start index 405b3c2..3b22958 100755 --- a/ceph-osd-create-start +++ b/ceph-osd-create-start @@ -20,15 +20,15 @@ magic="ceph osd volume v026" set -x set -e -if [ $# -ne 3 ]; then - echo "$0 disk class osdweight" +if [ $# -lt 2 ]; then + echo "$0 disk class [osdweight]" echo "class = hdd or ssd" exit 1 fi export DEV=$1;shift export CLASS=$1; shift -export WEIGHT=$1; shift + uuid_metadata=$(uuidgen) uuid_block=$(uuidgen) @@ -58,7 +58,6 @@ lastpart=$(gdisk -l $DEV | tail -n1 | awk '{ print $1 }') --mbrtogpt -- $DEV /sbin/udevadm settle --timeout=600 - /sbin/mkfs -t xfs -f -i size=2048 -- "$dev_metadata" mountpath=/var/lib/ceph/osd/ceph-${osd_id} @@ -85,6 +84,13 @@ touch "$mountpath/sysvinit" ceph-osd --cluster ceph -i "${osd_id}" --mkfs chown -R ceph:ceph "$mountpath" +if [ $# -eq 1 ]; then + WEIGHT=$1; shift +else + nodev=$(echo $dev_block | sed 's,/dev/,,') + WEIGHT=$(lsblk -l -b | awk "/^$nodev/ { print \$4/(1024^4) }") +fi + ceph osd crush add osd.${osd_id} ${WEIGHT} host=$(hostname) echo "$metadata_dev /var/lib/ceph/osd/ceph-${osd_id} xfs noatime 0 0" >> /etc/fstab From 59028e1c4eefa75049e8a3fe06f021252484bce2 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 20:48:22 +0100 Subject: [PATCH 07/14] Kick out udevadm to avoid such auto mounts + dev_metadata=/dev/disk/by-partuuid/55015fcb-dcae-4ced-86f2-c46a0e22ae17 + dev_block=/dev/disk/by-partuuid/35964ca6-b825-4cef-a784-cc4531cd73f2 + /sbin/sgdisk --new=0:0:+100M --change-name=0:ceph data --partition-guid=0:55015fcb-dcae-4ced-86f2-c46a0e22ae17 --typecode=0:4fbd7e29-9d25-41b8-afd0-062c0ceff05d --mbrtogpt -- /dev/sdb Creating new GPT entries. Setting name! partNum is 0 REALLY setting name! The operation has completed successfully. + /sbin/udevadm settle --timeout=600 this triggers a mount!!! Feb 18 19:48:32 unconfigured-host kernel: [ 1608.438792] sdb: sdb1 Feb 18 19:48:33 unconfigured-host kernel: [ 1609.490182] XFS (sdb1): Mounting V5 Filesystem Feb 18 19:48:33 unconfigured-host kernel: [ 1609.500185] XFS (sdb1): Ending clean mount root@unconfigured-host:~# mount | grep sdb /dev/sdb1 on /var/lib/ceph/osd/ceph-0 type xfs (rw,noatime,attr2,inode64,noquota) That's a previous mount point that did not exist prior to calling udevadm. --- ceph-osd-create-start | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ceph-osd-create-start b/ceph-osd-create-start index 3b22958..01714f1 100755 --- a/ceph-osd-create-start +++ b/ceph-osd-create-start @@ -43,20 +43,20 @@ dev_block="/dev/disk/by-partuuid/$uuid_block" --typecode=0:4fbd7e29-9d25-41b8-afd0-062c0ceff05d \ --mbrtogpt -- $DEV -/sbin/udevadm settle --timeout=600 - +hdparm -z "$DEV" # Using gdisk --largest-new does not change the name or set guid; # So use 2 steps instead /sbin/sgdisk --largest-new=0 --mbrtogpt -- $DEV -/sbin/udevadm settle --timeout=600 +hdparm -z "$DEV" lastpart=$(gdisk -l $DEV | tail -n1 | awk '{ print $1 }') /sbin/sgdisk --change-name="${lastpart}:ceph block" \ --partition-guid="${lastpart}:$uuid_block" \ --typecode="${lastpart}:cafecafe-9b03-4f30-b4c6-b4b80ceff106" \ --mbrtogpt -- $DEV -/sbin/udevadm settle --timeout=600 +hdparm -z "$DEV" + /sbin/mkfs -t xfs -f -i size=2048 -- "$dev_metadata" From 32636437b71ac8ad0e6f258379027eeb87a3f662 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 20:51:02 +0100 Subject: [PATCH 08/14] hdparm fails if called to often to fast: The operation has completed successfully. + hdparm -z /dev/sdb /dev/sdb: re-reading partition table + /sbin/sgdisk --largest-new=0 --mbrtogpt -- /dev/sdb Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. + hdparm -z /dev/sdb /dev/sdb: re-reading partition table BLKRRPART failed: Device or resource busy --- ceph-osd-create-start | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ceph-osd-create-start b/ceph-osd-create-start index 01714f1..0d06a3d 100755 --- a/ceph-osd-create-start +++ b/ceph-osd-create-start @@ -43,19 +43,21 @@ dev_block="/dev/disk/by-partuuid/$uuid_block" --typecode=0:4fbd7e29-9d25-41b8-afd0-062c0ceff05d \ --mbrtogpt -- $DEV -hdparm -z "$DEV" +sleep 2 ; hdparm -z "$DEV" # Using gdisk --largest-new does not change the name or set guid; # So use 2 steps instead /sbin/sgdisk --largest-new=0 --mbrtogpt -- $DEV -hdparm -z "$DEV" + +sleep 2 ; hdparm -z "$DEV" lastpart=$(gdisk -l $DEV | tail -n1 | awk '{ print $1 }') /sbin/sgdisk --change-name="${lastpart}:ceph block" \ --partition-guid="${lastpart}:$uuid_block" \ --typecode="${lastpart}:cafecafe-9b03-4f30-b4c6-b4b80ceff106" \ --mbrtogpt -- $DEV -hdparm -z "$DEV" +sleep 2 ; hdparm -z "$DEV" + /sbin/mkfs -t xfs -f -i size=2048 -- "$dev_metadata" From c8425833afa785c419dadaef50e930dce98b83a8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 21:03:00 +0100 Subject: [PATCH 09/14] Need udevadm to create device links --- ceph-osd-create-start | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ceph-osd-create-start b/ceph-osd-create-start index 0d06a3d..a0d957a 100755 --- a/ceph-osd-create-start +++ b/ceph-osd-create-start @@ -42,23 +42,20 @@ dev_block="/dev/disk/by-partuuid/$uuid_block" --partition-guid="0:$uuid_metadata" \ --typecode=0:4fbd7e29-9d25-41b8-afd0-062c0ceff05d \ --mbrtogpt -- $DEV - -sleep 2 ; hdparm -z "$DEV" +/sbin/udevadm settle --timeout=600 # Using gdisk --largest-new does not change the name or set guid; # So use 2 steps instead /sbin/sgdisk --largest-new=0 --mbrtogpt -- $DEV +/sbin/udevadm settle --timeout=600 -sleep 2 ; hdparm -z "$DEV" lastpart=$(gdisk -l $DEV | tail -n1 | awk '{ print $1 }') /sbin/sgdisk --change-name="${lastpart}:ceph block" \ --partition-guid="${lastpart}:$uuid_block" \ --typecode="${lastpart}:cafecafe-9b03-4f30-b4c6-b4b80ceff106" \ --mbrtogpt -- $DEV -sleep 2 ; hdparm -z "$DEV" - - +/sbin/udevadm settle --timeout=600 /sbin/mkfs -t xfs -f -i size=2048 -- "$dev_metadata" From 7829f82fb3c20f6262a45e74c0e22fa02d3bccdd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 21:06:28 +0100 Subject: [PATCH 10/14] Get the real device name to match wtih lsblk --- ceph-osd-create-start | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ceph-osd-create-start b/ceph-osd-create-start index a0d957a..e38db4e 100755 --- a/ceph-osd-create-start +++ b/ceph-osd-create-start @@ -86,7 +86,8 @@ chown -R ceph:ceph "$mountpath" if [ $# -eq 1 ]; then WEIGHT=$1; shift else - nodev=$(echo $dev_block | sed 's,/dev/,,') + devname=$(readlink -f $dev_block) + nodev=$(echo $devname | sed 's,/dev/,,') WEIGHT=$(lsblk -l -b | awk "/^$nodev/ { print \$4/(1024^4) }") fi From 527bfb197ee4e4942ba6b2c5e2341363f14f0665 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 21:17:35 +0100 Subject: [PATCH 11/14] Add tool to create fresh gpt table --- disk-create-fresh-gpt | 5 +++++ remove-all-partitions | 1 + 2 files changed, 6 insertions(+) create mode 100644 disk-create-fresh-gpt diff --git a/disk-create-fresh-gpt b/disk-create-fresh-gpt new file mode 100644 index 0000000..76d8a1a --- /dev/null +++ b/disk-create-fresh-gpt @@ -0,0 +1,5 @@ +#!/bin/sh + +disk=$1 + +printf 'g\nw' | fdisk $disk diff --git a/remove-all-partitions b/remove-all-partitions index 798d0a6..60456d4 100755 --- a/remove-all-partitions +++ b/remove-all-partitions @@ -8,3 +8,4 @@ fi disk=$1 sgdisk -Z "$disk" +dd if=/dev/zero of=$disk bs=1M count=10 From fc1daf86214b0bbd75cab53a2e67e2efdb06f4cf Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 21:18:14 +0100 Subject: [PATCH 12/14] + permissions --- ceph-osd-create-on-all-disks | 0 disk-create-fresh-gpt | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ceph-osd-create-on-all-disks mode change 100644 => 100755 disk-create-fresh-gpt diff --git a/ceph-osd-create-on-all-disks b/ceph-osd-create-on-all-disks old mode 100644 new mode 100755 diff --git a/disk-create-fresh-gpt b/disk-create-fresh-gpt old mode 100644 new mode 100755 From 8f777acf420600ac79c56921531bb370cd40a3fd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 21:48:29 +0100 Subject: [PATCH 13/14] Allow pool creation --- ceph-keyring-create-initial | 2 +- ceph-pool-create | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ceph-keyring-create-initial b/ceph-keyring-create-initial index cf81d3d..43d4eb9 100755 --- a/ceph-keyring-create-initial +++ b/ceph-keyring-create-initial @@ -15,4 +15,4 @@ ceph-authtool "$fname" --gen-key -n client.admin \ --cap mon 'allow *' \ --cap osd 'allow *' \ --cap mgr 'allow *' \ - --cap mds 'allow' + --cap mds 'allow *' diff --git a/ceph-pool-create b/ceph-pool-create index 891347e..197c9e1 100755 --- a/ceph-pool-create +++ b/ceph-pool-create @@ -1,9 +1,14 @@ #!/bin/sh -pool=$1; shift +if [ $# -ne 2 ]; then + echo "$0 name pgs" + exit 1 +fi echo "This script is not finished to create pool $pool" -exit 1 +name=$1; shift +pg=$1;shift -ceph osd pool application enable +ceph osd pool create "$name" "$pg" +ceph osd pool application enable "$name" rbd From 8fdebd0c45458c3c6d794b0ac54c0e931b3e1a77 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Feb 2018 21:49:26 +0100 Subject: [PATCH 14/14] Remove warning --- ceph-pool-create | 2 -- 1 file changed, 2 deletions(-) diff --git a/ceph-pool-create b/ceph-pool-create index 197c9e1..531f236 100755 --- a/ceph-pool-create +++ b/ceph-pool-create @@ -5,8 +5,6 @@ if [ $# -ne 2 ]; then exit 1 fi -echo "This script is not finished to create pool $pool" - name=$1; shift pg=$1;shift