HOW TO CONFIGURE SWAP OVER RAID IN LINUX

In this post we will learn how to create swap over raid . I’ll be configuring swap over raid six . Which requires minimum four harddisks .

  • Create Four partitions and of same size
[root@localhost ~]# fdisk /dev/sda
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57368-65399, default 57368):
Using default value 57368
Last cylinder or +size or +sizeM or +sizeK (57368-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57491-65399, default 57491):
Using default value 57491
Last cylinder or +size or +sizeM or +sizeK (57491-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57614-65399, default 57614):
Using default value 57614
Last cylinder or +size or +sizeM or +sizeK (57614-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57737-65399, default 57737):
Using default value 57737
Last cylinder or +size or +sizeM or +sizeK (57737-65399, default 65399): +1000M
  • also change partition type to raid
  • Command t  ( to change partition type)
  • After that don’t forget to run partprobe command.
Command (m for help): t
Partition number (1-8): 8
Hex code (type L to list codes): fd
Changed system type of partition 8 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-8): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-8): 6
Hex code (type L to list codes): fd
Changed system type of partition 6 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-8): 5
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]# partprobe /dev/sda
  • Fdisk -l command to check partition type and its size
[root@localhost ~]# fdisk -l
Disk /dev/sda: 537.9 GB, 537932857344 bytes
255 heads, 63 sectors/track, 65399 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       50993   409601241   83  Linux
/dev/sda2           50994       57367    51199155   82  Linux swap / Solaris
/dev/sda4           57368       65399    64517040    5  Extended
/dev/sda5           57368       57490      987966   fd  Linux raid autodetect
/dev/sda6           57491       57613      987966   fd  Linux raid autodetect
/dev/sda7           57614       57736      987966   fd  Linux raid autodetect
/dev/sda8           57737       57859      987966   fd  Linux raid autodetect
  • Now create raid 6
  • –level=6 means we want this raid to be raid6
[root@localhost ~]# mdadm --create /dev/md6 --level=6 --raid-devices=4 /dev/sda5 /dev/sda6 /dev/sda7 /dev/sda8
mdadm: /dev/sda5 appears to contain an ext2fs file system
    size=1975552K  mtime=Mon Jan 23 23:07:14 2017
mdadm: /dev/sda5 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Mon Jan 23 23:05:07 2017
mdadm: /dev/sda6 appears to contain an ext2fs file system
    size=1975552K  mtime=Mon Jan 23 23:07:14 2017
mdadm: /dev/sda6 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Mon Jan 23 23:05:07 2017
mdadm: /dev/sda7 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Mon Jan 23 23:05:30 2017
mdadm: /dev/sda8 appears to be part of a raid array:
    level=raid1 devices=2 ctime=Mon Jan 23 23:05:30 2017
Continue creating array? yes
mdadm: array /dev/md6 started.
  • Check raid by cat /proc/mdstat command
  • Md6 is active on sda8 , sda 7 , sda6 , sda5
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md6 : active raid6 sda8[3] sda7[2] sda6[1] sda5[0]
  • Format /dev/md6 .
[root@localhost ~]# mkswap /dev/md6
Setting up swapspace version 1, size = 2023092 kB
  • Now activate swap on /dev/md6 .
  • To check swap size type free   -m command
[root@localhost ~]# swapon /dev/md6
[root@localhost ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1893        647       1246          0         54        453
-/+ buffers/cache:        139       1754
Swap:        51928          0      51928
  • Now mount the raid to save data .Go to /etc/fstab
[root@localhost ~]# vim /etc/fstab
  • Make entry as shown below .
/dev/md6                swap                    swap    defaults         0 0
  • Press ESC and type :wq ( to save and quit )
~
~
~
~
:wq

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s