Now that we have a raid array created, we are going to create some virtual drives. Why virtual drives? Well, we have one large terabyte drive right now, and if we just put folders in there, it can quickly get cumbersome. You have no control on size of those folders, and permissions can be more difficult. And if you try to share this drive, you can’t assign different drive letters in windows to different folders, just one to the drive. One other issue is file system. I am going to use just a basic file system here, but in the past I have created different file systems based on the type of use ie. large video files, small text files, etc. Making those decisions is beyond the scope of this tutorial, and I have decided that for my purposes now, it doesn’t matter that much. You can decided differently.
What we will discuss is using LVM. This enables you to set up virtual drives that can contain different file systems, and that can be grown and shrunk (usually) to fit the space needs of the system. We will look at maintenance of these file systems at a later tutorial. Here we will create a backup, and a pictures virtual drive. We will not use the full terabyte of space, so that we can grow these as needed, or add another for say music at another time.
I will once again be doing this on an ubuntu system, but the use of these tools is fairly standard across linux distributions.
First we will need to make sure that you have LVM installed.
sudo apt-get install lvm2
We need to create what is called a physical volume. We need to tell LVM what actual physical drives are involved. Lets check what drives we have again.
$ sudo fdisk -l Disk /dev/sda: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 1 121601 976760001 fd Linux raid autodetect Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xfe76bc93 Device Boot Start End Blocks Id System /dev/sdb1 1 121601 976760001 fd Linux raid autodetect
This is just a partial list of the drives. See that the /dev/sda1 and /dev/sdb1 drives have a system type of fd. In the last part of teh tutorial we set up software raid. If you are NOT using raid, you will need to add these devices to your physical volume. For us, we are going to add /dev/md0 that we created last time. Lets just verify that the array is there.
$ sudo mdadm --detail --scan ARRAY /dev/md0 level=raid1 num-devices=2 metadata=00.90 UUID=****
Note: all UUID’s will be replaced with **** in this doc. They will be different on every machine anyway.
As you can see, array /dev/md0 is ready to go. Lets create that physical volume finally.
sudo pvcreate /dev/md0
You can verify that it is created with the pvdisplay command.
$ sudo pvdisplay "/dev/md0" is a new physical volume of "931.51 GB" --- NEW Physical volume --- PV Name /dev/md0 VG Name PV Size 931.51 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID ****
Now we need to create our volume group. That last step identified what hardware LVM has available. This next step groups that hardware into volume groups. I will call my “nas”.
sudo vgcreate nas /dev/md0
We can then verify our volume group.
$ sudo vgdisplay --- Volume group --- VG Name nas System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 931.51 GB PE Size 4.00 MB Total PE 238466 Alloc PE / Size 0 / 0 Free PE / Size 238466 / 931.51 GB VG UUID ****
Next, we can finally create our virtual drives. I am going to create a backup drive of 100 gig, and a pictures drive of 400 gig, both which are added to the “nas” volume group. You can create drives of what ever size you would like.
sudo lvcreate --name backup --size 100G nas sudo lvcreate --name pictures --size 400G nas
You can see information about these virtual drives with another display command. Guess what it is.
$ sudo lvdisplay --- Logical volume --- LV Name /dev/nas/backup VG Name nas LV UUID gqrIVE-YtS4-cBne-QyPK-oMO1-7V7V-UaBoUL LV Write Access read/write LV Status available # open 0 LV Size 100.00 GB Current LE 25600 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0 --- Logical volume --- LV Name /dev/nas/pictures VG Name nas LV UUID oDxJJi-lxsG-9RHw-RBME-oJah-jOJJ-J8I4p3 LV Write Access read/write LV Status available # open 0 LV Size 400.00 GB Current LE 102400 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:1
Now that we have our virtual drives, can we start filling them up? Not quite. We need partitions on them. These drives are just like a bare drive from the factory. We can put whatever file system we want on them. I am just going to use ext3. This may not be the best file system out there, but it is proven, and works good enough for me.
sudo mkfs.ext3 /dev/nas/backup sudo mkfs.ext3 /dev/nas/pictures
That takes a little bit of time, just as would without LVM. As far as your programs, and bash, and Gnome are concerned, /dev/nas/backup is just another drive. It does not care, and does no know that underneath all this is a raid array and virtual drives.
Now we need to get them mounted so that they are useable. First off, I create a couple of mount points. I like to keep them organized.
sudo mkdir /var/nas sudo mkdir /var/nas/backup /var/nas/pictures sudo mount /dev/nas/backup /var/nas/backup sudo mount /dev/nas/pictures /var/nas/pictures
Now, do a “df” to see the drives on the system and the space used.
$ df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdd1 186693520 2469660 174740292 2% / /dev/mapper/nas-backup 103212320 192248 97777192 1% /var/nas/backup /dev/mapper/nas-pictures 412849328 203156 391674652 1% /var/nas/pictures
Note: I removed other system file systems that we are not talking about here.
You can see that our two drives are there. They are listed at /var/mapper/nas-backup and /var/mapper/nas-pictures, but they are the /dev/nas/backup and /dev/nas/pictures we have been setting up.
Now you can copy your data into these drives.
I am not the only one that uses these drives, and they will be shared on samba (later tutorial) so I like to change the permissions on these folders. I will create a “nas” group, add myself (insert your user id for *user*), and change the permissions.
sudo groupadd nas sudo adduser *user* nas sudo chown -R *user*:nas /var/nas/backup sudo chown -R *user*:nas /var/nas/pictures
The file permissions are set up as writable by owner and readable by group and other. I will leave them this way for now.
Things look good to go, and they would for awhile, until you reboot. Then your drives would disappear. We need to make them a little more permanent. We do this by putting some entries in the /etc/fstab file. This is the list of all mountable file systems that the OS uses to connect things up when booting.
This file in Ubuntu is using UUID’s, so we will to. First thing you need to do is find out what yours are. So…
$ sudo blkid /dev/sdc1: UUID="****1" SEC_TYPE="ext2" TYPE="ext3" /dev/sdd1: UUID="****2" TYPE="ext3" /dev/sdd5: TYPE="swap" UUID="****3" /dev/sda1: UUID="****4" TYPE="mdraid" /dev/sdb1: UUID="****5" TYPE="mdraid" /dev/md0: UUID="****6" TYPE="lvm2pv" /dev/mapper/nas-backup: UUID="****7" TYPE="ext3" /dev/mapper/nas-pictures: UUID="****8" TYPE="ext3"
You can see the unique ID’s that are assigned to the drives in the array, the raid array its self, the LVM physical volume, and finally, the two logical volumes. Use these UUID’s that you get when you execute blkid. Now lets edit /etc/fstab
$ sudo nano -w /etc/fstab # /etc/fstab: static file system information. # #
proc /proc proc defaults 0 0 # /dev/sdd1 UUID=****2 / ext3 relatime,errors=remount-ro 0 $ # /dev/sdd5 UUID=****3 none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0 #/dev/nas/backup UUID=****7 /var/nas/backup ext3 relatime,noexec 0 2 #/dev/nas/pictures UUID=****8 /var/nas/pictures ext3 relatime,noexec 0 2
You shouldn’t have to change anything except add the lines at the bottom for the backup and pictures drives (or whatever you created) . Please use the UUID’s you found from blkid.
Press ctrl-x to exit nano and save the file.
Try a reboot and see how it works. Once you bring the system back up, open a terminal and type df. This will show you all mounted drives, and your new drives should be there.