How to partition a disk, set its file system type & mount it

  1. 缘起同事在调整VolGroup-lv_root与VolGroup-lv_home分区大小之时,系统还未执行完直接重启了,导致报错如下
    How to partition a disk, set its file system type & mount it
  1. parted -l查看后发现,/dev/mapper/VolGroup-lv_home的Partition Table类型为msdos,需修改为loop
    How to partition a disk, set its file system type & mount it
  1. 解决方法
1) To know all the disks attached to VPS/Server type

 # parted --list

 It will show you all the disk along with the unpartitioned disk. Let, we attached a new disk "/dev/xvdb" to server. It will show "unrecognised disk label" message on "parted --list".

 ----
 root@server [~] parted /dev/xvdb
 GNU Parted 1.8.1
 Using /dev/xvdb
 Welcome to GNU Parted! Type 'help' to view a list of commands.
 (parted) print free
 Error: Unable to open /dev/xvdb - unrecognised disk label.
 ----

 2) Execute the following command to edit disk "/dev/xvdb":

 # parted /dev/xvdb

 3) Type "mklabel msdos"

 It creates a new disk label of type "msdos". The new disk label will have no partitions. This command won't technically destroy your data, but it will make it will make it basically unusable.

 ----
 (parted) mklabel msdos
 ----

 4) Type "print free" to know the partition details.

 ----
 (parted) print free

 Model: Xen Virtual Block Device (xvd)
 Disk /dev/xvdb: 53.7GB
 Sector size (logical/physical): 512B/512B
 Partition Table: msdos

 Number Start End Size Type File system Flags
 0.00kB 53.7GB 53.7GB Free Space

 (parted)
 ----

 5) Type "mkpart primary 0.00kB 53.7GB" (let the total size is 53.7GB)

 ----
 (parted) mkpart primary 0.00kB 53.7GB
 ----

 6) Again type "print free" to know the partition details.

 ----
 (parted) print free

 Model: Xen Virtual Block Device (xvd)
 Disk /dev/xvdb: 53.7GB
 Sector size (logical/physical): 512B/512B
 Partition Table: msdos

 Number Start End Size Type File system Flags
 1 0.51kB 53.7GB 53.7GB primary

 (parted)
 ----

 7) type "quit" to exit the parted utility.

 ----
 (parted) quit
 Information: Don't forget to update /etc/fstab, if necessary.

 root@server [~]#
 ----

 8) Execute the following command:

 # parted --list

 This time it will show the new disk too. Now we have to set the file system type on the disk and mount it.

 ==========
 root@server [~]# parted --list
 Error: Unable to open /dev/md0 - unrecognised disk label.


 Model: Unknown (unknown)
 Disk /dev/sda2: 1074MB
 Sector size (logical/physical): 512B/512B
 Partition Table: loop

 Number Start End Size File system Flags
 1 0.00kB 1074MB 1074MB linux-sw ap


 Model: Unknown (unknown)
 Disk /dev/sda1: 73.4GB
 Sector size (logical/physical): 512B/512B
 Partition Table: loop

 Number Start End Size File system Flags
 1 0.00kB 73.4GB 73.4GB ext3


 Model: Unknown (unknown)
 Disk /dev/xvdb: 53.6GB
 Sector size (logical/physical): 512B/512B
 Partition Table: msdos

 Number Start End Size File system Flags
 1 0.00kB 53.6GB 53.6GB ext3
 ==========

 8) Since the partition is not formated so we cannot mount it without formatting. To format the new disk use "mkfs.ext3 /dev/xvdb1". It may take some time to process.

 ====================
 root@server [~]# mkfs.ext4 /dev/xvdb
 mke2fs 1.39 (29-May-2006)
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 6553600 inodes, 13107199 blocks
 655359 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem b locks=4294967296
 400 block groups
 32768 blocks per group, 32768 fragments per group
 16384 inodes per group
 Superblock backups stored on blocks:
 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
 4096000, 7962624, 11239424

 Writing inode tables: done
 Creating journal (32768 blocks): done
 Writing superblocks and filesystem accounting information:
 done

 This filesystem will be automatically checked every 38 mounts or
 180 days, whichever comes first. Use tune2fs -c or -i to override.
 ====================

 9) Take a backup of file "/etc/fstab" and then open it using "vi" editor and mount it

 ------
 root@server [~]# cp -pv /etc/fstab /etc/fstab2
 `/etc/fstab' -> `/etc/fstab2'
 ------

 We will add the following line in "/etc/fstab". Here we are mounting the partition at "/backup" directory.

------
 /dev/xvdb1   /backup   ext4   defaults   0   0
------

 10) Use the following command to mount it.

 ------
 root@server [~]# mount /backup
 ------

Thank you.

原文连接
How to partition a disk, set its file system type & mount it

上一篇:greenplum中的Instrumentation统计数据


下一篇:CPU使用率终于正常了——记一次订餐系统事故处理