Thursday, October 29, 2015

Setting up multiple hard drives at once on Ubuntu

Sometimes you need to set up multiple hard drives sequentially, say for example for a Hadoop data node.
Here's how you do it quick and easy:
# for hdd in /dev/sd{c..h};do echo -e "n\n\n\n\n\nw\n\n"|fdisk $hdd;mkfs.ext4 ${hdd}1;done

In order to automount, use:
# blkid

Add/replace the UUID of the new HDD in /etc/fstab like the following examples:
UUID=b8923549-5794-4cad-89b3-0813fafb9566 /            ext4    errors=remount-ro 0       1
UUID=f0fc9526-0579-4116-994b-c79878f7f393 /hdfs/10    ext4    noatime 0    1

Changing UUID of an existing partition:
# tune2fs /dev/sdl1  -U d81ce3c1-27fa-4a37-8d61-3bebc7ac4e92

Extra options:
  • Enable writeback mode. This mode will typically provide the best ext4 performance.
# tune2fs -o journal_data_writeback /dev/sda10
  • Delete has_journal option
# tune2fs -O ^has_journal /dev/sda10