Total Pageviews

Friday, 21 October 2016

LVM (Logical Volume Manager) !!!

I thought of uploading posts related to Linux since many days, all these days I have posted things related to Solaris itself, so I wanted to start Linux... So the basic thing in the Linux OS is the LVM. 

ubu@ubuntu:~$ su -
Password:
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# df -kh
Filesystem                   Size  Used Avail Use% Mounted on
udev                         982M     0  982M   0% /dev
tmpfs                        201M  3.3M  197M   2% /run
/dev/mapper/ubuntu--vg-root  5.4G  1.3G  3.8G  26% /
tmpfs                       1001M     0 1001M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                       1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                    472M   55M  393M  13% /boot
tmpfs                        100K     0  100K   0% /run/lxcfs/controllers
cgmfs                        100K     0  100K   0% /run/cgmanager/fs
tmpfs                        201M     0  201M   0% /run/user/1000
root@ubuntu:~#

For Linux machines meta devices like in Solaris we have Physical Volumes (PVs). Below is the command and output to display PV.

root@ubuntu:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               ubuntu-vg
  PV Size               7.52 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1925
  Free PE               0
  Allocated PE          1925
  PV UUID               KBhVnP-30fy-u8QV-IXHK-1zLE-98kR-1Ducfa
root@ubuntu:~#

As you see I already have a PV under which a VG (Volume Group) created, this is because my root disk is under LVM. So upon a PV we will create VG...

root@ubuntu:~# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  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               7.52 GiB
  PE Size               4.00 MiB
  Total PE              1925
  Alloc PE / Size       1925 / 7.52 GiB
  Free  PE / Size       0 / 0
  VG UUID               9ZjLhk-IoTQ-Qfli-j9XS-PjgW-7FDv-3SaqTa

root@ubuntu:~#

Above "ubuntu-vg" is VG for my root and swap. Now LVs (Logical Volumes) comes to the scene. So you can see my lvs for root and swap below.

root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                stDQ9W-X34I-4eFk-7rDq-SLRL-0kpv-hLki1z
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 1
  LV Size                5.52 GiB
  Current LE             1413
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                3K30n5-M7ew-Znww-km5q-IRQr-dqfz-E9Dtzr
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

root@ubuntu:~#

Like "format" command in Solaris, we have command "fdisk -l" to display the disks... I compare all the time because it is easy to understand somethings when we already know few similar things...

root@ubuntu:~# fdisk -l | more
Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram3: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram4: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram5: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram6: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram7: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram8: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram9: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram10: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram11: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram12: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram13: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram14: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/ram15: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa51c9f65

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   999423   997376  487M 83 Linux
/dev/sda2       1001470 16775167 15773698  7.5G  5 Extended
/dev/sda5       1001472 16775167 15773696  7.5G 8e Linux LVM

Disk /dev/mapper/ubuntu--vg-root: 5.5 GiB, 5926551552 bytes, 11575296 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/ubuntu--vg-swap_1: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
root@ubuntu:~#

Now I will add few disks for our learning purpose...(It is so easy in Oracle Virtual box or VMware Workstation).

Again logging in,

ubu@ubuntu:~$
ubu@ubuntu:~$ su -
Password:
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# df -kh
Filesystem                   Size  Used Avail Use% Mounted on
udev                         982M     0  982M   0% /dev
tmpfs                        201M  3.3M  197M   2% /run
/dev/mapper/ubuntu--vg-root  5.4G  1.3G  3.8G  26% /
tmpfs                       1001M     0 1001M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                       1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                    472M   55M  393M  13% /boot
cgmfs                        100K     0  100K   0% /run/cgmanager/fs
tmpfs                        100K     0  100K   0% /run/lxcfs/controllers
tmpfs                        201M     0  201M   0% /run/user/1000
root@ubuntu:~#

This time let us see output which we require,

