Wiping the hard drive before installing the operating system


(5 comments)

Many people often think that to have a clean hard drive just repartition the disk and recreate the filesystems. The reality is not so.
For MBR disk partition table, disk partitioning tools like fdisk, cfdisk, parted, and filesystem creation tools like mkfs.ext4 only manipulate the first sector of the disk (sector 0) and sectors beginning from the first partition. We use a USB memory stick to illustrate, the device name is /dev/sdb



This hard disk has one partition starting from sector 63. Thus 62 sectors from sector 1 to sector 62 are not affected by normal disk tools. Even the use of wipefs to wipe all signatures on the disk did not remove the information in these 62 sectors.
This space should have originally been empty. If it does not, we call the disk is not clean to install new operating system.
This happens even if you buy a brand new hard drive, which the manufacturer can code to track equipment or take care of customers. But the risk is that it may be the code of a bootkits root virus.

The solution is to create a file containing all 0 bytes and overwrite that area. The following program creates the file zerodisk.dat containing all bytes 0, which is the size of 62 sectors (1 sector has 512 bytes)

#include <stdlib.h>
#include <stdio.h>
#include <strings.h>

int main() {
 
    FILE *f = fopen("zerodisk.dat", "w");
    char data[512 * 62];
    bzero(data, 512 * 62);
    fwrite(data, 512, 62, f);
    fclose(f);

    return 0;
}


Now we use dd to overwrite the file content to the location on the disk, as the root user:

dd if=zerodisk.dat of=/dev/sdb seek=1 conv=notrunc



You now have the necessary empty disk area, feel free to use disk tools and start installing the new operating system. After installing GRUB (bootloader), its image will be safely written to that empty area.

Currently unrated

Comments

buy dumpscc check 1 month, 3 weeks ago

Hɑve you ever thought aboսt ading a little ƅit more than just yyour aгticles?
I mean, what you say is important and all.
Nevеrtheless tһink of if you ɑdded some great picturеs or videos to give your posts more, "pop"!Yoᥙrr contnt
іѕ excellent but with images and videօs, this site could certainly be one off the greateѕt in its field.
Superb blog!

Link | Reply
Currently unrated

Tuyen Pham Thanh 1 month, 3 weeks ago

Thanks for your comments. I will collect more illustrative media if possible.

Link | Reply
Currently unrated

holymolyslots 1 month, 1 week ago

Playing slots iss definitely ann thrilling game.

Link | Reply
Currently unrated

Don Quinn 1 month, 2 weeks ago

How to install 6.2 on 4TB gpt drive?

Link | Reply
Currently unrated

Tuyen Pham Thanh 1 month, 2 weeks ago

Mount your target partition as the root partition manually, for example /dev/sda1:
mount /dev/sda1 /mnt
After installation, create fstab:
echo /dev/sda1 / ext4 defaults 1 1 > /mnt/etc/fstab
before restarting.

Link | Reply
Currently unrated

New Comment

required

required (not published)

optional

required


What is 6 - 2?

required