2021年09月05日

ubuntu qemu raw partition

soft raid

linux下的玩法就是多啊,用2个raw image文件,挂上loop设备,然后再用 JBOD 模式(即 linear) 的soft raid,拼成一个虚拟的盘,已现实单独访问一个raw physical partition。

由于单独的partition是没有 gpt 分区表的,需要为单独的partition造出一个gpt分区表了。

mdadm --detail /dev/md0
/dev/md0:
           Version : 
     Creation Time : Mon Sep  6 09:49:32 2021
        Raid Level : linear
        Array Size : 101811712 (97.10 GiB 104.26 GB)
      Raid Devices : 3
     Total Devices : 3

             State : clean 
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

          Rounding : 512K

Consistency Policy : none

    Number   Major   Minor   RaidDevice State
       0       7        0        0      active sync   /dev/loop0
       1     259        1        1      active sync   /dev/nvme0n1p1
       2       7        1        2      active sync   /dev/loop1
mdadm --examine /dev/md0
/dev/md0:
   MBR Magic : aa55
Partition[0] :    203623423 sectors at            1 (type ee)
parted /dev/md0 unit s print
Model: Linux Software RAID Array (md)
Disk /dev/md0: 203623424s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start    End         Size        File system  Name     Flags
 1      2048s    204799s     202752s     fat32        EFI      boot, esp
 2      204800s  203622283s  203417484s  ntfs         Windows  msftdata
parted /dev/nvme0n1 unit s print
# 省略...
Disk /dev/nvme0n1: 1000215216s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start       End          Size        File system     Name                  Flags
 1      239616s     203638667s   203399052s  ntfs            Basic data partition  msftdata
# 省略...
~# fdisk -l /dev/loop0
GPT PMBR size mismatch (203623423 != 204799) will be corrected by write.
Disk /dev/loop0: 100 MiB, 104857600 bytes, 204800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device       Boot Start    End Sectors  Size Id Type
/dev/loop0p1          1 204799  204799  100M ee GPT
~# fdisk -l /dev/loop1
Disk /dev/loop1: 10 MiB, 10485760 bytes, 20480 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

204800 + 203399052 + 20480 = 203624332

为什么少了908个扇区? 203624332 - 203623424 = 908

这里才少34个扇区,正好是gpt的备份 https://superuser.com/questions/1117683/why-is-mdadm-shorting-me-33-sectors-on-my-linear-virtual-software-raid-device?rq=1

最后34个扇区是gpt分区的备份分区头和备份分区表项。为什么我会少了908个扇区?