9

OK, so I've got three image files in /home/, and they each reside on different physical drives:

image1.img

image2.img

image3.img

Each image is the same size, and I want to put the images themselves into RAID0.

How should I go about RAIDing them?

EDIT: Using mdadm I get this error:

enter image description here

EDIT: Output of cat /proc/mdstat

enter image description here

EDIT: Output of sudo gparted /dev/md0

enter image description here

10
  • If I understand correctly, you want to have a RAID-0 drive which has thrice the size of the image files and is stripped between the three image files?
    – lemonslice
    Aug 25, 2015 at 17:08
  • Yes. The idea is to be able to create a RAID unit that can span multiple drives without actually placing the drives in RAID.
    – Daniel
    Aug 26, 2015 at 20:30
  • What does cat /proc/mdstat say about this error?
    – lemonslice
    Aug 27, 2015 at 20:31
  • See edit to question
    – Daniel
    Aug 28, 2015 at 16:01
  • What are the media below the image files? Based on the error message they do not support seek...
    – lemonslice
    Aug 28, 2015 at 16:41

3 Answers 3

10
+50

To install the Linux software RAID you need to install the mdadm package.

sudo apt-get install mdadm

If you want to make a software RAID-0 from the three image files, you need to create loop devices for each image files:

sudo losetup /dev/loop1 image1.img
sudo losetup /dev/loop2 image2.img
sudo losetup /dev/loop3 image3.img

After you can create a RAID-0 array from them:

sudo mdadm --create /dev/md0 --level=0 --raid-devices=3 /dev/loop1 /dev/loop2 /dev/loop3
4
  • command mdadm not found
    – Daniel
    Aug 26, 2015 at 20:33
  • You have to install the package mdadm.
    – lemonslice
    Aug 27, 2015 at 10:52
  • See edit to question
    – Daniel
    Aug 27, 2015 at 19:53
  • That's with a fresh install of mdadm.
    – Daniel
    Aug 27, 2015 at 19:54
1

If your system matches the basic requirements you could use zfs (8 GB RAM, 64-bit system):

Add repo and update package list:

sudo add-apt-repository ppa:zfs-native/stable
sudo apt-get update

Install package:

sudo apt-get install ubuntu-zfs

Create a striped vdev (with no redundancy, but you asked for RAID0):

sudo zpool create vol0 ~/image[1-3].img

This creates the stripe and mounts it at /vol0.

sudo zfs create vol0/filesystem

This creates a zfs file system on the stripe and mounts it at /vol0/filesystem. Use

sudo zfs set mountpoint=/mnt/filesystem vol0/filesystem

if you want to change the mount point.

You can also add automatic compression:

sudo zfs create vol0/filesystem/compressed
sudo zfs set compression=on vol0/filesystem/compressed

Now everything you put into /mnt/filesystem/compressed will automatically be compressed.

9
  • "E: Unable to locate package ubuntu-zfs"
    – Daniel
    Aug 24, 2015 at 16:01
  • And this should also work with iso files, right?
    – Daniel
    Aug 24, 2015 at 16:04
  • Forgot to add instructions on how to add the repo. Have edited now. Aug 25, 2015 at 6:02
  • I'm not sure what you mean with iso files... The instructions will create a blank file system striped over the 3 files in question. Do you have data in your iso files that you somehow wish to access on a striped partition? Aug 25, 2015 at 6:03
  • No, I was just curious as to whether or not it could be done with, say a DVD-RW for instance, or something like that.
    – Daniel
    Aug 25, 2015 at 16:20
0

I literally just did touch image#.img for each one. Is there something else I should do?

This is indeed the problem. The files are 0 bytes, and you cannot seek inside them. You have to make files that actually have a size. It can be a a sparse file if you want:

[/tmp]$ dd if=/dev/zero of=1.img bs=1M count=25 conv=sparse
25+0 records in
25+0 records out
26214400 bytes (26 MB, 25 MiB) copied, 0.00334608 s, 7.8 GB/s
[/tmp]$ dd if=/dev/zero of=2.img bs=1M count=25 conv=sparse
25+0 records in
25+0 records out
26214400 bytes (26 MB, 25 MiB) copied, 0.00347987 s, 7.5 GB/s
[/tmp]$ dd if=/dev/zero of=3.img bs=1M count=25 conv=sparse
25+0 records in
25+0 records out
26214400 bytes (26 MB, 25 MiB) copied, 0.00330069 s, 7.9 GB/s
[/tmp]$ du  1.img 
0       1.img

Now I can make loopdevices and assemble array:

[/tmp]$ sudo losetup loop0 1.img 
[/tmp]$ sudo losetup loop1 2.img 
[/tmp]$ sudo losetup loop2 3.img 
[/tmp]$ sudo mdadm --create /dev/md0 --level=0 --raid-devices=3 /dev/loop0 /dev/loop1 /dev/loop2
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[/tmp]$ sudo mkfs.ext4 /dev/md0 
mke2fs 1.42.11 (09-Jul-2014)
Discarding device blocks: done                            
Creating filesystem with 73728 1k blocks and 18432 inodes
Filesystem UUID: 8123197c-a9aa-434d-9233-103fe20727ed
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[/tmp]$ mkdir mnt/
[/tmp]$ sudo mount /dev/md0 mnt/
[/tmp]$ df -h mnt/
Filesystem      Size  Used Avail Use% Mounted on
/dev/md0         66M  1.3M   60M   3% /tmp/mnt
[/tmp]$ cat /proc/mdstat 
Personalities : [raid0] 
md0 : active raid0 loop2[2] loop1[1] loop0[0]
      73728 blocks super 1.2 512k chunks

unused devices: <none>
[/tmp]$ du -h 1.img 2.img 3.img 
1.3M    1.img
1.6M    2.img
1.6M    3.img

Sparse files will grow up to the maximum size, as data is written to them. They will not shrink if files inside the filesystem is deleted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .