Add new disk to Red Hat Linux server, create new filesystem without reboot.

If you are running a VMware virtual Red Hat Linux server then it is very easy to add a new disk. For physical servers with hot add capability this is also possible. I am going to show you how to add a new disk to Red Hat Linux complete with a new filesystem, without rebooting the server.

List the disks installed. The command lsscsi is not installed in the default installation of Red Hat, you will need to install it. This will be list of current disks before rescanning.

[root@linux ~]# lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware Virtual disk 1.0 /dev/sda
[2:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb

List all scsi host value.

[root@linux ~]# ll /sys/class/scsi_host
total 0
lrwxrwxrwx 1 root root 0 Jan 14 21:40 host0 -> ../../devices/pci0000:00/0000:00:07.1/host0/scsi_host/host0
lrwxrwxrwx 1 root root 0 Jan 14 21:40 host1 -> ../../devices/pci0000:00/0000:00:07.1/host1/scsi_host/host1
lrwxrwxrwx 1 root root 0 Jan 14 21:40 host2 -> ../../devices/pci0000:00/0000:00:10.0/host2/scsi_host/host2

Normally you would have to reboot the server to see the new disk, but you can rescan the SCSI bus for a new disk without rebooting.

[root@linux ~]# echo “- – -” > /sys/class/scsi_host/host0/scan
[root@linux ~]# echo “- – -” > /sys/class/scsi_host/host1/scan
[root@linux ~]# echo “- – -” > /sys/class/scsi_host/host2/scan

List all disks found, sdc is the new disk that did not appear in the original scan.

[root@linux ~]# lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware Virtual disk 1.0 /dev/sda
[2:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb
[2:0:2:0] disk VMware Virtual disk 1.0 /dev/sdc

Create a new partition on sdc using fdisk.

[root@linux ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xafebcbd2.
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

Command (m for help): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xafebcbd2

Device Boot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ 83 Linux

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): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xafebcbd2

Device Boot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Display the new partition sdc1.

[root@linux ~]# fdisk -l
……………….
………
….
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xafebcbd2

Device Boot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ 8e Linux LVM

Create a new physical volume.

[root@linux ~]# pvcreate /dev/sdc1
dev_is_mpath: failed to get device for 8:33
Physical volume “/dev/sdc1” successfully created

List all physical volumes. Notice sdc1 is not assigned to any volume group yet.

[root@linux ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup lvm2 a– 19.51g 0
/dev/sdb1 VolGroupOpt lvm2 a– 20.00g 0
/dev/sdc1 lvm2 a– 19.99g 19.99g

Create new volume group VoGroupLog on sdc1.

[root@linux ~]# vgcreate voGroupLog /dev/sdc1
Volume group “voGroupLog” successfully created

List all volume groups.

[root@linux ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz–n- 19.51g 0
voGroupLog 1 0 0 wz–n- 19.99g 19.99g
VolGroupOpt 1 1 0 wz–n- 20.00g 0

Create new logical volume lv_log using 100% of available free space in voGroupLog

[root@linux ~]# lvcreate -l 100%FREE -n lv_log voGroupLog
Logical volume “lv_log” created

List all logical volumes.

[root@linux ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao—- 15.57g
lv_swap VolGroup -wi-ao—- 3.94g
lv_log voGroupLog -wi-a—– 19.99g
lv_opt VolGroupOpt -wi-ao—- 20.00g

Make new ext4 filesystem on lv_log.

[root@linux ~]# mkfs.ext4 /dev/mapper/voGroupLog-lv_log
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5240832 blocks
262041 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Create a new directory /MyLog for mounting the new filesystem.

[root@linux /]# mkdir MyLog

List the path for the new logical volume, it is /dev/mapper/VoGroupLog-lv_log. You need this information for mounting it.

[root@linux /]# ll /dev/mapper
total 0
crw-rw—- 1 root root 10, 58 Jan 14 21:40 control
lrwxrwxrwx 1 root root 7 Jan 14 21:40 VolGroup-lv_root -> ../dm-0
lrwxrwxrwx 1 root root 7 Jan 14 21:40 VolGroup-lv_swap -> ../dm-1
lrwxrwxrwx 1 root root 7 Jan 14 21:40 VolGroupOpt-lv_opt -> ../dm-2
lrwxrwxrwx 1 root root 7 Jan 27 11:47 voGroupLog-lv_log -> ../dm-3

Mount the filesystem.

[root@linux /]# mount /dev/mapper/voGroupLog-lv_log /MyLog

List all mounted filesystem.

[root@linux /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4 16G 6.9G 7.7G 48% /
tmpfs tmpfs 7.3G 0 7.3G 0% /dev/shm
/dev/sda1 ext4 485M 92M 368M 20% /boot
/dev/mapper/VolGroupOpt-lv_opt ext4 20G 14G 5.5G 71% /opt
/dev/mapper/voGroupLog-lv_log ext4 20G 172M 19G 1% /MyLog

Add the new mount path to the /etc/fstab file so it will persist after a reboot,add the below line.

/dev/mapper/voGroupLog-lv_log /MyLog ext4 defaults 1 1

About Andrew Lin

Hi, I have always wanted to creat a blog site but never had the time. I have been working in Information Technology for over 15 years. I specialize mainly in networks and server technologies and dabble a little with the programming aspects. Andrew Lin

View all posts by Andrew Lin →