0

hello i am very new at linux and was reading a internal documentation on creating space. i came across this command can some one please explain what this command means dd if=/dev/zero bs=1G count=20 >> /OVS/Repositories/repo/.ACFS/snaps/vm_name/VirtualMachines/vm_name/System.img

what i understand from this command is i am giving a 20gb allocation to the System.img dont know if this is= correct

  • it adds 20 gigabytes (block size 1G count 20) of zeros (/dev/zero) to that file (or makes the file 20GB in size if it doesn't already exist) – Bravo Nov 15 '21 at 22:45
  • 1
    `bs` and `count`? In general mind this: [*`dd` is a cranky tool which is hard to use correctly*](https://unix.stackexchange.com/a/121888/108618). – Kamil Maciorowski Nov 15 '21 at 23:09
  • 1
    One of the contributors here has [written extensively on `dd`](https://unix.stackexchange.com/search?q=user%3A885+dd). You may find enlightenment here. – Seamus Nov 15 '21 at 23:40

1 Answers1

1

Let's break this into pieces:

dd if=/dev/zero bs=1G count=20 

The dd command copies data. The input data is from the device that generates an infinite number of zeros. The dd parameters say to use a block size of 1G and copy 20 blocks, so that would be 20G of zeros.

>> /OVS/Repositories/repo/.ACFS/snaps/vm_name/VirtualMachines/vm_name/System.img

The >> symbol saves output from the previous command to the following filename in append mode. If you used > by itself instead, it would either create a new file or truncate the existing file and start from the beginning as if it was a new file.

If this file didn't exist before, this would initialize it to a non-sparse 20G file of zeros.

If this already existed, you would be expanding it by 20G. Since this file appears to be a disk image (guessing from the filename), presumably your next step would be to expand the filesystem inside it to use the new space.

user10489
  • 5,834
  • 1
  • 10
  • 22
  • But `>>` passes the 20GB of zeros through the parent process and has it write the file. Read `man dd`, you can specify the output file, an offset, etc. – waltinator Nov 16 '21 at 00:30
  • No, `>>` doesn't pass anything through the parent process. The parent process opens the file in append mode and then runs `dd` with that as stdout. There is no difference in performance from what you suggest. – user10489 Nov 16 '21 at 05:29