Closed grembo closed 7 months ago
@bretton Maybe you could share some example output of
lsblk
on your test machines.
Hetzner server 1
root@rescue ~ # lsblk -no NAME,TYPE,TRAN
loop0 loop
sda disk sata
├─sda1 part
├─sda2 part
├─sda3 part
└─sda4 part
sdb disk sata
├─sdb1 part
├─sdb2 part
├─sdb3 part
└─sdb4 part
Hetzner server 2
root@rescue ~ # lsblk -no NAME,TYPE,TRAN
loop0 loop
sda disk sata
├─sda1 part
├─sda2 part
├─sda3 part
└─sda4 part
sdb disk sata
├─sdb1 part
├─sdb2 part
├─sdb3 part
└─sdb4 part
sdc disk sata
├─sdc1 part
├─sdc2 part
├─sdc3 part
└─sdc4 part
sdd disk sata
├─sdd1 part
├─sdd2 part
├─sdd3 part
└─sdd4 part
xneelo I don't have the same command format, just output
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 7.3T 0 disk
sdb 8:16 0 894.3G 0 disk
├─sdb1 8:17 0 1M 0 part
├─sdb2 8:18 0 488M 0 part
│ └─md0 9:0 0 487M 0 raid1 /boot
└─sdb3 8:19 0 893.8G 0 part
└─md1 9:1 0 893.6G 0 raid1 /
sdc 8:32 0 894.3G 0 disk
├─sdc1 8:33 0 1M 0 part
├─sdc2 8:34 0 488M 0 part
│ └─md0 9:0 0 487M 0 raid1 /boot
└─sdc3 8:35 0 893.8G 0 part
└─md1 9:1 0 893.6G 0 raid1 /
sdd 8:48 0 7.3T 0 disk
private server 1, ubuntu, not a rescue system
# lsblk -no NAME,TYPE,TRAN
loop0 loop
loop1 loop
loop2 loop
loop3 loop
loop4 loop
loop5 loop
loop6 loop
loop7 loop
loop8 loop
loop10 loop
sda disk
├─sda1 part
└─sda2 part
└─md0 raid1
└─md0p1 part
sdb disk
├─sdb1 part
└─sdb2 part
└─md0 raid1
└─md0p1 part
sdc disk
├─sdc1 part
└─sdc9 part
sdd disk
├─sdd1 part
└─sdd9 part
sde disk
├─sde1 part
└─sde9 part
sdf disk
├─sdf1 part
└─sdf9 part
sdg disk
├─sdg1 part
└─sdg9 part
sdh disk
├─sdh1 part
└─sdh9 part
nbd0 disk
├─nbd0p1 part
└─nbd0p2 part
nvme0n1 disk nvme
└─nvme0n1p1 part nvme
nvme1n1 disk nvme
└─nvme1n1p1 part nvme
nvme2n1 disk nvme
├─nvme2n1p1 part nvme
└─nvme2n1p2 part nvme
nvme3n1 disk nvme
└─nvme3n1p1 part nvme
private server 2, ubuntu, not a rescue console
lsblk -no NAME,TYPE,TRAN
sda disk sata
├─sda1 part
├─sda2 part
│ └─md0 raid1
└─sda3 part
sdb disk sata
├─sdb1 part
├─sdb2 part
│ └─md0 raid1
└─sdb3 part
sdc disk sata
└─md127 raid1
sdd disk sata
└─md127 raid1
loop0 loop
loop1 loop
loop2 loop
loop3 loop
loop4 loop
loop5 loop
loop6 loop
for more than four drives, chatgpt had suggested the following will work
qemu-system-x86_64 \
... # other options
# IDE Drives
-drive file=/dev/sda,format=raw,if=ide \
-drive file=/dev/sdb,format=raw,if=ide \
-drive file=/dev/sdc,format=raw,if=ide \
-drive file=/dev/sdd,format=raw,if=ide \
# SATA Drives
-device ahci,id=ahci0 \
-drive file=/dev/sde,format=raw,if=none,id=drive-sde \
-device ide-drive,drive=drive-sde,bus=ahci0.0 \
-drive file=/dev/sdf,format=raw,if=none,id=drive-sdf \
-device ide-drive,drive=drive-sdf,bus=ahci0.1 \
# VirtIO Drives
-drive file=/dev/sdg,format=raw,if=none,id=drive-sdg \
-device virtio-blk-pci,drive=drive-sdg \
-drive file=/dev/sdh,format=raw,if=none,id=drive-sdh \
-device virtio-blk-pci,drive=drive-sdh \
... # other options
but it needs some tricky logic to make this automatic
not all rescue systems will have the json output option for lsblk
, and not sure if useful
lsblk from util-linux 2.27.1
Usage:
lsblk [options] [<device> ...]
List information about block devices.
Options:
-a, --all print all devices
-b, --bytes print SIZE in bytes rather than in human readable format
-d, --nodeps don't print slaves or holders
-D, --discard print discard capabilities
-e, --exclude <list> exclude devices by major number (default: RAM disks)
-f, --fs output info about filesystems
-i, --ascii use ascii characters only
-I, --include <list> show only devices with specified major numbers
-J, --json use JSON output format
-l, --list use list format output
-m, --perms output info about permissions
-n, --noheadings don't print headings
-o, --output <list> output columns
-O, --output-all output all columns
-p, --paths print complete device path
-P, --pairs use key="value" output format
-r, --raw use raw output format
-s, --inverse inverse dependencies
-S, --scsi output info about SCSI devices
-t, --topology output info about topology
-x, --sort <column> sort output by <column>
-h, --help display this help and exit
-V, --version output version information and exit
Available columns (for --output):
NAME device name
KNAME internal kernel device name
MAJ:MIN major:minor device number
FSTYPE filesystem type
MOUNTPOINT where the device is mounted
LABEL filesystem LABEL
UUID filesystem UUID
PARTTYPE partition type UUID
PARTLABEL partition LABEL
PARTUUID partition UUID
PARTFLAGS partition flags
RA read-ahead of the device
RO read-only device
RM removable device
HOTPLUG removable or hotplug device (usb, pcmcia, ...)
MODEL device identifier
SERIAL disk serial number
SIZE size of the device
STATE state of the device
OWNER user name
GROUP group name
MODE device node permissions
ALIGNMENT alignment offset
MIN-IO minimum I/O size
OPT-IO optimal I/O size
PHY-SEC physical sector size
LOG-SEC logical sector size
ROTA rotational device
SCHED I/O scheduler name
RQ-SIZE request queue size
TYPE device type
DISC-ALN discard alignment offset
DISC-GRAN discard granularity
DISC-MAX discard max bytes
DISC-ZERO discard zeroes data
WSAME write same max bytes
WWN unique storage identifier
RAND adds randomness
PKNAME internal parent kernel device name
HCTL Host:Channel:Target:Lun for SCSI
TRAN device transport type
SUBSYSTEMS de-duplicated chain of subsystems
REV device revision
VENDOR device vendor
For more details see lsblk(8).
using this version of script, lsblk output as text file inputs and trying different ones
#!/bin/bash
#
# using lsblk output in multiple text files, test
# check for drives
echo "Searching sd[abcd] and nvme"
set +e
# Capture the complete output of lsblk for debugging
lsblk_output=$(cat disk1.txt)
# Get nvme drives first
drive_type="NVMe"
detected_drives=$(echo "$lsblk_output" | awk '/^nvme/ && $2 == "disk" {print $1}')
# If no nvme drives found, detect all list all sd* drives, excluding CD-ROM and USB drives
if [ -z "$detected_drives" ]; then
drive_type="SATA"
detected_drives=$(echo "$lsblk_output" | \
awk '$2 == "disk" && $3 != "usb" && $3 != "sr" && $1 ~ /^sd/ {print $1}')
fi
set -e
echo "Detected drives: $detected_drives"
# array holding list of disks to pass to qemu
disks=()
for drive in $detected_drives; do
echo "Adding $drive_type drive: $drive"
disks+=( "-drive" "file=/dev/$drive,format=raw" )
done
echo "Configured disks: ${disks[*]}"
if [ ${#disks[@]} -eq 0 ]; then
exit_error "Could not find any disks"
fi
# arguments to qemu
qemu_args=(\
"${disks[@]}" \
)
echo "Qemu options: ${qemu_args[@]}"
test 1
Searching sd[abcd] and nvme
Detected drives: sda
sdb
Adding SATA drive: sda
Adding SATA drive: sdb
Configured disks: -drive file=/dev/sda,format=raw -drive file=/dev/sdb,format=raw
Qemu options: -drive file=/dev/sda,format=raw -drive file=/dev/sdb,format=raw
test 2
Searching sd[abcd] and nvme
Detected drives: sda
sdb
sdc
sdd
Adding SATA drive: sda
Adding SATA drive: sdb
Adding SATA drive: sdc
Adding SATA drive: sdd
Configured disks: -drive file=/dev/sda,format=raw -drive file=/dev/sdb,format=raw -drive file=/dev/sdc,format=raw -drive file=/dev/sdd,format=raw
Qemu options: -drive file=/dev/sda,format=raw -drive file=/dev/sdb,format=raw -drive file=/dev/sdc,format=raw -drive file=/dev/sdd,format=raw
test 3
Searching sd[abcd] and nvme
Detected drives: nvme0n1
nvme1n1
nvme2n1
nvme3n1
Adding NVMe drive: nvme0n1
Adding NVMe drive: nvme1n1
Adding NVMe drive: nvme2n1
Adding NVMe drive: nvme3n1
Configured disks: -drive file=/dev/nvme0n1,format=raw -drive file=/dev/nvme1n1,format=raw -drive file=/dev/nvme2n1,format=raw -drive file=/dev/nvme3n1,format=raw
Qemu options: -drive file=/dev/nvme0n1,format=raw -drive file=/dev/nvme1n1,format=raw -drive file=/dev/nvme2n1,format=raw -drive file=/dev/nvme3n1,format=raw
test 4
Searching sd[abcd] and nvme
Detected drives: sda
sdb
sdc
sdd
Adding SATA drive: sda
Adding SATA drive: sdb
Adding SATA drive: sdc
Adding SATA drive: sdd
Configured disks: -drive file=/dev/sda,format=raw -drive file=/dev/sdb,format=raw -drive file=/dev/sdc,format=raw -drive file=/dev/sdd,format=raw
Qemu options: -drive file=/dev/sda,format=raw -drive file=/dev/sdb,format=raw -drive file=/dev/sdc,format=raw -drive file=/dev/sdd,format=raw
live at qa.sh for now
wget --no-check-certificate https://depenguin.me/qa.sh
chmod +x qa.sh
./run.sh https://example.org/mypubkey
just for interests sake
AWS host
lsblk -no NAME,TYPE,TRAN
xvda disk
└─xvda1 part
very old Ubuntu host, upgraded to Ubuntu 16
sda disk sata
└─isw_dhgacgdjih_vg0 dmraid
├─isw_dhgacgdjih_vg0p1 part
├─isw_dhgacgdjih_vg0p2 part
└─isw_dhgacgdjih_vg0p5 part
├─vg0-root lvm
├─vg0-var lvm
├─vg0-swap lvm
├─vg0-srv lvm
├─vg0-xxxxxxxx0_srv lvm
└─vg0-yyyyyyy0_srv lvm
sdb disk sata
└─isw_dhgacgdjih_vg0 dmraid
├─isw_dhgacgdjih_vg0p1 part
├─isw_dhgacgdjih_vg0p2 part
└─isw_dhgacgdjih_vg0p5 part
├─vg0-root lvm
├─vg0-var lvm
├─vg0-swap lvm
├─vg0-srv lvm
├─vg0-xxxxxxxx0_srv lvm
└─vg0-yyyyyyy0_srv lvm
sr0 rom sata
Qemu/KVM Ubuntu host
lsblk -no NAME,TYPE,TRAN
loop0 loop
loop1 loop
loop2 loop
loop3 loop
loop5 loop
loop6 loop
loop7 loop
loop8 loop
sr0 rom ata
vda disk
├─vda1 part
└─vda2 part
live at qa.sh for now
test on four disk system works using qa.sh and ansible script, unattended install, raid10
root@server1:~ # zpool status
pool: zroot
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
zroot ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
ada0p4 ONLINE 0 0 0
ada1p4 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
ada2p4 ONLINE 0 0 0
ada3p4 ONLINE 0 0 0
errors: No known data errors
thanks @grembo all seems good!
woops, forgot to check
# please bump version on change
VERSION="v0.0.14"
updated on site run.sh
This brings back using an array directly, does some code cleanup.
It fixes a bug - please the comments (and questions) within the review.
I didn't have a chance to test it in practice, but the changes should be sound 🤞
@bretton Maybe you could share some example output of
lsblk
on your test machines.@bretton Please check even the outdated comments (especially around Hetzner)