Hot add CPU and disks to a Linux system

In a Linux VM sometimes one might need to add new CPUs and / or disks to the system.


To avoid a reboot I can follow these steps. This is under OpenSUSE and SLES11, but works for any Linux distro.

1. CPU


# ls /sys/devices/system/cpu/
cpu0  cpu1  cpu2  cpu3  cpuidle  intel_pstate  kernel_max  microcode  modalias  offline  online  possible  power  present  uevent

# cat /sys/devices/system/cpu/online
0-2


In this example only 3 CPUs are online and used


# cat /proc/cpuinfo | grep processor
processor       : 0
processor       : 1
processor       : 2


Online the 4th CPU:

# echo 1 > /sys/devices/system/cpu/cpu3/online

The CPU is now online and in use. The mpstat utility can also be used to see per CPU utilization.

# cat /proc/cpuinfo | grep processor
processor       : 0
processor       : 1
processor       : 2
processor       : 3


2. Disks

Add a new disk to the system. First I need to rescan my host but I don't know which one. I can find out with:

# grep mpt /sys/class/scsi_host/host?/proc_name                               
/sys/class/scsi_host/host0/proc_name:mptspi  

# echo "- - -" > /sys/class/scsi_host/host0/scan

- - - will tell to rescan everything on that scsi host. I can now see the new disk attached (sdb)
OR:
 ls /sys/class/scsi_host/ | while read host ; do echo "- - -" > /sys/class/scsi_host/$host/scan ; done


# dmesg
[  652.561414] sd 0:0:1:0: [sdb] Cache data unavailable
[  652.561418] sd 0:0:1:0: [sdb] Assuming drive cache: write through
[  652.561422] sd 0:0:1:0: [sdb] Attached SCSI disk

Make a new file system and mount the device.

# mkfs.ext4 /dev/sdb
mke2fs 1.41.9 (22-Aug-2009)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

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

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

# mount /dev/sdb /mnt

Add the entry to fstab.

# echo "/dev/sdb   /mnt   ext4    defaults  0  0" >> /etc/fstab