Monday, April 8, 2013

Step by step instructions for installing a software RAID 1 mirror using gmirror and GPT partitions

Step 1: Setup The Partitions

Once inside the shell here are the commands to setup GPT and slice up both disks.  These examples assume you are doing this on disk 'ada0' and 'ada1' (SATA), if you are using SCSI you'd do da0, da1:

# ---- Setup 1st disk
#
gpart create -s gpt da0
gpart add -s 64k -t freebsd-boot -l boot0 da0
gpart add -s 8G -t freebsd-swap -l swap0 da0
gpart add -t freebsd-ufs -l disk00 da0

# -- Install boot code to first disk
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 da0

# ---- Setup 2nd disk
#
gpart create -s gpt da1
gpart add -s 64k -t freebsd-boot -l boot1 da1
gpart add -s 8G -t freebsd-swap -l swap1 da1
gpart add -t freebsd-ufs -l disk02 da1

# -- Install boot code to 2nd disk
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada1
 
**note: continue to all harddisk as above example
 
 [root@nas-master ~]# gpart add -t freebsd-ufs -l disk00/1/2/3/ da0/1/2/3

[root@nas-master ~]# gpart show -l

=>      63  15131573  da4  MBR  (7.2G)
        63    771057    1  (null)  [active]  (376M)
    771120   6538455    2  (null)  (3.1G)
   7309575   7807590    3  (null)  (3.7G)
  15117165     14471       - free -  (7.1M)

=>     0  771057  da4s1  BSD  (376M)
       0      65         - free -  (32k)
      65  770944      1  (null)  (376M)
  771009      48         - free -  (24k)

=>      0  6538455  da4s2  BSD  (3.1G)
        0       16         - free -  (8.0k)
       16  6538432      1  (null)  (3.1G)
  6538448        7         - free -  (3.5k)

=>       34  585871897  da0  GPT  (279G)
         34  585871897    1  disk00  (279G)

=>       34  585871897  da1  GPT  (279G)
         34  585871897    1  disk01  (279G)

=>        34  3906963565  da2  GPT  (1.8T)
          34  3906963565    1  disk02  (1.8T)

=>        34  3906963565  da3  GPT  (1.8T)
          34  3906963565    1  disk03  (1.8T)

Step 2: Setup The Gmirror ProvidersBefore we proceed we need to have GEOM "re-taste" the partitions so our nice labels show up in /dev/gpt/:

[root@nas-master ~]# true > /dev/da0/1/2/3


# You can check to make sure this worked by running:
[root@nas-master ~]# ls -l /dev/gpt/total 0
crw-r-----  1 root  operator    0, 171 Mar 11 03:33 disk00
crw-r-----  1 root  operator    0, 132 Mar 11 03:33 disk01
crw-r-----  1 root  operator    0, 140 Mar 11 03:34 disk02
crw-r-----  1 root  operator    0, 161 Mar 11 03:34 disk03

Now we can continue to build the mirror providers for each of our partitions:

# -- Build gmirrors
[root@nas-master ~]# gmirror label disk00 /dev/gpt/disk00 /dev/gpt/disk01
[root@nas-master ~]# gmirror label disk02 /dev/gpt/disk02 /dev/gpt/disk03
# -- Load the geo_mirror KLD
[root@nas-master ~]# kldload geom_mirror
# -- Check status 
[root@nas-master ~]# gmirror status
         Name    Status  Components
mirror/disk02  COMPLETE  gpt/disk03 (ACTIVE)
                                         gpt/disk02 (ACTIVE)
mirror/disk00  COMPLETE gpt/disk01 (ACTIVE)
                                         gpt/disk00 (ACTIVE)

Step 3: Create And Mount The Root (/) Filesystem
Here we actually format the root filesystem, enabling soft updates (-U).  I also use "-L disk" to set the filesystem label but this isn't needed.  Then we mount the new filesystem in /mnt (which is where the installer expects the target filesystem to be).
[root@nas-master ~]# newfs -U -L disk00 /dev/mirror/disk00
[root@nas-master ~]# newfs -U -L disk02 /dev/mirror/disk02

[root@nas-master ~]# mount /dev/mirror/disk00 /mnt[root@nas-master ~]# mount /dev/mirror/disk02 /mnt02

now need to create the fstab file which will be put into place by the installer

# Device                    Mountpoint  FStype  Options         Dump    Pass#

/dev/mirror/disk00              /               ufs     rw      1       1
/dev/mirror/disk02              /               ufs     rw      1       1
Step 4: Final Configuration
# -- Make sure gmirror module comes up on boot
[root@nas-master ~]# echo 'geom_mirror_load="YES"' >> /boot/loader.conf




Friday, March 29, 2013

Extending LVM using pvcreate, vgcreate, lvcreate, lvextend and resize2fs

 