root@ubuntu:~# fdisk -l | grep /dev/sd
Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 sectors
/dev/sda1  *       2048   999423   997376  487M 83 Linux
/dev/sda2       1001470 16775167 15773698  7.5G  5 Extended
/dev/sda5       1001472 16775167 15773696  7.5G 8e Linux LVM
Disk /dev/sdb: 100 MiB, 104857600 bytes, 204800 sectors
Disk /dev/sdc: 100 MiB, 104857600 bytes, 204800 sectors
Disk /dev/sdd: 100 MiB, 104857600 bytes, 204800 sectors
root@ubuntu:~#

root@ubuntu:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               ubuntu-vg
  PV Size               7.52 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1925
  Free PE               0
  Allocated PE          1925
  PV UUID               KBhVnP-30fy-u8QV-IXHK-1zLE-98kR-1Ducfa

root@ubuntu:~#

Let us create PVs from disks we added,

root@ubuntu:~# pvcreate /dev/sdb /dev/sdc /dev/sdd
  Physical volume "/dev/sdb" successfully created
  Physical volume "/dev/sdc" successfully created
  Physical volume "/dev/sdd" successfully created
root@ubuntu:~#

root@ubuntu:~# pvdisplay /dev/sdb /dev/sdc /dev/sdd
  "/dev/sdd" is a new physical volume of "100.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd
  VG Name
  PV Size               100.00 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               TFtlnW-ZiPx-GrQc-ws9d-md37-i8ij-QeB9gG

  "/dev/sdb" is a new physical volume of "100.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name
  PV Size               100.00 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               j7O15i-NSPS-ppJO-0263-x1hP-P222-veof5g

  "/dev/sdc" is a new physical volume of "100.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name
  PV Size               100.00 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               tNCHDy-8bdJ-JFS6-Zfhe-TFLK-YQgz-iDL9Lt

root@ubuntu:~#

Its time to create VG on our PV...

root@ubuntu:~# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  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               7.52 GiB
  PE Size               4.00 MiB
  Total PE              1925
  Alloc PE / Size       1925 / 7.52 GiB
  Free  PE / Size       0 / 0
  VG UUID               9ZjLhk-IoTQ-Qfli-j9XS-PjgW-7FDv-3SaqTa

root@ubuntu:~#

root@ubuntu:~# vgcreate vol1 /dev/sdb /dev/sdc /dev/sdd
  Volume group "vol1" successfully created
root@ubuntu:~#

root@ubuntu:~# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  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               7.52 GiB
  PE Size               4.00 MiB
  Total PE              1925
  Alloc PE / Size       1925 / 7.52 GiB
  Free  PE / Size       0 / 0
  VG UUID               9ZjLhk-IoTQ-Qfli-j9XS-PjgW-7FDv-3SaqTa

  --- Volume group ---
  VG Name               vol1
  System ID
  Format                lvm2
  Metadata Areas        3
  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                3
  Act PV                3
  VG Size               288.00 MiB
  PE Size               4.00 MiB
  Total PE              72
  Alloc PE / Size       0 / 0
  Free  PE / Size       72 / 288.00 MiB
  VG UUID               Kpd01H-UQqs-n1f9-VVA3-6buC-f1EO-pTK7v1

root@ubuntu:~#

Then its time for LV....

root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                stDQ9W-X34I-4eFk-7rDq-SLRL-0kpv-hLki1z
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 1
  LV Size                5.52 GiB
  Current LE             1413
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                3K30n5-M7ew-Znww-km5q-IRQr-dqfz-E9Dtzr
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

root@ubuntu:~#

Mine is latest ubuntu server, so the default Filesystem will be ext4...

root@ubuntu:~# lvcreate -L 50M vol1 -n mydata1
  Rounding up size to full physical extent 52.00 MiB
WARNING: ext4 signature detected on /dev/vol1/mydata1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/vol1/mydata1.
  Logical volume "mydata1" created.
root@ubuntu:~#
root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                stDQ9W-X34I-4eFk-7rDq-SLRL-0kpv-hLki1z
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 1
  LV Size                5.52 GiB
  Current LE             1413
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                3K30n5-M7ew-Znww-km5q-IRQr-dqfz-E9Dtzr
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

  --- Logical volume ---
  LV Path                /dev/vol1/mydata1
  LV Name                mydata1
  VG Name                vol1
  LV UUID                rggxbf-Tenn-kEZA-FdkQ-aRUb-umHP-o0wLoL
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-06 18:13:53 -0400
  LV Status              available
  # open                 0
  LV Size                52.00 MiB
  Current LE             13
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2

