Skip to contentSkip to conversation

How to move a btrfs volume to a smaller disk

DISCUSSION Hendrik Friedel 3 participants 4 messages Mar 9, 2016 – Mar 11, 2016 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hello,

I intend to move this subvolume to a new device. btrfs fi show /mnt2/Data_Store/
Label: 'Data_Store' uuid: 0ccc1e24-090d-42e2-9e61-d0a1b3101f93
Total devices 1 FS bytes used 47.93GiB
devid 1 size 102.94GiB used 76.03GiB path /dev/sdb4

(fi usage at the bottom of this message)

The new device (sda4) is 8G smaller unfortunately.
sda 8:0 0 111.8G 0 disk

└─sda4    8:4    0 103.5G  0 part
sdb       8:16   0 119.2G  0 disk
└─sdb4    8:20   0   111G  0 part  /mnt2/Data_Store

Thus, btrfs replace does not work

What would you suggest now to move the FS (it does contain many subvolumes)?

I tried btrfs send /mnt2/Data_Store/read_only_snapshot/ | btrfs receive /mnt/sda4/ but this only created an empty subvolume /mnt/sda4/read_only_snapshot/

So, then
btrfs device add /dev/sda4 /mnt/Data_Store
btrfs balance start /mnt/Data_Store
btrfs device remove /dev/sdb4 /mnt/Data_Store
?

Or is there a better option?

Regards,
Hendrik

btrfs fi usage /mnt2/Data_Store/
Overall:
Device size: 102.94GiB
Device allocated: 74.03GiB
Device unallocated: 28.91GiB
Device missing: 0.00B
Used: 47.96GiB
Free (estimated): 53.24GiB (min: 53.24GiB)
Data ratio: 1.00
Metadata ratio: 1.00
Global reserve: 512.00MiB (used: 0.00B)

Data,single: Size:69.00GiB, Used:44.67GiB
/dev/sdb4 69.00GiB

Metadata,single: Size:5.00GiB, Used:3.29GiB
/dev/sdb4 5.00GiB

System,single: Size:32.00MiB, Used:16.00KiB
/dev/sdb4 32.00MiB

Unallocated:
/dev/sdb4 28.91GiB

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

#1 lore raw
Quoted 12 lines · Hendrik Friedel

Hello,

I intend to move this subvolume to a new device. btrfs fi show /mnt2/Data_Store/
Label: 'Data_Store' uuid: 0ccc1e24-090d-42e2-9e61-d0a1b3101f93
Total devices 1 FS bytes used 47.93GiB
devid 1 size 102.94GiB used 76.03GiB path /dev/sdb4

(fi usage at the bottom of this message)

The new device (sda4) is 8G smaller unfortunately.
sda 8:0 0 111.8G 0 disk

Quoted 7 lines
└─sda4    8:4    0 103.5G  0 part
sdb       8:16   0 119.2G  0 disk
└─sdb4    8:20   0   111G  0 part  /mnt2/Data_Store

Thus, btrfs replace does not work

What would you suggest now to move the FS (it does contain many subvolumes)?

btrfs dev resize to shrink it to (slightly smaller than) the
replacement device, then btrfs replace should work. Then btrfs dev resize max to fill up the replacement device completely.

Hugo.

Quoted 45 lines

I tried btrfs send /mnt2/Data_Store/read_only_snapshot/ | btrfs receive /mnt/sda4/
but this only created an empty subvolume /mnt/sda4/read_only_snapshot/

So, then
btrfs device add /dev/sda4 /mnt/Data_Store
btrfs balance start /mnt/Data_Store
btrfs device remove /dev/sdb4 /mnt/Data_Store
?

Or is there a better option?

Regards,
Hendrik

btrfs fi usage /mnt2/Data_Store/
Overall:
Device size: 102.94GiB
Device allocated: 74.03GiB
Device unallocated: 28.91GiB
Device missing: 0.00B
Used: 47.96GiB
Free (estimated): 53.24GiB (min: 53.24GiB)
Data ratio: 1.00
Metadata ratio: 1.00
Global reserve: 512.00MiB (used: 0.00B)

Data,single: Size:69.00GiB, Used:44.67GiB
/dev/sdb4 69.00GiB

Metadata,single: Size:5.00GiB, Used:3.29GiB
/dev/sdb4 5.00GiB

System,single: Size:32.00MiB, Used:16.00KiB
/dev/sdb4 32.00MiB

Unallocated:

   /dev/sdb4      28.91GiB

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

Signature · 4 lines
Hugo Mills             | Well, sir, the floor is yours. But remember, the
hugo@... carfax.org.uk | roof is ours!
http://carfax.org.uk/  |
PGP: E2AB1DE4          |                                             The Goons
#2 lore raw

Hello Hugo,

thanks for your ultrafast reply.
Unfortunately, it does not work for me:
[root@homeserver mnt2]# btrfs filesystem resize 80G /mnt2/Data_Store/ && btrfs replace start /dev/sdb4 /dev/sda4 /mnt2/Data_Store/ -f && btrfs filesystem resize max /mnt2/Data_Store/ Resize '/mnt2/Data_Store/' of '80G'
ERROR: target device smaller than source device (required 119121379328 bytes)
[root@homeserver mnt2]# btrfs filesystem show /mnt2/Data_Store/
Label: 'Data_Store' uuid: 0ccc1e24-090d-42e2-9e61-d0a1b3101f93
Total devices 1 FS bytes used 47.95GiB
devid 1 size 80.00GiB used 66.03GiB path /dev/sdb4

