挂载新磁盘

##由于程序需要读取信息,会出现PCI(sysfs)读取中
root@ubuntu:~# sudo lshw -C disk
  *-disk                 
       description: SCSI Disk
       physical id: 0.0.0
       bus info: scsi@0:0.0.0
       logical name: /dev/sda
       size: 279GiB (300GB)
       capabilities: partitioned partitioned:dos
       configuration: signature=000e042e
  *-disk
       description: ATA Disk
       product: INTEL SSDSC2CW06
       physical id: 0.0.0
       bus info: scsi@2:0.0.0
       logical name: /dev/sdb
       version: 400i
       serial: EKCV321500DF060AGN
       size: 55GiB (60GB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 signature=000d4dbd

root@ubuntu:~# fdisk -l

Disk /dev/sdb: 60.0 GB, 60022480896 bytes
255 heads, 63 sectors/track, 7297 cylinders, total 117231408 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d4dbd

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1        39106560   117229567    39061504   83  Linux
/dev/sdb2            2048    15624191     7811072   82  Linux swap / Solaris
/dev/sdb3   *    15624192    16015359      195584   83  Linux
/dev/sdb4        16015360    39106559    11545600   83  Linux

Partition table entries are not in disk order

Disk /dev/sda: 300.0 GB, 300000000000 bytes
255 heads, 63 sectors/track, 36472 cylinders, total 585937500 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e042e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   552439807   276218880   83  Linux
/dev/sda2       552441854   585936895    16747521    5  Extended
/dev/sda5       552441856   585936895    16747520   82  Linux swap / Solaris
fdisk: unable to read /dev/mapper/cryptswap1: Inappropriate ioctl for device


root@ubuntu:~# fdisk /dev/sda

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): p
Partition number (1-4, default 3): 3
First sector (552439808-585937499, default 552439808):
Using default value 552439808
Last sector, +sectors or +size{K,M,G} (552439808-552441853, default 552441853):
Using default value 552441853

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.


##*******************************************************************************##
##  error 16: Device or resource busy.
##  由于该磁盘已经分区,则再进行分区,则会提示以下错误.

##  root@ubuntu:~# fdisk -l
##
##  Disk /dev/sda: 300.0 GB, 300000000000 bytes
##  255 heads, 63 sectors/track, 36472 cylinders, total 585937500 sectors
##  Units = sectors of 1 * 512 = 512 bytes
##  Sector size (logical/physical): 512 bytes / 512 bytes
##  I/O size (minimum/optimal): 512 bytes / 512 bytes
##  Disk identifier: 0x000e042e

##     Device Boot      Start         End      Blocks   Id  System
##  /dev/sda1   *        2048   552439807   276218880   83  Linux
##  /dev/sda2       552441854   585936895    16747521    5  Extended
##  /dev/sda5       552441856   585936895    16747520   82  Linux swap / Solaris
##  fdisk: unable to read /dev/mapper/cryptswap1: Inappropriate ioctl for device
##********************************************************************************##


##直接mount
root@ubuntu:~# mount /dev/sda1 /data/

##验证一下是否挂载成功
root@ubuntu:~# df -TH
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sdb1      ext4       40G  1.1G   37G   3% /
udev           devtmpfs  8.4G  4.1k  8.4G   1% /dev
tmpfs          tmpfs     3.4G  283k  3.4G   1% /run
none           tmpfs     5.3M     0  5.3M   0% /run/lock
none           tmpfs     8.5G  4.1k  8.5G   1% /run/shm
/dev/sdb3      ext4      190M   33M  147M  19% /boot
/dev/sdb4      ext4       12G   30M   11G   1% /home
/dev/sda1      ext4      279G   62M  265G   1% /data

## ls /data 发现/data遗留了太多的之前系统的数据,所以需要进该分区进行格式化

##发现原来挂载的分区是不能被格式化的,所以需要先对其对卸载.
root@ubuntu:/data# mkfs -t ext4 /dev/sda1
mke2fs 1.42 (29-Nov-2011)
/dev/sda1 is mounted; will not make a filesystem here!

##卸载的时候发现,原来有人正在使用该分区,不能卸载。
root@ubuntu:/data# umount /data
umount: /data: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

##查看一下是谁使用了该分区。
root@ubuntu:/data# fuser -m -v /data/
                     USER        PID ACCESS COMMAND
/data:               root     kernel mount /data
                     root       8834 ..c.. bash
                     yuxin      9111 ..c.. bash
##Kill使用该分区的用户,把root也直接kill
root@ubuntu:/data# kill -9 9111
root@ubuntu:/data# kill -9 8834
##卸载成功
root@ubuntu:/data# umount /data
root@ubuntu:/data#
##格式化该分区,成功.
root@ubuntu:~# mkfs -t ext4 /dev/sda1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
17268736 inodes, 69054720 blocks
3452736 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2108 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

##将其设置为开机自动挂载
##在最后一行加上
###################################################
#
#   /dev/sda1  /data  ext4  defaults  0  0
#
###################################################

root@ubuntu:/data# more /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=1dfe21b6-f0ec-41dd-9022-4b89b9db4e99 /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda3 during installation
UUID=58b86c68-3d15-43d5-9c38-9be2624352db /boot           ext4    defaults        0       2
# /home was on /dev/sda4 during installation
UUID=4319d38f-dc57-4c4a-a9cb-7bdc678ba9d4 /home           ext4    defaults        0       2
# swap was on /dev/sda2 during installation
#UUID=0875c384-60c7-410f-b7d4-8a994494cc1e none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0
/dev/sda1                                 /data           ext4    defaults         0      0


辅助资料:
http://wiki.ubuntu.org.cn/%E5%AE%89%E8%A3%85%E6%96%B0%E7%A1%AC%E7%9B%98
http://blog.csdn.net/tianlesoftware/article/details/5642883

猜你喜欢

转载自qson.iteye.com/blog/1980147