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

简介:
  1. 缘起同事在调整VolGroup-lv_root与VolGroup-lv_home分区大小之时,系统还未执行完直接重启了,导致报错如下
    Screenshot_from_2018_07_13_17_16_35
  1. parted -l查看后发现,/dev/mapper/VolGroup-lv_home的Partition Table类型为msdos,需修改为loop
    Screenshot_from_2018_07_13_17_18_09
  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

目录
相关文章
|
6天前
|
Dart
Dart之集合详解(List、Set、Map)
Dart之集合详解(List、Set、Map)
10 1
|
11天前
|
存储 JavaScript 前端开发
JavaScript进阶-Map与Set集合
【6月更文挑战第20天】JavaScript的ES6引入了`Map`和`Set`,它们是高效处理集合数据的工具。`Map`允许任何类型的键,提供唯一键值对;`Set`存储唯一值。使用`Map`时,注意键可以非字符串,用`has`检查键存在。`Set`常用于数组去重,如`[...new Set(array)]`。了解它们的高级应用,如结构转换和高效查询,能提升代码质量。别忘了`WeakMap`用于弱引用键,防止内存泄漏。实践使用以加深理解。
|
6天前
|
Go
go语言map、实现set
go语言map、实现set
13 0
|
6天前
|
存储 消息中间件 算法
Java中的集合框架详解:List、Set、Map的使用场景
Java中的集合框架详解:List、Set、Map的使用场景
|
6天前
|
存储 自然语言处理 C++
【C++航海王:追寻罗杰的编程之路】set|map|multiset|multimap简单介绍
【C++航海王:追寻罗杰的编程之路】set|map|multiset|multimap简单介绍
13 0
【C++航海王:追寻罗杰的编程之路】set|map|multiset|multimap简单介绍
|
10天前
|
存储 算法 NoSQL
C++一分钟之-map与set容器详解
【6月更文挑战第21天】C++ STL的`map`和`set`是基于红黑树的关联容器,提供有序存储和高效查找。`map`存储键值对,键唯一,值可重复;`set`仅存储唯一键。两者操作时间复杂度为O(log n)。常见问题包括键的唯一性和迭代器稳定性。自定义比较函数可用于定制排序规则,内存管理需注意适时释放。理解和善用这些工具能提升代码效率。
13 3
|
12天前
|
存储 编译器 C++
|
20天前
|
存储 安全 Java
Java集合详解:Set, Map, Vector, List的对比与联系
Java集合框架核心包括List、Set、Map和Vector。List允许重复元素,如ArrayList(适合读取)和LinkedList(适合插入删除)。Set不允许重复,有HashSet(无序)和TreeSet(排序)。Map存储键值对,HashMap(无序)和TreeMap(排序)。Vector是线程安全的ArrayList替代品,但在多线程环境下使用。选择集合类型应根据应用场景,如有序、无序、键值对需求及线程安全考虑。