群晖DSM7.0存储相关逆向 & 强行使用LVM

大类
逆向
技术标签
逆向-Linux
优先级
Medium
开始日期
Jul 20, 2022
状态
Maintaining
Public
Public
最后更新
Jul 22, 2022

群晖存储相关概念

名称
英文名 & 术语
对应Linux文件
群晖存储信息
存储空间
storage space / space
/volumeX
space到pool的对应关系(每个vgX对应volumeX (存储于vg meta中)
存储池
storage pool / pool
/dev/mdX & /dev/vgX
pool的LVM、RAID信息(存储于space map中)
磁盘
disk
/dev/sdX
存储上层信息(具体格式未明)
 

强行使用群晖存储LVM

Debug命令

  • 查看磁盘synoblock metadata:sudo synospace --synoblock -g /dev/sdX
  • 查看各个硬盘序列号、容量等信息:sudo synodisk --enum
  • 查看/dev/mdX对应的底层磁盘:sudo mdadm -v --detail /dev/md5

1. 创建存储空间

  • 普通的群晖Basic存储池便是基于LVM的,因此我们直接创建一个普通的Basic存储池(称为:存储池A)即可,本例对应 /dev/vg2

2. 添加硬盘到LVM

执行LVM操作

  • 将新建立的md初始化为LVM pv,如 pvcreate /dev/md4
  • 将pv加入到A的LVM vg中,如 vgextend /dev/vg2 /dev/md4

更新DSM设置

  • 重启DSM,其会自动将存储池B标记为损毁,而存储池A变为RAID Group
    • 原因为存储池B的md device被A占用
    • notion image
  • 执行 sudo synostgpool --missing-space -e 查看所有的space的uuid等信息,得知存储池B的uuid
    • notion image
  • 执行 sudo synostgpool --missing-space -d [UUID] 删除临时存储池B,这样就只剩存储池A了
 
  • 再次重启DSM,应该可以正常使用,如果报告存储池A损毁(因为RAID device与space的映射可能仍然存在不同步)
    • 同上找到当前存储池A的uuid后 ,或者直接在界面里点重组
      • 也可以执行 sudo synostgpool --missing-space -a [丢失的UUID]
    • 之后即使重启dsm,仍然可以正常工作
  • 后续使用
    • 相同操作可重复多次以添加多个磁盘
    • btrfs可以在线动态大小resize,因此可以支持我们动态更换硬盘

3. 删除磁盘

执行LVM操作

  1. 缩小btrfs大小:sudo btrfs filesystem resize 13G /volume2
  1. 缩小LVM LV大小:sudo lvm lvresize -L 15G /dev/vg2/volume_2
  1. 移动LVM PV数据:sudo lvm pvmove /dev/md3 /dev/md4
  1. 删除VG中的PV:sudo vgreduce vg2 /dev/md3

更新DSM设置

  • 执行sudo mdadm --stop /dev/md3停止待删除磁盘的RAID组
  • 此时群晖中将显示:
    • notion image
  • 修改/var/lib/space/space_table和/run/space/space_table(两文件内容一样,须同时修改),删除”raids”数组下需删除的硬盘
    • notion image

群晖存储相关命令手册参考

群晖在/usr/syno/sbin下放了大量管理命令,其中有一部分为存储管理命令
  • synodisk:管理底层物理磁盘
    • Copyright (c) 2003-2021 Synology Inc. All rights reserved. Usage: synodisk --partition -d DEV_PATH Partition disk -t (s)ystem/(d)ata/(a)ll --write_cache_set --help Show the usage --enum -t internal/ebox/cache/usb/sys Enumerate disks in internal or expansion box --info PATH Query the disk information. Note [PATH] is omitted for single-disk plateform --detect_fs PATH Detect the file system of a device --isssd DEV_PATH Check the disk is ssd or not --standby DEV_PATH Set [DEV_PATH] disk to standby --usbstandby DEV_PATH Set [DEV_PATH] usb disk to standby --get_idle DEV_PATH Get [DEV_PATH] disk idle time --read_temp DEV_PATH Get [DEV_PATH] disk temperature --write_cache_get DEV_PATH Get [DEV_PATH] disk write cache status --is_secure_erasing Check is any disk secure erasing --get_location_form DEV_PATH get device location form(containerID-diskOrder) . e.g. 0-1 --smart_info_get DEV_PATH get the smart information --m2-card-model-get DEV_PATH get m.2 adapter card model --is-perf-testing DEV_PATH_LIST Check is any disk in DEV_PATH_LIST doing performance test or not, the device is split by ','. e.g. /dev/sda,/dev/sdb. the result is 0: not or 1:testing. --check-valid DEV_PATH check whether the disk is valid --is-all-interal-drives-free-to-use check whether the all internal drives are free to use --readonly-get DEV_PATH get read-only mode of disk --readonly-set DEV_PATH RO set the disk to enable/disable read-only --check -p PATH1,PATH2,... [-u] [-m mode] [-c] [-s size] [-r LOWERBOUND,UPPERBOUND]] -u Show details of correct block. (Default is disable) -p Set the location(s) of the target devices. -m Set the operation mode of the checking. The argument can be: 'seq': Sequential writing mode. 'jump' Jump writing mode. -c Do checksum after writing. (Default is disable) -s Set the data block size in bytes based on the format [digital][unit] where [digitial] is a integer and [unit] can be 'K','M' or 'G' representing kilo, meter and giga bytes. If the unit of the value is not assigned, the default unit is 'k'. -r Set the check range. The arguments LOWERBOUND and UPPERBOUND are also represented as [digital][unit]. (Default unit is 'k') The default values of LOWERBOUND and UPPERBOUND are 0 and maximum disk size. Note that LOWERBOUND must always smaller than UPPERBOUND.
  • synostgdisk:管理存储池中,disk的激活与否(对应菜单停用磁盘)
    • Copyright (c) 2003-2021 Synology Inc. All rights reserved. --help show this help page. --get-dump get the disk dump info. --disk-activate <DISK_PATH> activate a deactivated disk, only for debug. --disk-deactivate <DISK_PATH> deactivate the disk.
  • synostgpool:新建存储池
    • Copyright (c) 2003-2021 Synology Inc. All rights reserved. Synology Storage Pool Tool A simple pool to . Usage: synostgpool [COMMAND]... Available command: --help : show this help --create [OPTIONS] DISK_PATH_1 DISK_PATH_2 ... : OPTIONS: -t <POOL_TYPE> : create a unused pool if "single" is given -l <RAID_LEVEL> : determine raid level RAID_LEVEL : SHR1, SHR2, basic, raid0, raid1, raid5, raid6, raid10, linear, raid_f1 -c : whether perform disk check after create -d : <DESC> e.g. synostgpool --create -t single -l 5 -c -d "my storage pool" /dev/sda3 /dev/sdb3 /dev/sdc3 --detected-pool [COMMAND] --missing-space [COMMAND] space table operations --auto-repair DISK_PATH --restore-building-tasks : respawn process for committed tasks --misc <OPTION> please use synostgpool --misc -h to see futher introduction $ sudo synostgpool --misc -h Copyright (c) 2003-2021 Synology Inc. All rights reserved. Synology Storage Pool Tool Misc Action Usage: synostgpool --misc <OPTION> Available OPTION: --help|-h : show this help --get-drive-role|-r : get the role of all drives --hotspare-get-by-space|-s <SPACE_PATH> : Get hotspare drives that protect the SPACE_PATH --get-pool-info|-i : get the json info of all pools
  • synostgreclaim:空间回收
    • Usage: synostgreclaim [OPTION] --get-runnable [--timestamp=<t>] Check runnable from configs. --enable-task [--force] Enable space reclaim task. --disable-task [--force] Disable space reclaim task. --update-state [--force] Enable/Disable space reclaim task by schedule config. --get-state Get state of space recaim task (idle/running/pause/delay) --get-num-subvol Get number of remaining subvolume --get-all-status [--verbose] Print all status of space reclaim task. --delay <n> Delay space reclaim task <n> seconds. --cancel-delay Cancel delay. --get-delay-time Get delay end timestamp. --set-schedule <schedule> Set week schedule by a string has 7*24 0/1s string [--option=run_all_time/run_setting_time] choose schedule runtime option --dump-config Dump config to stdout. --init-config Init config file. --udc Internal command for synology service --check-num-subvol Trigger daemon check are there too many deleted queue.
  • synostgtask:存储空间任务管理,应该可以用来暂停一些任务
    • $ sudo synostgtask --help Copyright (c) 2003-2021 Synology Inc. All rights reserved. Synology Storage Manager Task Command Usage: synostgtask <OPTION> Available OPTION: --resume [--async] : resume all interrupted tasks, fork to background on async mode --reload [--async] --uuid=<UUID> : reload certain task jornal file --help
  • synostgvolume:优雅版存储空间卸载工具
    • Copyright (c) 2003-2021 Synology Inc. All rights reserved. Synology Volume Tool for Storage Manager Usage: synostgvolume [COMMAND]... Available command: --help : show this help --is-writable VOLUME_PATH: check whether volume is writable (i.e. fs/cache/pool are fine) e.g. synostgvolume --is-wriable /volume1 --unmount [-p <volume path>] [-a] : unmount volume with stopping service e.g. unmount specified volume: synostgvolume --unmount -p /volume1 unmount all volume: synostgvolume --unmount -a --report-ext4-fsck-done --path=<volume device path> [--fsck-exit-code=<integer>] : report fsck done and clear volume suggestion flags e.g. synostgvolume --report-ext4-fsck-done --path=/dev/mapper/cachedev_1 --fsck-exit-code=0
  • synostorage:核心回调
    • Copyright (c) 2003-2021 Synology Inc. All rights reserved. SYNOPSIS synostorage --help : show this help synostorage --hotspare : hotspare management synostorage --mail : mail notification synostorage --lock : lock management synostorage --vol-mounted : volume mount hook synostorage --vol-unmounting : volume unmount hook synostorage --notify-idle-drive : detect all idle drives and sent notification per drive synostorage --notify-drive-bundle-update : detect all bundle drive and check update synostorage --notify-fsck-skipped : detect there is a notification for fsck skip this boot progress synostorage --upgrade-space-busy-hard-check : check whether any space is busy and need to block DSM upgrade
  • synospace:存储空间管理
    • $ sudo synospace --help Copyright (c) 2003-2021 Synology Inc. All rights reserved. Synology Space Test Tool A complementary command line program for tweaking space settings. Usage: synospace [<group>] <command> [option] Available group/command: synospace --help Show the help synospace <command> --help Show detail help in specified command synospace --lv-meta <command> [option] <VG_PATH> Manage lv metadata synospace --meta <command> [option] [<SPACE_PATH>] Manage space metadata synospace --enum [option] Enumerate space infomation synospace --synoblock <command> [option] <DISK_PATH> Manage syno-block synospace --root-block <command> [option] <DISK_PATH> Manage root-block synospace --map-file <command> Manage space map file synospace --build_file <command> Manage space build file synospcae --partition <command> [option] <DISK_PATH...> Partition disk synospace --lock <command> Manage lock file synospace --misc <command> Just misc synospace --check-part-syno-blk Check all disks' partition layout version and synoblock offset synospace --fast-repair <VG_PATH|MD_PATH> Feed fast-repair hints to storage pool synospace --feed-hint <VG_PATH|MD_PATH> Feed filesystem unused hints to storage pool, regardless of pool's supporting of repair synospace --disk-replace <command> For replace failed drive synospace --auto-scrubbing Trigger bootup auto scrubbing synospace --stop-all-spaces unload all volume and underneath block device synospace --start-all-spaces start all block device and mount above volume synospace --enum-raid [-f] scan raid obj, using -f to enum by read disk instead of cache synospace --update-raid-sb-cache update raid superblock for all disks synospace --history-diff [--detail] Show space history diff synospace --switch-over <--start|--end> Notify HA switch over start/end. Usage: synospace --misc <command> Available command: synospace --misc --get-unused-path|-u <STORAGE_TYPE:COUNT> Get unused path according type. STORGAE_TYPE : Storage type. Valid input: lvm_pool, lvm_shr, raid, volume COUNT : Total count you need.