root@ubuntu:~#

One more volume, 

root@ubuntu:~# lvcreate -L 150M vol1 -n mydata2
  Rounding up size to full physical extent 152.00 MiB
WARNING: ext4 signature detected on /dev/vol1/mydata2 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/vol1/mydata2.
  Logical volume "mydata2" created.
root@ubuntu:~#

root@ubuntu:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                stDQ9W-X34I-4eFk-7rDq-SLRL-0kpv-hLki1z
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 1
  LV Size                5.52 GiB
  Current LE             1413
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                3K30n5-M7ew-Znww-km5q-IRQr-dqfz-E9Dtzr
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-04 19:35:42 -0400
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1

  --- Logical volume ---
  LV Path                /dev/vol1/mydata1
  LV Name                mydata1
  VG Name                vol1
  LV UUID                rggxbf-Tenn-kEZA-FdkQ-aRUb-umHP-o0wLoL
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-06 18:13:53 -0400
  LV Status              available
  # open                 0
  LV Size                52.00 MiB
  Current LE             13
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2

  --- Logical volume ---
  LV Path                /dev/vol1/mydata2
  LV Name                mydata2
  VG Name                vol1
  LV UUID                jjFSn5-TE2X-13fq-j9we-QCwf-7ZJk-9H6FOl
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2016-10-06 18:14:10 -0400
  LV Status              available
  # open                 0
  LV Size                152.00 MiB
  Current LE             38
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:3
root@ubuntu:~#

Once done with the LV creation we should make FS on our volume...

root@ubuntu:~# mkfs.ext4 /dev/vol1/mydata1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 53248 1k blocks and 13328 inodes
Filesystem UUID: e49e7c09-88fa-44c1-b988-2cef549dd049
Superblock backups stored on blocks:
        8193, 24577, 40961

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

root@ubuntu:~#

FS creation for our second volume...

root@ubuntu:~# mkfs.ext4 /dev/vol1/mydata2
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 155648 1k blocks and 38912 inodes
Filesystem UUID: c5bdb3ce-eb8a-4e31-89df-33dc802548d6
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
root@ubuntu:~#

root@ubuntu:~# mkdir -p /data1
root@ubuntu:~#
root@ubuntu:~# mkdir -p /data2
root@ubuntu:~#

Now I will mount the FS...

root@ubuntu:~# mount /dev/vol1/mydata1 /data1
root@ubuntu:~#
root@ubuntu:~# mount /dev/vol1/mydata2 /data2
root@ubuntu:~#
root@ubuntu:~# df -kh
Filesystem                   Size  Used Avail Use% Mounted on
udev                         982M     0  982M   0% /dev
tmpfs                        201M  3.3M  197M   2% /run
/dev/mapper/ubuntu--vg-root  5.4G  1.3G  3.8G  26% /
tmpfs                       1001M     0 1001M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                       1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                    472M   55M  393M  13% /boot
cgmfs                        100K     0  100K   0% /run/cgmanager/fs
tmpfs                        100K     0  100K   0% /run/lxcfs/controllers
tmpfs                        201M     0  201M   0% /run/user/1000
/dev/mapper/vol1-mydata1      47M  842K   42M   2% /data1
/dev/mapper/vol1-mydata2     144M  1.6M  132M   2% /data2
root@ubuntu:~#

To make it permanent mount, to mount at boot time just add the entries in the /etc/fstab file...

root@ubuntu:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/ubuntu--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=8d74a25e-fef8-45d4-ab90-1cb14910d7f0 /boot           ext2    defaults        0       2
/dev/mapper/ubuntu--vg-swap_1 none            swap    sw              0       0
root@ubuntu:~#

root@ubuntu:~# vi /etc/fstab
root@ubuntu:~#

