The mdadm create
command is used to create a new linear RAID device, /dev/md0
, using the device /dev/sdb1
. The command is executed with options such as --level=1
, -n 1
, -f
, and --raid-disk=2
to specify RAID level and disk configuration.
mdadm --create /dev/md0 --level=1 -n 1 -f --raid-disk=2 /dev/sdb1
#!/bin/bash
# Function to create a RAID 1 array
create_raid1() {
local device_name="/dev/md0"
local raid_level="1"
local num_disks="1"
local raid_disk=${2:-2}
local metadata_format="--metadata=1.2"
local disk_device="/dev/sdb1"
mdadm $metadata_format --create $device_name --level=$raid_level --raid-devices=$num_disks -f --raid-disk=$raid_disk $disk_device
}
# Call the function
create_raid1
MDADM Command
mdadm
create
--level=1
: Specify the RAID level (1 for linear RAID)-n 1
: Specify the number of active devices-f
: Force creation, overwriting existing data--raid-disk=2
: Specify the starting disk number for the RAID (2)/dev/md0
: Specify the name of the new RAID device/dev/sdb1
: Specify the device to use as the RAID deviceCreates a new linear RAID device /dev/md0
using /dev/sdb1
as the device