Solving the problem with ‘error: attempt to read or write outside of disk “hd0″’

After installing Linux at the first boot you may encounter the error mentioned in the subject.

To understand the reason, literally a couple of words about the boot process. It all starts with the fact that the BIOS initializes the devices, including hard drives; after that, the BIOS transmits control to the GRUB booter, indicating the place on the disk where it should read the configuration file and other files necessary for it.

BIOS is a rather old invention and it has a number of limitations. For example, no BIOS is able to work with disks over 2 terabytes. Therefore, if you installed the system on such a disk, then it is quite possible that the BIOS will not cope with loading the operating system.

But this is not all – some BIOSes has especially poor design – they cannot point GRUB to files that are too far from the beginning of the disk – not necessarily beyond 2 Terabytes, perhaps much closer.

How is the recording on the disc performed

This seems counterintuitive, but the information is not recorded to the disk sequentially – that is, if 10% of the disk space is occupied, this does not mean that the first 10% are occupied – the information can be scattered randomly. Smart disks specifically record information in different areas – so that the disc degrades evenly.

Therefore, when you install the operating system, the /boot folder can be anywhere — even at the end of the disk.

error: attempt to read or write outside of disk «hd0″

So, as a result of the confluence of a number of circumstances:

  • BIOS is used (not EFI)
  • large disk size
  • poor BIOS design
  • folder /boot is written too far from the beginning of the disk

can get the error:

error: attempt to read or write outside of disk «hd0″

From that facts the conclusions follow:

  • when installing on the same disk, the error may or may not occur (depending on the location of the /boot folder on the disk)
  • Reinstalling GRUB, which is advised on some websites, may or may not help - again, depending on where the /boot folder is overwritten
  • if your computer supports EFI, then you will never encounter this error
  • the problem disk may well boot on another computer (there are nuances - on another computer there may be EFI or also poorly designed BIOS)

And the most important conclusion – if the /boot folder is written to a separate partition and the partition is located at the beginning of the disk, then this will almost certainly solve the problem.

How to put the /boot folder on a separate section.

I will show the example of Debian and derivatives (Kali Linux, for example). With other distributions, the actions are similar – but you need to look in advance for information on how to put the /boot folder in a separate section during the installation process.

I would especially note that if your computer supports EFI (and this is the majority of computers manufactured in the last 8-10 years), then you will not encounter this problem and you do not need to worry.

So, at the beginning of the installation is performed as usual.

Then, when you get to the disk layout – select ‘Manual’:

Select the disk to partition:

Choose Yes:

Select FREE SPACE:

Create a new partition:

We do not very big size – 1 Gigabyte is enough for more than. In fact, less than 100 megabytes will be used. In any case it is better to allocate more than 200 megabytes:

Primary:

Be sure to select ‘Beginning’ - otherwise everything what we do now is meaningless:

Go to Mount Point:

Select /boot - static files of the boot loader:

Set Bootable flag to on. Select Done setting up the partition:

Now go to the FREE SPACE and create another section:

Further, as with the first partition – set the size. Select a logical partition.

The mount point should be / - this character means the root filesystem:

We get:

By the way, for the main partition you can use not all the free space - you can save space on the disk for other needs. You can also allocate 10 Gigabytes for SWAP partition – swap area (used when there is not enough RAM). To do this, when you set the properties of the disk, select ‘Use as’, and there select the ‘swap area’.

Next, the installation of the operating system again continues as usual.

Conclusion

The problem can arise both with an internal hard drive, and with an external USB drive. The problem may arise suddenly – even on a disk that previously worked fine – it's all about “luck” - where exactly the /boot folder will be written. The method shown in this article will allow you not to rely on luck, but to completely prevent this problem.

By the way, if you’ve got into manual disk partitioning anyway, it is recommended to create another partition and select it to mount the /home folder. The result will be that the system will be on one partition, and the /home folder, in which user files are located, on another. Therefore, the next time you reinstall the operating system, the files in the /home folder will not be deleted (unless you do this manually). And you can re-connect this partition to mount as /home. That is, it turns out that you have a new system, and all user files are in the same place as before the reinstallation.

Recommended for you:

6 Comments to Solving the problem with ‘error: attempt to read or write outside of disk “hd0″’

  1. finelf says:

    This article saved my life! I was 2 weeks trying to figure out why the hell my I get this Error. Converting my ssd with Windows to GPT and switching to UEFI booting mode was the trick. HUGE THANKS

  2. Drazen says:

    Great article… solved my problems with Xubuntu instalation. Thanx

  3. Daniel B. says:

    Had an old Dell 600m laptop with a 80GB hdd in it that was not behaving. Bought the hardware to install an M.2 250GB SSD. Installation of Linux Mint went perfectly until boot time, then I got the above error. After trying several other online 'solutions' (don't users try their own solutions first??? I mean, really!) this is the one that not only made sense but worked beautifully. Turns out my /boot partition really WAS installed too far from the beginning of the disk. Once I corrected this with the above solution, the laptop booted up after finishing the install of Linux Mint 19 on this 32-bit laptop. I had to power off at the end of OS installation, then power back on. After that, bootup is going on without a hitch. I now have a usable laptop again, with an much better hard drive and much better OS.

  4. Steve Goble says:

    ^^^^^^^^

    THIS!

    I recently ran into this working on old re-purposed HP ProLiant server.  For days I tried installing multiple operating systems, multiple different drives (USB and internal) and no matter what it came up with this error.  I was so frustrated trying to find old ROM/BIOS upgrades etc because most other articles start to point you to BIOS settings as the culprit when you read through the replies.

    After skimming through your article, I manually created partitions during install and then immediately booted up with a GParted USB and correctly set labels and flags on my partitions which BAM solved the boot issue.  

    THANKS!!

  5. Anonymous says:

    Dopo aver perso un sacco di tempo nel tentativo di installare qualsiasi versione di Linux nel mio vecchio laptop, Compaq Presario X1000, cercando soluzioni all'errore come da titolo, mi sono imbattuto nel tuo articolo e sono finalmente riuscito a risolvere i problemi. Ti ringrazio tantissimo per la soluzione che hai proposto, che ha risolto il problema del Grub Rescue. GRAZIE.

  6. Sol Li says:

    I don't belong to the computer generation, but this article was for everybody. Thank you very much!
    I have used the distro Q4OS on and off for some years. Never experienced any problem before this happened.
    I will now make it a habit to install a boot partition on our older computers.

Leave a Reply to finelf Cancel reply

Your email address will not be published. Required fields are marked *