Linux Bulk Mount HDD

Source: Internet
Author: User
Tags arithmetic

########### #parted工具分区 ###############

#!/bin/bash #shell脚本开头格式
Path=/bin:/sbin:/usr/bin:/usr/sbin #保证脚本中的命令能在此路径中搜索得到
Export PATH #设置以上环境变量 to make it effective
I=1
While [$i-lt] #判断变量i是否小于13, (the number of hard disks, except the system disk is 12 blocks), here 13 depends on how many hard drives to mount
Do
J= ' echo $i |awk ' {printf '%c ', 97+ $i} ' #%c stands for ASCII characters. Displays the first character of the corresponding parameter, 97 for A; The system disk is SDA, if it is the other need to modify the script
Parted/dev/sd$j <<format # << on behalf of input redirection (format as identifier, when you encounter format again this identifier represents the end); The content between format is entered as a command to PARTED/DEV/SD After $j
Mklabel GPT # Mklabel Create a new disk for GPT partition
Mkpart primary 0-1 #创建一个分区为主分区 and divides the entire disk into a single partition
Ignore
Quit
FORMAT
Mkfs.ext4-t largefile/dev/sd${j}1 #格式化磁盘
Mkdir/disk${i} #十以上用大括号包含, such as ${10}
Mount= "/dev/sd${j}1/disk${i} ext4 defaults 0 0"
rm-rf/disk${i}/*
echo $mount >>/etc/fstab #写入分区表
i=$ (($i + 1)) #在shell中, $ (()) for arithmetic operations
Done
echo "/n/n*****formating and mounting have finished****/n/n" #格式化和安装完成
Mount-a #挂载 (all file systems mounted in the/etc/fstab file)

########### #fdisk工具分区 ###############

#!/bin/bash #shell脚本开头格式
Path=/bin:/sbin:/usr/bin:/usr/sbin #保证脚本中的命令能在此路径中搜索得到
Export PATH #设置以上环境变量 to make it effective
I=1
While [$i-lt] #判断变量i是否小于13, (the number of hard disks, except the system disk is 12 blocks)
Do
J= ' echo $i |awk ' {printf '%c ', 97+ $i} ' #%c stands for ASCII characters. Displays the first character of the corresponding parameter, 97 for A; The system disk is SDA, if it is the other need to modify the script
Fdisk/dev/sd$j <<format # << on behalf of input redirection (format as identifier, when you encounter format again this identifier represents the end); The content between format is entered as a command to parted/dev/sd$ After J
N # Mklabel Create new disk for GPT partition
P #创建一个分区为主分区 and divides the entire disk into one partition
1
#按回车默认输入有效值
#按回车默认输入有效值
W
FORMAT
Mkfs.ext4/dev/sd${j}1 #格式化磁盘
Mkdir/disk${i}
Mount= "/dev/sd${j}1/disk${i} ext4 defaults 0 0"
rm-rf/disk${i}/*
echo $mount >>/etc/fstab #写入分区表
i=$ (($i + 1)) #在shell中, (()) for arithmetic operations
Done
echo "/n/n*****formating and mounting have finished****/n/n" #格式化和安装完成 (there is a space between the contents of the output, you need double quotes)
Mount-a #挂载 (all file systems mounted in the/etc/fstab file)

########### #手工2TB磁盘格式化 ###############
For large 2TB disks, the partitioning method is as follows:
# PARTED/DEV/SDB
GNU Parted 2.1
Using/dev/sdb
Welcome to GNU parted! Type ' help ' to view a list of commands.
(parted) Print
Model:ata Hitachi HUA72302 (SCSI)
disk/dev/sdb:2000gb
Sector size (logical/physical): 512b/512b
Partition Table:msdos

Number Start End Size Type File system Flags

(parted) mklable GPT
(parted) Mkpart primary 0 2000000
(parted) Printmodel:ata Hitachi HUA72302 (SCSI)

disk/dev/sdb:2000gb
Sector size (logical/physical): 512b/512b
Partition Table:msdos

Number Start End Size Type File system Flags
1 1049kB 2000GB 2000GB primary Ext4


(parted) quit
Quick way to format this partition:
#mkfs. Ext4-t LARGEFILE/DEV/SDB1
Note:

If you use MKFS.EXT4 to format the partition without parameters, the disk formatting is very slow, so you need to increase the-T largefile parameter.

Linux Bulk Mount HDD

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.