RHEL 6 Manually Creating A Logical Volume And Auto Mounting It As an Ext4 file system

RHEL 6 Manually Creating A Logical Volume And Auto Mounting It As Ext4 for a device that has been added to your VM and not previously used.
The device should already be allocated and should show up with no other “fdisk’ed” devices on it – for this example (see my By The Way note immediately below for a caution).
ls /dev/sdd
/dev/sdd
By The Way – you don’t have to use fdisk – you could skip this step but then – the entry won’t be in the device table and somebody may go behind you and mess stuff up – or worse yet – you’ll forget and mess it up yourself – I did that once with a system disk – but that is another post literally – it would was not pretty – now I do this step every time…
[root@bronze Desktop]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x781f9ab4.
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): c
DOS Compatibility flag is not set
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):
Using default value 2097151
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.
[root@bronze Desktop]#
[root@bronze Desktop]# pvcreate /dev/sdd
/dev/sdd: Couldn’t find device. Check your filters?
[root@bronze Desktop]# pvcreate /dev/sdd1
Physical volume “/dev/sdd1” successfully created
[root@bronze Desktop]# vgcreate u04VolGroup /dev/sdd1
Volume group “u04VolGroup” successfully created
[root@bronze Desktop]# lvcreate –size 1G u04VolGroup
Volume group “u04VolGroup” has insufficient free space (255 extents): 256 required.
[root@bronze Desktop]# lvcreate –size 1000M u04VolGroup
Logical volume “lvol0” created.
ot@bronze Desktop]# mkdir /u04
[root@bronze Desktop]# mkfs.ext4 /dev/u04VolGroup/lvol0
mke2fs 1.43-WIP (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
64000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@bronze Desktop]# mount -t ext4 /dev/u04VolGroup/lvol0 /u04
[root@bronze Desktop]# df -h | grep -i /u04
/dev/mapper/u04VolGroup-lvol0
969M 1.3M 902M 1% /u04
[root@bronze Desktop]# cp -p /etc/fstab /etc/fstab.20170107
# add the following line to fstab after backing it up
[root@bronze Desktop]# cat /etc/fstab | grep -i /u04
/dev/mapper/u04VolGroup-lvol0 /u04 ext4 defaults 1 2
Now reboot and make sure /u04 mount auto starts
[root@bronze Desktop]# reboot
df -h | grep -i u04
/dev/mapper/u04VolGroup-lvol0
969M 1.3M 902M 1% /u04

Leave a Comment

Scroll to Top