这里我介绍一下在云主机ubuntu系统中如何处理新加的硬盘的,具体来说分为以下6步:
1)找到新添加的硬盘设备,这个需要从系统的log里找。
-
stack@ubunt:~$ dmesg |grep vd
-
[ 0.949797] vda: vda1 vda2 < vda5 >
-
[ 0.959385] vdb: unknown partition table
-
[ 1.159555] systemd-udevd[119]: starting version 204
-
[ 1.442816] EXT4-fs (vda1): mounted filesystem with ordered data mode. Opts: (null)
-
[ 2.189858] Adding 1046524k swap on /dev/vda5. Priority:-1 extents:1 across:1046524k FS
-
[ 2.416559] EXT4-fs (vda1): re-mounted. Opts: errors=remount-ro
-
[ 4.663330] systemd-udevd[361]: starting version 204
因为我这里使用的时虚拟的硬盘所以设备名是以“vd”开头的,如果你添加的是IDE接口的硬盘你可以grep “hd",如果是SATA/SAS等scsi的硬盘,可以grep “sd"。
2)使用fdisk在硬盘上创建分区。
-
stack@ubunt:~$ fdisk /dev/vdb
-
fdisk: unable to open /dev/vdb: Permission denied
-
stack@ubunt:~$ sudo fdisk /dev/vdb
-
sudo: unable to resolve host ubunt
-
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
-
Building a new DOS disklabel with disk identifier 0x6e850859.
-
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)
-
-
Command (m for help): n
-
Partition type:
-
p primary (0 primary, 0 extended, 4 free)
-
e extended
-
Select (default p): p
-
Partition number (1-4, default 1): 1
-
First sector (2048-209715199, default 2048):
-
'Using default value 2048
-
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
-
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
-
Using default value 209715199
-
-
Command (m for help): w
-
The partition table has been altered!
-
-
Calling ioctl() to re-read partition table.
-
Syncing disks.
"n"表示新建一个分区,"p"表示创建一个主分区,“1”表示只创建一个分区,“w“表示保存分区信息。在输入分区个数之后,系统会让你配置分区的大小,直接回车选择默认的数字就行。
3)时新建的分区在系统中生效。
stack@ubunt:~$ partprobe
4)格式化新建的分区。
-
stack@ubunt:~$ sudo mkfs.ext4 /dev/vdb1
-
mke2fs 1.42.9 (4-Feb-2014)
-
Filesystem label=
-
OS type: Linux
-
Block size=4096 (log=2)
-
Fragment size=4096 (log=2)
-
Stride=0 blocks, Stripe width=0 blocks
-
6553600 inodes, 26214144 blocks
-
1310707 blocks (5.00%) reserved for the super user
-
First data block=0
-
Maximum filesystem blocks=4294967296
-
800 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, 7962624, 11239424, 20480000, 23887872
-
-
Allocating group tables: done
-
Writing inode tables: done
-
Creating journal (32768 blocks): done
-
Writing superblocks and filesystem accounting information: done
5)创建硬盘挂载点,修改/etc/fstab使得硬盘能够一直挂载在系统中。
在新版本的ubuntu系统中/etc/fstab推荐使用分区的uuid来定义分区的挂载点,所以需要首先得到磁盘的uuid,这可以通过blkid命令得到。
-
stack@ubunt:~$ sudo blkid -p /dev/vdb1
-
/dev/vdb1: UUID="7689119f-9ad7-4cf8-a7c5-0589147b3566" VERSION="1.0" TYPE="ext4" USAGE="filesystem" PART_ENTRY_SCHEME="dos" PART_ENTRY_TYPE="0x83" PART_ENTRY_NUMBER="1" PART_ENTRY_OFFSET="2048" PART_ENTRY_SIZE="209713152" PART_ENTRY_DISK="253:16"
然后在/etc/fstab中加入下面的配置后保存,退出。
-
UUID=7689119f-9ad7-4cf8-a7c5-0589147b3566 /usr/localext4 ext4 defaults 0 0
6)重启系统,然后通过df命令确认。
-
stack@ubunt:~$ df /dev/vdb1
-
Filesystem 1K-blocks Used Available Use% Mounted on
-
/dev/vdb1 103080224 61044 97759968 1% /usr/localext4
-
stack@ubunt:~$ cd /usr/localext4/
-
stack@ubunt:/usr/localext4$ ls
-
lost+found
-
stack@ubunt:/usr/localext4$ touch testfile
-
touch: cannot touch ‘testfile’: Permission denied
-
stack@ubunt:/usr/localext4$ sudo touch testfile
-
stack@ubunt:/usr/localext4$ ls -la
-
total 24
-
drwxr-xr-x 3 root root 4096 Apr 15 22:53 .
-
drwxr-xr-x 11 root root 4096 Apr 15 22:03 ..
-
drwx------ 2 root root 16384 Apr 15 21:56 lost+found
-
-rw-r--r-- 1 root root 0 Apr 15 22:53 testfile
Bingo!完成!