components of LVM are as follows:
1. VG – Volume Group: high level container that holds one or more physical or logical volumes.
2. PV – Physical Volume: represents a storage device such as a disk drive or storage media.
3. PE – Physical Extent: each physical volume is divided into equal size blocks called physical extents.
4. LV – Logical Volume: eqivalent to a disk partition and can contain a filesystem.
5. LE – Logical Extent: Each logical volume (LV) is divided into equal size blocks called logical extents.
Creating new partition
First you need to add a new disk, it does not matter whether it is a virtual or physical. In my case I have added a Disk /dev/vdb.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@mytestbox ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.3 (Santiago)
[root@mytestbox ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007c501
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3         409      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2             409       41611    20765696   8e  Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/mapper/vg_01-swap_vol: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
<p>Disk /dev/mapper/vg_01-root_vol: 12.7 GB, 12650020864 bytes
255 heads, 63 sectors/track, 1537 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
<p>Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Next you need to create a partition on this new disk. For that we will use fdisk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@mytestbox ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3467714a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3467714a
Device Boot      Start         End      Blocks   Id  System
We will create a new primary partition
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Command (m for help): n
Command action<br />
   e   extended<br />
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-41610, default 1):press enter
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-41610, default 41610):press enter
Using default value 41610
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
And check with fdisk if it has been recognized
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@mytestbox ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007c501
Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3         409      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2             409       41611    20765696   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3467714a
Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       41610    20971408+  8e  Linux LVM
[root@mytestbox ~]#
Creating physical volume
First let’s check the size of existing physical volume
1
2
3
4
<br />
[root@mytestbox ~]# pvs
  PV         VG    Fmt  Attr PSize  PFree
  /dev/vda2  vg_01 lvm2 a--  19.78g    0
And create a new physical volume and check if it worked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[root@mytestbox ~]# pvcreate /dev/vdb1
  Writing physical volume data to disk &quot;/dev/vdb1&quot;
  Physical volume &quot;/dev/vdb1&quot; successfully created
[root@mytestbox ~]# pvs
  PV         VG    Fmt  Attr PSize  PFree
  /dev/vda2  vg_01 lvm2 a--  19.78g     0
  /dev/vdb1        lvm2 a--  20.00g 20.00g
[root@mytestbox ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               vg_01
  PV Size               19.80 GiB / not usable 23.00 MiB
  Allocatable           yes (but full)
  PE Size               32.00 MiB
  Total PE              633
  Free PE               0
  Allocated PE          633
  PV UUID               vp2QRP-Ufi4-2f3v-afSI-o4pM-2hYb-H4YRoh
&quot;/dev/vdb1&quot; is a new physical volume of &quot;20.00 GiB&quot;
  --- NEW Physical volume ---
  PV Name               /dev/vdb
  VG Name<br />
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               7X10kE-GF36-iuhE-1ja6-9LLa-q2CI-hWRiao
[root@mytestbox ~]#
Extending volume group
Now it’s time to extend our volume group, Please note the values Free PE / Size before and after the extend.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[root@mytestbox ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_01
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.78 GiB
  PE Size               32.00 MiB
  Total PE              633
  Alloc PE / Size       633 / 19.78 GiB
  Free  PE / Size       0 / 0
  VG UUID               qHhhfc-HvnQ-bS2t-dUqX-buOP-MWCf-THdQQP

[root@mytestbox ~]# vgextend vg_01 /dev/vdb1
  Volume group &quot;vg_01&quot; successfully extended
[root@mytestbox ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_01
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               39.75 GiB
  PE Size               32.00 MiB
  Total PE              1272
  Alloc PE / Size       633 / 19.78 GiB
  Free  PE / Size       639 / 19.97 GiB
  VG UUID               qHhhfc-HvnQ-bS2t-dUqX-buOP-MWCf-THdQQP
[root@mytestbox ~]#
Extending logical volume
Now, as we got a volume group extended, we can extend a desired logical volume. In my case it will be a root partition.
1
2
3
4
[root@mytestbox ~]# lvextend -L +19G /dev/vg_01/root_vol (e.g, /dev/mapper/VolGroup00-LogVo100)
  Extending logical volume root_vol to 30.78 GiB
  Logical volume root_vol successfully resized
And resize file system so now size can now be visible to the system
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
root@mytestbox ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_01-root_vol
                       12G  1.3G  9.8G  12%
tmpfs                 246M     0  246M   0% /dev/shm
/dev/vda1             194M   78M  106M  43% /boot
[root@mytestbox ~]# resize2fs /dev/vg_01/root_vol
resize2fs 1.41.12 (17-May-2010
Filesystem at /dev/vg_01/root_vol is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_01/root_vol to 8069120 (4k) blocks.
The filesystem on /dev/vg_01/root_vol is now 8069120 blocks long.
[root@mytestbox ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_01-root_vol
                       31G  1.3G   28G   5% /
tmpfs                 246M     0  246M   0% /dev/shm
/dev/vda1             194M   78M  106M  43% /boot
[root@mytestbox ~]#