How can I create one large partiton over two drives in CentOS?

18,027

Solution 1

You need to use LVM (Logical Volume Manager)

First of all , you must be aware that if any of the physical disk fail , the Big 4TB volume will fail too. Backup your data first!

Basically , all you need to do is to partition your data (/dev/sda2 and /dev/sdb1) partition in lvm format then :

  • create two physical volumes (pvcreate /dev/sda2 /dev/sdb1)
  • create one volume group with the two physical volumes (vgcreate VG_DATA /dev/sda2 /dev/sdb1)
  • create one logical volume ( lvcreate -l 100%FREE -n DATA VG_DATA )
  • create the filesystem on your new volume (mkfs.ext3 /dev/VG_DATA/DATA)
  • mount the volume (mount /dev/VG_DATA/DATA /data )

There are dozen of sites with howtos lvm like this one.

Lvm is a lot more than these 4 commands , read the fine manual if you want advanced configuration. I hope it will help you

Solution 2

I personally feel LVM is overkill for this simple task, I would suggest setting up mdadm to create a RAID array.

Now you have two options:

  • either a linear array, which will literally produce a concatenated partition based on two source partitions
  • or RAID-0, which has the additional limitation that the source partitions must be of the same size but provides a substantial performance boost to reading and writing.

However beware, if either disk fails at least half and possibly all of your data will be lost. If you use a linear array some may be recoverable, with RAID-0 it will all almost certainly be destroyed, decide which of these trade-offs you want when deciding the type of array you choose.

Next, you need to create a large partition on each disk, you can do this with fdisk or any other tool, and I wont go into detail here as there are better guides elsewhere.

Then you run mdadm in the form of:

# for a RAID-0 Array
mdadm --create --verbose /dev/md0 --level=stripe /dev/sda1 /dev/sdb2

# for a linear Array
mdadm --create --verbose /dev/md0 --level=linear /dev/sda1 /dev/sdb2

Where /dev/sda1 and /dev/sdb2 are replaced with the partitions we created in the previous step. I then suggest taking a quick browse of the mdadm man page to learn how you may need to maintain this array.

You may choose to use LVM instead as Max has suggested and that may well serve you better if you end up with an extremely complex configuration but I do not feel it is really needed for a simple case like yours, raid may also provide substantial performance improvements over LVM if configured correctly, however that goes beyond the scope of this answer.

Share:
18,027

Related videos on Youtube

Codemonkey
Author by

Codemonkey

Updated on September 18, 2022

Comments

  • Codemonkey
    Codemonkey over 1 year

    I've got a new dedicated server that I want to use purely for backup purposes.

    [root@dedi ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        20G  942M   18G   6% /
    tmpfs           7.8G     0  7.8G   0% /dev/shm
    /dev/sda1       283M   32M  236M  12% /boot
    /dev/sda2       1.8T   68M  1.7T   1% /data
    [root@dedi ~]# cat /proc/partitions
    major minor  #blocks  name
    
       8        0 1953481816 sda
       8        1     307200 sda1
       8        2 1932167168 sda2
       8        3   20480000 sda3
       8        4     524288 sda4
       8       16 1953481816 sdb
    

    I'd like to keep the tmpfs and /boot as they are, and create one big ~4TB partition out of the rest.

    I know this is relatively straightforward stuff, but I'd really appreciate hand walking through it, as I've never done any linux partitioning stuff before, and don't want to make a mess of the brand new box...

    Many thanks

    • Mike
      Mike about 9 years
      I take it you want to combine sda2 with sdb? With a raid 0 like that if either drive has issues all your backups are gone.
    • Codemonkey
      Codemonkey about 9 years
      Correct. How can you tell it's RAID 0? I assumed it would be more "JBOD", which I'm fine with, I have no need for extra performance. I'm backuping to another location as well, and have RAID 1 on the main server, so I'm not overly concerned about not having RAID 1 on this box.
    • MSalters
      MSalters about 9 years
      @Mike: I don't read in the answer that RAID 0 is desired, and it's a bad idea for the reasons you indicated. But how else do you tell Linux to store files on one of two disks/partitions? It's of course unavoidable that you lose a file when the disk it's on crashes and you have no redundancy. The problem with Linux LVM RAID is that apparently it also loses the files on the good disk. That wouldn't be acceptable if it was designed today; it seems the behavior is tolerated only because RAID-0 is ancient.
    • Vality
      Vality about 9 years
      @MSalters Raid0 doesn't work in the way you seem to imply, it doesn't store some files on one disk and some files on the other, it stores alternating "stripes" on each disk, each stripe being usually much less than a file, so most files are on both disks, its meaningless to say that it could save the files on one disk, it just isn't like that. It is not designed for reliability and it should not be expected, it is purely for performance and if used for storing important data should be combined with redundancy and good backup. Raid0 is tolerated because of high read performance, not age.
    • MSalters
      MSalters about 9 years
      @Vality: I know how RAID-0 works, that is exactly why I'm arguing for a non-striped alternative. That's especially relevant here as the read performance of RAID-0 isn't needed for backups (which is mostly writes)
    • Vality
      Vality about 9 years
      @MSalters I am not objecting to your suggestion that an alternative may be more appropriate here. Indeed my answer goes into that in more detail. I merely felt your criticism of raid 0 was much more universal and somewhat unwarranted. It certainly has its disadvantages but it does have a very useful niche and certainly is used for reasons other than being old. Line any system it has trade-offs between advantages and issues, but it certainly does have significant advantages.
  • Codemonkey
    Codemonkey about 9 years
    You give explicit bash commands for all but the first step... seems a shame to almost give full guidance but not quite!
  • Codemonkey
    Codemonkey about 9 years
    Not an answer, should have been a comment.
  • Tom Hallam
    Tom Hallam about 9 years
    Yes, but I can't add comments except to my own posts!
  • answerSeeker
    answerSeeker over 6 years
    Yeah, would've been awesome if he continued. LVM is tricky to setup