Search code examples
linuxunixcentosredhatswap

fdisk - create swap partition that is half the disk size


I have a /dev/xvdf disk mounted on my linux server. I am creating a swap partition using this disk which I am successfull in doing so.

However, what i would also like to do is partition just half the disk to use for swap, and keep the other half.

I have done the following :

**fdisk -l**

Disk /dev/xvdf: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

to begin the creating the swap partition :

fdisk /dev/xvdf
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6ab35b7f.

I then went ahead and selected to make a new partition (primary) :

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p

I then selected 1 which is the default partition number

Partition number (1-4, default 1): 1
First sector (2048-2097151, default 2048):
Using default value 2048

And this is where the confusion begins for me, i intend to use only half of the total disk of /dev/xvdf and i did the following :

Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): 536MB
Value out of range.
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +536MB
Partition 1 of type Linux and of size 511 MiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

I have specified 536MB on the size as shown above which is half of /dev/xvdf which is 1073MB.

Is this the correct way of partioning half the disk please ?


Solution

  • I'm sure this question has already been answered long ago, but for future reference, I believe fdisk reads partition sizes using M, not MB. In this case, you would need to change your final partition size to +536M.