How to convert Linear filesystem to software RAID-1 in Linux ?

In this article I am going to show how can we convert the linear device into RAID configuration.

Step 1 : I have created one soft RAID-1 using one new device and one mentioned as missing one.

root@localhost ~]# mdadm –create –verbose /dev/md2 –level=1 –raid-devices=2 missing /dev/sdd1
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device.  If you plan to
store ‘/boot’ on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
–metadata=0.90
mdadm: size set to 204608K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.

Step 2 : Checked the status of soft raid you will find that one device is in missing status. This is the same device which we titled as missing in previous step.

[root@localhost ~]# mdadm –detail /dev/md2
/dev/md2:
Version : 1.2
Creation Time : Sun Nov 16 09:29:14 2014
Raid Level : raid1
Array Size : 204608 (199.85 MiB 209.52 MB)
Used Dev Size : 204608 (199.85 MiB 209.52 MB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent

Update Time : Sun Nov 16 09:29:14 2014
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0

Name : localhost.localdomain:2  (local to host localhost.localdomain)
UUID : 3f6e6b49:48d886e6:7484276e:814f8f87
Events : 0

Number   Major   Minor   RaidDevice State
0       0        0        0      removed
1       8       49        1      active sync   /dev/sdd1

Step 3 : We want to convert the below device into mirror device.

[root@localhost ~]# df -h /Linear/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       190M  1.6M  175M   1% /Linear

[root@localhost ~]# dd if=/dev/zero of=/Linear/testfile1 bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.335132 s, 313 MB/s

Step 4 : I have created the same file system ext4 on the newly created RAID-1 configuration.

[root@localhost ~]# mkfs.ext4 /dev/md2
mke2fs 1.42.8 (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204608 blocks
10230 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

After doing this operation we have mounted the RAID-1 setup on one mountpoint.

[root@localhost ~]# mount /dev/md2 /RAID-1/

[root@localhost ~]# df -h /RAID-1/
Filesystem      Size  Used Avail Use% Mounted on
/dev/md2        190M  1.6M  175M   1% /RAID-1

Step 5 : Started copying of data from old setup to new setup.

[root@localhost RAID-1]# cp -axu /Linear/ /RAID-1/

Step 6 : After the copy is complete. We can unmount the linear filesystem and add the device which was used for linear in RAID-1.

Missing device has been replaced with Linear device.

[root@localhost RAID-1]# umount /Linear/

[root@localhost RAID-1]# mdadm –manage /dev/md2 –add /dev/sdc1
mdadm: added /dev/sdc1

[root@localhost RAID-1]# mdadm –detail /dev/md2
/dev/md2:
Version : 1.2
Creation Time : Sun Nov 16 09:29:14 2014
Raid Level : raid1
Array Size : 204608 (199.85 MiB 209.52 MB)
Used Dev Size : 204608 (199.85 MiB 209.52 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Sun Nov 16 09:32:47 2014
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Name : localhost.localdomain:2  (local to host localhost.localdomain)
UUID : 3f6e6b49:48d886e6:7484276e:814f8f87
Events : 47

Number   Major   Minor   RaidDevice State
2       8       33        0      active sync   /dev/sdc1
1       8       49        1      active sync   /dev/sdd1

Finally we have done with conversion from Linear to RAID-1. We can do the same for root disk as well if we are not having Hardware RAID configured on it but we need to recreate initrd in it so that server can boot from software RAID.

Advertisements

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