Score:1

Why Linux "dd" is erroring with "no space left on device" while copying a single partition to a smaller device?

cn flag

I'm trying to copy the single partition /dev/sda1 to /dev/sdc1, but I'm getting the error "no space left on device" and I honestly don't get why.

I'm working on an Oracle Cloud Infrastructure (OCI) VM where /dev/sda is a 768 GB volume whose sda1 partition has been shrinked o just 32 GB (the process was ok, no data loss! I can guarantee because that volume is an Oracle Database ASM disk group, and everything works fine after shrinking).

Since OCI allows only to grow volume size, I created a new volume /dev/sdc sized 50 GB (that's the minimum size allowed) and created a partition /dev/sdc1 of just 32 GB (same size as /dev/sda1).

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdc      8:32   0    50G  0 disk
└─sdc1   8:33   0    32G  0 part
sda      8:0    0   768G  0 disk
└─sda1   8:1    0    32G  0 part

I get an error while running

# dd if=/dev/sda1 of=/dev/sdc1 bs=512b conv=noerror,sync
dd: error writing ‘/dev/sdc1’: No space left on device
22567+0 records in
22566+0 records out
5915787264 bytes (5.9 GB) copied, 42.9384 s, 138 MB/s

The two partitions are exactly the same size, as shown by fdisk

# fdisk /dev/sda

Disk /dev/sda: 824.6 GB, 824633720832 bytes, 1610612736 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk label type: dos
Disk identifier: 0x7c9bf84b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    67108863    33553408   83  Linux


# fdisk /dev/sdc
Disk /dev/sdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk label type: dos
Disk identifier: 0x9b11add5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    67108863    33553408   83  Linux

What am I doing wrong?

in flag
It errors out quite early compared to 32G, I would verify nodes `ls -l /dev/sd?1` verify node numbers with `lsblk -b`, check `dmesg` for any messages, use `dd_rescue` or `ddrescue` instead.
Score:0
cn flag

I don't know what the problem was, but I had it work just cloning the entire volume

# dd if=/dev/sda of=/dev/sdc bs=512b conv=noerror,sync

Of course, the operation stops at 50 GB that is /dev/sdc total size erroring the same message, but the outcome is OK.

A.B avatar
cl flag
A.B
What was maybe the problem: your system didn't update its in-memory partition tables. You probably created /dev/dc1 at ~ 6G and increased it later. The easiest tool to force such update is `kpartx -u ...`. This should happen only if the partition is in use though.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.