root@ubuntu:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/ubuntu--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=8d74a25e-fef8-45d4-ab90-1cb14910d7f0 /boot           ext2    defaults        0       2
/dev/mapper/ubuntu--vg-swap_1 none            swap    sw              0       0
/dev/vol1/mydata1 /data1               ext4    rw 0       1
/dev/vol1/mydata2 /data2               ext4    rw 0       1
root@ubuntu:~#

After rebooting...

login as: ubu@10.0.0.143's password:
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-31-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

79 packages can be updated.
41 updates are security updates.

Last login: Thu Oct  6 18:44:28 2016
ubu@ubuntu:~$
ubu@ubuntu:~$ df -kh
Filesystem                   Size  Used Avail Use% Mounted on
udev                         982M     0  982M   0% /dev
tmpfs                        201M  3.4M  197M   2% /run
/dev/mapper/ubuntu--vg-root  5.4G  1.3G  3.8G  26% /
tmpfs                       1001M     0 1001M   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                       1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                    472M   55M  393M  13% /boot
/dev/mapper/vol1-mydata2     144M  1.6M  132M   2% /data2
/dev/mapper/vol1-mydata1      47M  842K   42M   2% /data1
cgmfs                        100K     0  100K   0% /run/cgmanager/fs
tmpfs                        201M     0  201M   0% /run/user/0
tmpfs                        201M     0  201M   0% /run/user/1000
ubu@ubuntu:~$

That's it for the volume and filesystem creation under LVM...

####################################################################################

Thursday, 20 October 2016

Solaris 10 Branded ZONE in Solaris 11 Host !!!

In this post, I am going to show how to configure and install a branded zone. In my case I am taking my Solaris 11 host as global zone and installing Solaris 10 in it.

We need a branded zone concept when base machine or global zone is of different OS version and if we are in need of another OS version zone within it.

A branded zone should be installed with separate OS unlike for a whole root zone where all packages were copied from global zone and sparse root zone where the global zone packages were shared.

root@Solaris11:~# zoneadm list -vc
  ID NAME             STATUS      PATH                         BRAND      IP
   0 global           running     /                            solaris    shared
root@Solaris11:~#
root@Solaris11:~#            As you see my Solaris 11 host is brand new with no non global zones...


root@Solaris11:~#
root@Solaris11:~# mkdir -p /export/home/zone1     ----- home directory for our Zone...
root@Solaris11:~#

root@Solaris11:~# dladm show-phys
LINK              MEDIA                STATE      SPEED  DUPLEX    DEVICE
net1              Ethernet             unknown    0      unknown   e1000g1
net2              Ethernet             unknown    0      unknown   e1000g2
net0              Ethernet             up         1000   full      e1000g0
root@Solaris11:~#

root@Solaris11:~# zonecfg -z zone1
Use 'create' to begin configuring a new zone.
zonecfg:zone1> create -b                                     to state it is a branded zone....
zonecfg:zone1>
zonecfg:zone1>
zonecfg:zone1> set brand=solaris10
zonecfg:zone1> 
zonecfg:zone1>
zonecfg:zone1> set zonepath=/export/home/zone1
zonecfg:zone1>
zonecfg:zone1> set autoboot=true
zonecfg:zone1> add net
zonecfg:zone1:net> set address=10.0.0.175/24
zonecfg:zone1:net> set physical=net0
zonecfg:zone1:net> info
net 0:
        address: 10.0.0.175/24
        allowed-address not specified
        configure-allowed-address: true
        physical: net0
        defrouter not specified
zonecfg:zone1:net>
zonecfg:zone1:net>
zonecfg:zone1:net> end
zonecfg:zone1>
zonecfg:zone1> info
zonename: zone1
zonepath: /export/home/zone1
brand: solaris10
autoboot: true
autoshutdown: shutdown
bootargs:
pool:
limitpriv:
scheduling-class:
ip-type: exclusive
hostid:
fs-allowed:
net 0:
        address: 10.0.0.175/24
        allowed-address not specified
        configure-allowed-address: true
        physical: net0
        defrouter not specified
