Skip to content

Instantly share code, notes, and snippets.

@cllu
Last active December 5, 2021 11:25
Show Gist options
  • Save cllu/5da648850ecfd30211bba140b132e824 to your computer and use it in GitHub Desktop.
Save cllu/5da648850ecfd30211bba140b132e824 to your computer and use it in GitHub Desktop.

I want to mount a previous Synology basic volume (wasn't using RAID or SHR) to copy data to a new drive.

Plug it in the USB port doesn't work, showing (Partition 1 does not start on phyical sector boundary).

# fdisk -l
Disk /dev/sdr: 2.7 TiB, 3000558944256 bytes, 5860466688 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start        End    Sectors Size Id Type
/dev/sdr1           1 4294967295 4294967295   2T ee GPT

Partition 1 does not start on physical sector boundary.

Calling mount would gives another error:

# mount /dev/sdr oldVolume/
mount: /dev/sdr: can't read superblock

The issue is that there is MD superblock at the beginning of the disk. This StackOverflow anwser provides a solution, which is to use a loop mount to mount a partition as a device and skip the superblock. If we use losetup /dev/loop0 /dev/sdd3 -o 1048576 directly, it is gonna mount the first partition, which is a 2.3G partition that contain system files (hidden from Synology UI). What I am interested in is the actual data partition. To find the offset for that, we can look at other drives that has similar partition structure:

# fdisk -l
Disk /dev/sda: 894.3 GiB, 960197124096 bytes, 1875385008 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x29b632b9

Device     Boot   Start        End    Sectors   Size Id Type
/dev/sda1          2048    4982527    4980480   2.4G fd Linux raid autodetect
/dev/sda2       4982528    9176831    4194304     2G fd Linux raid autodetect
/dev/sda3       9437184 1875180191 1865743008 889.7G fd Linux raid autodetect

/dev/sda is another 1T drive in the system. From the above, we can see the data partition starts at 9437184th block. Since we have 512 bytes per block, the byte offset for the data partition is 9437184 * 512 = 4831838208. Thus we can use the following to mount the partition (make sure /dev/loop1000 and /dev/md1000 don't exist):

losetup /dev/loop1000 /dev/sdr -o 4831838208
mdadm --assemble --run /dev/md1000 /dev/loop1000
mount /dev/loop1003 /mnt/oldVolume
@yitong-ovo
Copy link

yitong-ovo commented Nov 2, 2020

Very helpful to me, thank you.
This is my partition structure(in Synology DSM 6.2), and the above mounting method also works in this situation.

Disk /dev/sdf: 10.9 TiB, 12000138625024 bytes, 23437770752 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0AD5FFBE-A9A0-4B86-B080-B3434CDBDB63

Device       Start         End     Sectors  Size Type
/dev/sdf1     2048     4982527     4980480  2.4G Linux RAID
/dev/sdf2  4982528     9176831     4194304    2G Linux RAID
/dev/sdf3  9437184 23437565951 23428128768 10.9T Linux RAID

@atomicknight
Copy link

This was very helpful for me as well. I was able to use this approach to mount an SHR array with the disks connected via USB:

# Setup loopback devices
# The offset for my Synology device was 9453280 sectors (4840079360 bytes)
[[ ! -e /dev/loop5001 ]] && losetup /dev/loop5001 /dev/sds -o 4840079360
[[ ! -e /dev/loop5002 ]] && losetup /dev/loop5002 /dev/sdt -o 4840079360
[[ ! -e /dev/loop5003 ]] && losetup /dev/loop5003 /dev/sdu -o 4840079360
[[ ! -e /dev/loop5004 ]] && losetup /dev/loop5004 /dev/sdv -o 4840079360

# Assemble the array
[[ ! -e /dev/md5001 ]] && mdadm --assemble --run /dev/md5001 /dev/loop5001 /dev/loop5002 /dev/loop5003 /dev/loop5004

# Show array info
mdadm --detail /dev/md5001

Then examine the volume groups, noting the name:

lvm vgdisplay

Finally, activate the volume group and mount the volume:

# vg1000 was the value of the "VG Name" field from lvm vgdisplay
lvm vgchange -a y vg1000
[[ ! -e /mnt/old ]] && mkdir /mnt/old && mount /dev/vg1000/lv /mnt/old -o ro

@kqv1
Copy link

kqv1 commented Dec 5, 2021

I have same issue of not recognize USB disk "Partition 1 does not start on physical sector boundary". I was able to use this approach to mount my Basic partition. Thank you @cllu very much

Some more information:

  • In my system (DSM7), USB drive was called /dev/usb1
  • The byte offset for data partition is the same as 4831838208
  • There is some typos in the 3rd line of the original script. I updated:
losetup /dev/loop1000 /dev/usb1 -o 4831838208
mdadm --assemble --run /dev/md1000 /dev/loop1000
mount /dev/md1000 /mnt/oldVolume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment