阿里云ECS使用02:创建用户及磁盘挂载

1、创建用户

Linux中root账号作为管理员使用,在一般情况下需另建账号给个人日常使用。

[root@iZ23o5qv2ozZ ~]# useradd zhongning
[root@iZ23o5qv2ozZ ~]# passwd zhongning
Changing password for user zhongning.
New password: 
BAD PASSWORD: it is based on a dictionary word
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@iZ23o5qv2ozZ ~]# ls /home
zhongning
[root@iZ23o5qv2ozZ ~]#

编辑sudoer文件,以便可以使用sudo命令进行系统操作,减少root账号的使用。

[root@iZ23o5qv2ozZ ~]# vim /etc/sudoers

## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL
zhongning       ALL=(ALL)       ALL

2、挂载硬盘

通过挂载硬盘用于数据存储,方便日后数据备份、转存、恢复。数据盘要经过分区、格式化、挂载三个步骤后,才能正常使用。

2.1、磁盘分区

使用fdisk命令,查看分配的硬件编号:

[root@iZ23o5qv2ozZ ~]# fdisk -l

Disk /dev/xvda: 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: 0x00078f9c

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2611    20970496   83  Linux

Disk /dev/xvdb: 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: 0x00000000

[root@iZ23o5qv2ozZ ~]# 

上述信息显示,设备编号为/dev/xvdb的硬盘还没有使用,执行fdisk /dev/xvdb 进行分区

[root@iZ23o5qv2ozZ ~]# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x917e4ba3.
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): h
h: unknown command
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): 

而后依次输入,n:创建分区,p:创建主分区,1:主分区编号,2次回车使用所有的柱面确定分区使用所有的磁盘空间,w:写入分区表。

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): w
The partition table has been altered!

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

[root@iZ23o5qv2ozZ ~]# fdisk -l


Disk /dev/xvda: 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: 0x00078f9c


Device Boot Start End Blocks Id System
/dev/xvda1 * 1 2611 20970496 83 Linux


Disk /dev/xvdb: 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: 0x917e4ba3


Device Boot Start End Blocks Id System
/dev/xvdb1 1 2610 20964793+ 83 Linux
[root@iZ23o5qv2ozZ ~]#

2.2、格式化分区

将新创建的分区/dev/xvdb1进行格式化,格式化为ext3格式

[root@iZ23o5qv2ozZ ~]# mkfs.ext3 /dev/xvdb1
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, 5241198 blocks
262059 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 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@iZ23o5qv2ozZ ~]# 

2.3、挂载分区

在根目录下创建准备挂载的目录如/data,然后使用mount命令进行挂载,用df命令查看挂载是否成功。

[root@iZ23o5qv2ozZ /]# ls
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var
[root@iZ23o5qv2ozZ /]# ls
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var
[root@iZ23o5qv2ozZ /]# mkdir /data
[root@iZ23o5qv2ozZ /]# ls
bin  boot  data  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var
[root@iZ23o5qv2ozZ /]# mount /dev/xvdb1 /data
[root@iZ23o5qv2ozZ /]# df -m
Filesystem     1M-blocks  Used Available Use% Mounted on
/dev/xvda1         20158  1397     17737   8% /
tmpfs                498     0       498   0% /dev/shm
/dev/xvdb1         20153   173     18957   1% /data
[root@iZ23o5qv2ozZ /]#

下面设置开机自动挂载,修改/etc/fstab文件。

[root@iZ23o5qv2ozZ /]# vim /etc/fstab#
# /etc/fstab
# Created by anaconda on Thu Aug 14 21:16:42 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=94e4e384-0ace-437f-bc96-057dd64f42ee / ext4 defaults,barrier=0 1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
none                  /proc/xen               xenfs   defaults        0 0
/dev/xvdb1              /data                   ext3    defaults        0 0

大功告成,over。

posted @ 2014-11-17 22:04  头顶上的星空  阅读(1165)  评论(0编辑  收藏  举报