zonecfg:zone1>
zonecfg:zone1>
zonecfg:zone1> set ip-type=shared
zonecfg:zone1> verify
zonecfg:zone1> commit
zonecfg:zone1> exit
root@Solaris11:~#
root@Solaris11:~#
root@Solaris11:~# zoneadm list -vc
  ID NAME             STATUS      PATH                         BRAND      IP
   0 global           running     /                            solaris    shared
   - zone1            configured  /export/home/zone1           solaris10  shared
root@Solaris11:~#

Let me login to my Solaris 10 host to create Flash Archive...

root@Solaris11:~#
root@Solaris11:~# ssh 10.0.0.55
The authenticity of host '10.0.0.55 (10.0.0.55)' can't be established.
RSA key fingerprint is 83:07:bd:a2:f2:02:46:df:67:3d:01:af:ed:d8:9a:cf.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.55' (RSA) to the list of known hosts.
Password:
Last login: Tue Oct  4 22:02:59 2016 from 10.0.0.43
Oracle Corporation      SunOS 5.10      Generic Patch   January 2005
#
# bash
bash-3.2# uname -a
SunOS Solaris10 5.10 Generic_147148-26 i86pc i386 i86pc

bash-3.2# df -kh /
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d0s0        8.1G   3.9G   4.1G    49%    /
bash-3.2#
bash-3.2# 

bash-3.2# flarcreate -n arch1 -c archive1.flar               --- cmd to create flash archive....
Full Flash
Checking integrity...
Integrity OK.
Running precreation scripts...
Precreation scripts done.
Determining the size of the archive...

7896142 blocks
The archive will be approximately 2.13GB.
Creating the archive...
7896144 blocks
Archive creation complete.
Running postcreation scripts...
Postcreation scripts done.

Running pre-exit scripts...
Pre-exit scripts done.
bash-3.2#

bash-3.2# pwd
/
bash-3.2#
bash-3.2# ls
TT_DB          boot           etc            kernel         mnt            platform       system         var
archive1.flar  dev            export         lib            net            proc           tmp            vol
bin            devices        home           lost+found     opt            sbin           usr
bash-3.2#
bash-3.2#
bash-3.2# ls -lrth archive1.flar
-rw-r--r--   1 root     root        2.1G Oct  4 22:31 archive1.flar
bash-3.2#

bash-3.2# df -kh /
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d0s0        8.1G   6.0G   2.0G    76%    /
bash-3.2#
bash-3.2# exit
# Connection to 10.0.0.55 closed.
root@Solaris11:~#
root@Solaris11:~#
root@Solaris11:~# scp 10.0.0.55:/archive1.flar /export/home/
Password:
archive1.flar        100% |***********************************************************************|  2188 MB    06:35
root@Solaris11:~#
root@Solaris11:~#
root@Solaris11:~#
root@Solaris11:~# zoneadm list -vc
  ID NAME             STATUS      PATH                         BRAND      IP
   0 global           running     /                            solaris    shared
   - zone1            configured  /export/home/zone1           solaris10  shared
root@Solaris11:~#

Let us install OS in our new Zone....

root@Solaris11:~#
root@Solaris11:~# zoneadm -z zone1 install -a /export/home/archive1.flar -p
The following ZFS file system(s) have been created:
    rpool/export/home/zone1
Progress being logged to /var/log/zones/zoneadm.20161004T232607Z.zone1.install
    Installing: This may take several minutes...
Postprocessing: This may take a while...
   Postprocess: Updating the image to run within a zone
   Postprocess: Migrating data
        from: rpool/export/home/zone1/rpool/ROOT/zbe-0
          to: rpool/export/home/zone1/rpool/export
   Postprocess: A backup copy of /export is stored at /export.backup.20161004T233804Z.
It can be deleted after verifying it was migrated correctly.

        Result: Installation completed successfully.
Log saved in non-global zone as /export/home/zone1/root/var/log/zones/zoneadm.20161004T232607Z.zone1.install
root@Solaris11:~#
root@Solaris11:~#
root@Solaris11:~# zoneadm list -vc
  ID NAME             STATUS      PATH                         BRAND      IP
   0 global           running     /                            solaris    shared
   - zone1            installed   /export/home/zone1           solaris10  shared