[root@homeserver mnt2]# lsblk | grep sda4
└─sda4 8:4 0 103.5G 0 part

Greetings,
Hendrik

Quoted 17 lines · Hugo Mills
Quoted 16 lines · Hendrik Friedel

Hello,

I intend to move this subvolume to a new device. btrfs fi show /mnt2/Data_Store/
Label: 'Data_Store' uuid: 0ccc1e24-090d-42e2-9e61-d0a1b3101f93
Total devices 1 FS bytes used 47.93GiB
devid 1 size 102.94GiB used 76.03GiB path /dev/sdb4

(fi usage at the bottom of this message)

The new device (sda4) is 8G smaller unfortunately.
sda 8:0 0 111.8G 0 disk

└─sda4    8:4    0 103.5G  0 part
sdb       8:16   0 119.2G  0 disk
└─sdb4    8:20   0   111G  0 part  /mnt2/Data_Store
Quoted 54 lines
Quoted 3 lines

Thus, btrfs replace does not work

What would you suggest now to move the FS (it does contain many subvolumes)?

btrfs dev resize to shrink it to (slightly smaller than) the
replacement device, then btrfs replace should work. Then btrfs dev resize max to fill up the replacement device completely.

Hugo.

Quoted 45 lines

I tried btrfs send /mnt2/Data_Store/read_only_snapshot/ | btrfs receive /mnt/sda4/
but this only created an empty subvolume /mnt/sda4/read_only_snapshot/

So, then
btrfs device add /dev/sda4 /mnt/Data_Store
btrfs balance start /mnt/Data_Store
btrfs device remove /dev/sdb4 /mnt/Data_Store
?

Or is there a better option?

Regards,
Hendrik

btrfs fi usage /mnt2/Data_Store/
Overall:
Device size: 102.94GiB
Device allocated: 74.03GiB
Device unallocated: 28.91GiB
Device missing: 0.00B
Used: 47.96GiB
Free (estimated): 53.24GiB (min: 53.24GiB)
Data ratio: 1.00
Metadata ratio: 1.00
Global reserve: 512.00MiB (used: 0.00B)

Data,single: Size:69.00GiB, Used:44.67GiB

    /dev/sdb4      69.00GiB

Metadata,single: Size:5.00GiB, Used:3.29GiB

    /dev/sdb4       5.00GiB

System,single: Size:32.00MiB, Used:16.00KiB

    /dev/sdb4      32.00MiB

Unallocated:

    /dev/sdb4      28.91GiB

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

#3 lore raw
In reply to Hendrik Friedel
Quoted 16 lines · Hendrik Friedel

Hello,

I intend to move this subvolume to a new device. btrfs fi show /mnt2/Data_Store/
Label: 'Data_Store' uuid: 0ccc1e24-090d-42e2-9e61-d0a1b3101f93
Total devices 1 FS bytes used 47.93GiB
devid 1 size 102.94GiB used 76.03GiB path /dev/sdb4

(fi usage at the bottom of this message)

The new device (sda4) is 8G smaller unfortunately.
sda 8:0 0 111.8G 0 disk

└─sda4    8:4    0 103.5G  0 part
sdb       8:16   0 119.2G  0 disk
└─sdb4    8:20   0   111G  0 part  /mnt2/Data_Store
Quoted 6 lines

Thus, btrfs replace does not work

What would you suggest now to move the FS (it does contain many subvolumes)?

I tried btrfs send /mnt2/Data_Store/read_only_snapshot/ | btrfs receive /mnt/sda4/ but this only created an empty subvolume /mnt/sda4/read_only_snapshot/

I suspect that you captured snapshot as

==========================
btrfs sub snap -r /mnt2/Data_Store /mnt2/Data_Store/read_only_snapshot
==========================

and /mnt2/Data_Store only contains subvolumes instead of having files/directries directly. Then send/receive work as you said. Probably if you run "ls -li /mnt2/Data_Store", all files have inode 256 (it means subvolume). In addition, all the directories under /mnt2/Data_Store/read_only_snapshot are empty.

It's because "sub snap" only handles one subvolume and doesn't handle subvolumes inside it. So, if you'd like to copy all the data by send/receive, you should capture and send/receive snapshot for each subvolume.

Quoted 6 lines

So, then
btrfs device add /dev/sda4 /mnt/Data_Store
btrfs balance start /mnt/Data_Store
btrfs device remove /dev/sdb4 /mnt/Data_Store
?

balance is not necessary. When you run
device remove /dev/sdb4, then all the contents of /dev/sdb4 migrate to /dev/sda4 properly.

Thanks,
Satoru

Quoted 40 lines

Or is there a better option?

Regards,
Hendrik

btrfs fi usage /mnt2/Data_Store/
Overall:
Device size: 102.94GiB
Device allocated: 74.03GiB
Device unallocated: 28.91GiB
Device missing: 0.00B
Used: 47.96GiB
Free (estimated): 53.24GiB (min: 53.24GiB)
Data ratio: 1.00
Metadata ratio: 1.00
Global reserve: 512.00MiB (used: 0.00B)

Data,single: Size:69.00GiB, Used:44.67GiB

    /dev/sdb4      69.00GiB

Metadata,single: Size:5.00GiB, Used:3.29GiB

    /dev/sdb4       5.00GiB

System,single: Size:32.00MiB, Used:16.00KiB

    /dev/sdb4      32.00MiB

Unallocated:

    /dev/sdb4      28.91GiB

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html