-1

I want to create file.img from unallocated hdd to another hdd ( backup the hdd ) to rescue my partitions and files in it . When I

dd if=/dev/sda of=dev/sdb/file.img 

It shows

dd: failed to open '/dev/sda': permission is denied 

Please help Can i create image from used space only on unallocated hdd this is all what i need . Because i will attempt to perform tdisk after creating the image to try rescue the partitions with files in it Recover data on a hard-drive that changed partition table

  • 1
    You've not provided any Ubuntu product/release details; but a normal system requires elevated privileges to copy devices, thus a "permission denied" error is usually indicative of the user not elevating privileges (ie. using sudo). – guiverc Aug 18 '23 at 12:12
  • 1
    You need sudo dd ... to access block devices. Make sure no partition of the disk is mounted while you copy the data. The destination file name dev/sdb/file.img looks strange. Have you mounted a whole disk (not a partition) to dev/sdb/ in the current working directory? Special disk backup tools (e.g. clonezilla or partimage) might be better than dd. – Bodo Aug 18 '23 at 12:15
  • Can i create image from used space only on unallocated hdd this is all what i need . Because i will attempt to perform tdisk after creating the image to try rescue the partitions with files in it https://askubuntu.com/q/1482115/1721749 – Mahmoud Sobeih Aug 18 '23 at 12:34

1 Answers1

1

Please use lsblk and ponder on the data it displays.

Example:

$ lsblk -ape7 -o+FSTYPE
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT FSTYPE
/dev/sda           8:0    0  7.3T  0 disk            
└─/dev/sda1        8:1    0  7.3T  0 part            ext4
/dev/nvme0n1     259:0    0  3.7T  0 disk            
├─/dev/nvme0n1p1 259:1    0  487M  0 part /boot/efi  vfat
├─/dev/nvme0n1p2 259:2    0   16G  0 part [SWAP]     swap
└─/dev/nvme0n1p3 259:3    0  3.6T  0 part /          ext4

The first column tells you the disk and partition names...
These are for use as source for reading all data from that disk or partition without the use of a filesystem .

A filesystem - as stated under FSTYPE - will organize and keep order on your files and folders.
NOTE: If you write to a disk or partition (e.g. /dev/sda, /dev/sda1 or /dev/nvme0n1 ... above), you will BYPASS the filesystem - and by that destroy what it has created.

Note here now: if you read data from e.g. /dev/sda and write it to /dev/sdb (if you have one), then you will have removed and overwritten ALL data on /dev/sda, replacing it with what was on /dev/sdb .

If you want a BACKUP of /dev/sdb - you will want to write that data to a FILE on e.g. the ext4 partition making up / - i.e. /SDB-BACKUP.bin or some such.
Only by that you will keep what already exist on /...

Now ponder thoroughly on the above, before you do anything more.

You will most likely prefer to do this
$ sudo dd if=/dev/sda of=/sda-backup-on-sdb.img
... or similar.
That is; if /dev/sdb/ has any filesystem and content on it - that you wish to KEEP.

Hannu
  • 5,374
  • 1
  • 23
  • 40