root@Solaris11:~#

Next step is to bring our ZONE to "ready" state....

root@Solaris11:~#
root@Solaris11:~# zoneadm -z zone1 ready
root@Solaris11:~#
root@Solaris11:~# zoneadm list -vc
  ID NAME             STATUS      PATH                         BRAND      IP
   0 global           running     /                            solaris    shared
   2 zone1            ready       /export/home/zone1           solaris10  shared
root@Solaris11:~#

Now boot the zone...

root@Solaris11:~# zoneadm -z zone1 boot
root@Solaris11:~# zoneadm list -vc
  ID NAME             STATUS      PATH                         BRAND      IP
   0 global           running     /                            solaris    shared
   2 zone1            running     /export/home/zone1           solaris10  shared
root@Solaris11:~#

Thats it, done with configuration and installation part in which we came across different states of a Zone...

root@Solaris11:~# zlogin -C zone1
[Connected to zone 'zone1' console]

Solaris10 console login: root
Password:
Last login: Tue Oct  4 22:10:05 from 10.0.0.75
Oct  4 19:51:17 Solaris10 login: ROOT LOGIN /dev/console
Oracle Corporation      SunOS 5.10      Generic Patch   January 2005
#
#
# bash
bash-3.2#
bash-3.2# ifconfig -a
lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000
net0:1: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 2
        inet 10.0.0.175 netmask ff000000 broadcast 10.255.255.255
lo0:1: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1
        inet6 ::1/128
bash-3.2#
bash-3.2#
bash-3.2# who                                     -C is for Console login....
root       console      Oct  4 19:51
bash-3.2#
bash-3.2#
bash-3.2# df -kh
Filesystem             Size   Used  Available Capacity  Mounted on
rpool/ROOT/zbe-0       6.0G   3.8G       2.1G    65%    /
rpool/ROOT/zbe-0/var   6.0G    79M       2.1G     4%    /var
/.SUNWnative/lib       4.9G   2.8G       2.1G    57%    /.SUNWnative/lib
/.SUNWnative/platform
                       4.9G   2.8G       2.1G    57%    /.SUNWnative/platform
/.SUNWnative/sbin      4.9G   2.8G       2.1G    57%    /.SUNWnative/sbin
/.SUNWnative/usr       4.9G   2.8G       2.1G    57%    /.SUNWnative/usr
/dev                     0K     0K         0K     0%    /dev
proc                     0K     0K         0K     0%    /proc
ctfs                     0K     0K         0K     0%    /system/contract
mnttab                   0K     0K         0K     0%    /etc/mnttab
objfs                    0K     0K         0K     0%    /system/object
swap                   1.2G   344K       1.2G     1%    /etc/svc/volatile
/usr/lib/libc/libc_hwcap1.so.1
                       5.9G   3.8G       2.1G    65%    /lib/libc.so.1
fd                       0K     0K         0K     0%    /dev/fd
swap                   1.2G    32K       1.2G     1%    /tmp
/etc/svc/volatile/     1.2G   344K       1.2G     1%    /var/run
rpool/export           6.0G    32K       2.1G     1%    /export
rpool/export/home      6.0G    32K       2.1G     1%    /export/home
rpool                  6.0G    31K       2.1G     1%    /rpool
bash-3.2#
bash-3.2# ~.
[Connection to zone 'zone1' console closed]
root@Solaris11:~#
root@Solaris11:~#
root@Solaris11:~# zoneadm list -vc
  ID NAME             STATUS      PATH                         BRAND      IP
   0 global           running     /                            solaris    shared
   2 zone1            running     /export/home/zone1           solaris10  shared
root@Solaris11:~#
root@Solaris11:~#
root@Solaris11:~# ping 10.0.0.175
10.0.0.175 is alive
root@Solaris11:~#

Easy and simple steps to follow while creating a branded zone, just need a flash archive of required OS version...

#####################################################################################