Site map  

Increase boot 'sector' size

Problem

In a lot of Linux setups the first partition starts at cylinder 1, leaving 32 - 1.5 kB for the boot loader. So that's 32768 - 1536 = 31232 bytes.
Recently some versions of core.img (copy of /boot/grub/core.img) appeared that are larger. This means you need a larger boot area in order to have a bootable system.

My server has a Raid1 with LVM on top. Each disk has a swap area outside the Raid and just after the boot area;

     Device Boot      Start         End      Blocks   Id  System
  /dev/sda1              63     3903794     1951866   82  Linux swap / Solaris
  /dev/sda2   *     3903795  1953520064   974808135   fd  Linux raid autodetect

     Device Boot      Start         End      Blocks   Id  System
  /dev/sdb1              63     3903794     1951866   82  Linux swap / Solaris
  /dev/sdb2   *     3903795  1953520064   974808135   fd  Linux raid autodetect

Blocks are 1, 2 or 4 kB. On my sytem 1 kB.

I knew that after the upgrade from Squeeze to Wheezy the core.img would be 31987 bytes. So I needed to increase the start position of the swap spaces;

     Old              New

    +---+ 0          +---+ 0
    |mbr|            |mbr|
    +---+ 32 k       |   |
    | S |            +---+ 64 k
    | w |            | S |
    | a |            | w |
    | p |            | a |
    |   |            | p |
    +---+            +---+
    | R |            | R |
    | a |            | a |
    | i |            | i |
    | d |            | d |
    |   |            |   |
    |   |            |   |
    |   |            |   |
    |   |            |   |
    +---+            +---+

Solution

Turn off swap;

~# swapoff /dev/sda1

Edit /etc/fstab. Put a comment in front of this swap partition's line in /etc/fstab, so this swap partition isn't used after reboot.

Fdisk. Set the start at 127 (or whatever gets you a whole number of blocks) instead of 63 sectors.

~# fdisk /dev/sda

If units are cylinders, Use 'u' to change the units from cylinders to sectors. Use 'p' to display partition table.

     Device Boot      Start         End      Blocks   Id  System
  /dev/sda1              63     3903794     1951866   82  Linux swap / Solaris
  /dev/sda2   *     3903795  1953520064   974808135   fd  Linux raid autodetect

- d, delete a partition.
- select 1.
- check with 'p';

     Device Boot      Start         End      Blocks   Id  System
  /dev/sda2   *     3903795  1953520064   974808135   fd  Linux raid autodetect

- n, add a new partition.
- select p, primary.
- select 1.
- start at 127, end at default.
- t, change the partition's system id to swap (82).
- check result with 'p';

     Device Boot      Start         End      Blocks   Id  System
  /dev/sda1             127     3903794     1951834   82  Linux swap / Solaris
  /dev/sda2   *     3903795  1953520064   974808135   fd  Linux raid autodetect

The swap space is 32 kB smaller, so it starts 32 kB further.
'w', to write table to disk and exit (or 'q' to quit without saving). Fdisk will complain about saving on a running system, but will do so anyway.

Fdisk should only write to the first bit of the disk. However, just to be on the safe side, I run grub anyway;

~# grub-install /dev/sda

Reboot;

~# shutdown -r now

After reboot

Make new swap

~# mkswap /dev/sda1

Edit fstab. Remove previous entered remark and replace uuid with new value from mkswap.

Turn on swap.

~# swapon /dev/sda1

2nd disk

- swapoff /dev/sdb1
- vi /etc/fstab: disable old swap space
- fdisk /dev/sdb
- grub-install /dev/sdb
- shutdown -r now

After 2nd reboot

- mkswap /dev/sdb1
- vi /etc/fstab: enable new swap space
- swapon /dev/sdb1