What should I do if I cannot create a file system or create a PV?

Source: Internet
Author: User

When formatting disk partitions, the report information is as follows:

“/dev/sdb3 is apparently in use by the system; will not make a filesystem here!”

It seems that the system is using this device and cannot create a file system. Use mount to view all mounted devices in the system, and do not:/dev/sdb3. however, when creating a file system. You cannot create a file system on this device.


Sometimes, when we create a new partition, we use [kpartx-AF dirve] or [partx-A dirve] to notify the kernel to re-identify all the partitions of the device. The newly created new area has been identified using CAT/proc/partitions, but an error is reported when PV is created:

“Can‘t open /dev/sdb2 exclusively.  Mounted filesystem?”

This device cannot be turned on and the file system has been installed?

In fact, these are caused by the existence of the ing information of the underlying device-mapper. Therefore, when formatting partitions and creating logical volumes, an error is reported. You can use the DMSetup interface to manage the ing of the kernel space.

DMSetup status: displays information about active logical devices on the system. DMSetup remove sdb1 remove logical devices. DMSetup remove_all reset all logical devices.

Device er is a ing framework from a logical device to a physical device provided in the Linux 2.6 kernel. Under this mechanism, you can easily develop storage resource management policies based on your needs, such as images and snapshots. popular Linux logical volume managers such as lvm2 (Linux Volume Manager 2 version), evms (enterprisevolume management system), and dmraid (device mapper raidtool) and so on. you can easily implement these features by developing a ing policy in the user space and writing a target driver plug-in to process specific IO requests as needed. device er mainly includes kernel space ing, device mapper library of user space, and DMSetup tool.

What should we do when we encounter an error when formatting partitions and creating PVS?

1. Process of error reporting when PV is created:

View the partition information of the device/dev/SDB, and prepare the partition for creating the PV:/dev/sdb2.

[[email protected] ~]# fdisk -l /dev/sdbDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x2c06c001   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1          34      273073+  83  Linux/dev/sdb2              35         296     2104515   8e  Linux LVM

The kernel must identify the newly created partition (only the kernel can directly access the hardware) to create a PV.

[[email protected] ~]# cat /proc/partitions | grep "sdb[1-9]?"major minor  #blocks  name   8       16   20971520 sdb   8       17     273073 sdb1   8       18    2104515 sdb2

The kernel has recognized and created PV.

[[email protected] ~]# pvcreate /dev/sdb2  Can‘t open /dev/sdb2 exclusively.  Mounted filesystem?

Note:

Failed to create PV.


So how can we solve the problem that the PV cannot be created on the device/dev/sdb2?


(1) first:Use DMSetup to view the information of logical devices on the system.

[[Email protected] ~] # DMSetup statussdb2: 0 4209030 linear ---------> sdb2 online sdb1: 0 546147 linear ---------> sdb1 online vg0-swap: 0 4194304 linearvg0-root: 0 41943040 linearvg0-usr: 0 20971520 linearvg0-var: 0 41943040 linear

(2 ),Remove all logical devices from disk/dev/SDB

Remove logical device: sdb2

[[email protected] ~]# dmsetup remove sdb2

Create PV again

[[email protected] ~]# pvcreate /dev/sdb2  Can‘t open /dev/sdb2 exclusively.  Mounted filesystem?

Note:

Creation failed.

Remove the logical device:/dev/sdb1 and create PV. Created successfully.


[[email protected] ~]# dmsetup remove sdb1


(3 ),After the removal is successful, you can create/dev/sdb2 as PV.

[[email protected] ~]# pvcreate /dev/sdb2  Physical volume "/dev/sdb2" successfully created

2. Process of formatting disk errors:

View the partition information of the device/dev/SDB

[[email protected] ~]# fdisk -l /dev/sdbDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x2c06c001   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1          34      273073+  83  Linux/dev/sdb2              35        1340    10490445   8e  Linux LVM

Delete/dev/sdb2 and recreate the partition/dev/sdb2.

[[email protected] ~]# fdisk  -l /dev/sdbDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x2c06c001   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1          34      273073+  83  Linux/dev/sdb2              35        1079     8393962+  83  Linux

Notify the kernel to identify the new device, that is, to re-read the Partition Table of the specified device.

[[email protected] ~]# kpartx -af /dev/sdbdevice-mapper: reload ioctl on sdb1 failed: Invalid argumentcreate/reload failed on sdb1

Check whether the kernel is identified. The partition/dev/sdb2 just created

[[email protected] ~]# cat /proc/partitions major minor  #blocks  name   8        0   83886080 sda   8        1     204800 sda1   8        2   62914560 sda2   8        3    2103516 sda3   8       16   20971520 sdb   8       17     273073 sdb1   8       18   10490445 sdb2

Note: You can see from the result. The kernel still does not recognize the newly created/dev/sdb2. Or the original LVM. PV/dev/sdb2


How can we solve this problem by notifying the kernel to re-read and failing to create a file system on a new logical device?

(1 ),View the status of a logical device

[[Email protected] ~] # DMSetup statusmyvg-root: 0 8388608 linear ----> the logical volume root under the volume group myvg is online. Vg0-swap: 0 4194304 linearvg0-root: 0 41943040 linearvg0-usr: 0 20971520 linearvg0-var: 0 41943040 linear

(2 ),Use DMSetup to remove the logical volume/dev/myvg/root

[[Email protected] ~] # DMSetup remove/dev/myvg/root check the status of the logical volume in the system. The myvg-root logical device is removed successfully.
[[email protected] ~]# dmsetup statusvg0-swap: 0 4194304 linearvg0-root: 0 41943040 linearvg0-usr: 0 20971520 linearvg0-var: 0 41943040 linear

(3 ),Notify the kernel again to identify the disk partition.

[[email protected] ~]# kpartx -af /dev/sdb[[email protected] ~]# $?0

Note:

The kernel has been recognized.

(4 ),Try to create a file system in the new partition/dev/sdb2

[[email protected] ~]# mke2fs -t ext4 /dev/sdb2mke2fs 1.41.12 (17-May-2010)/dev/sdb2 is apparently in use by the system; will not make a filesystem here!

Note:

/Dev/sdb2 device system in use, unable to Create File System

(5 ),View the status of all logical devices in the system

[[email protected] ~]# dmsetup statussdb2: 0 16787925 linearsdb1: 0 546147 linearvg0-swap: 0 4194304 linearvg0-root: 0 41943040 linearvg0-usr: 0 20971520 linearvg0-var: 0 41943040 linear

(6)Remove online logical devices: sdb1 and sdb2

[[email protected] ~]# dmsetup remove  sdb1[[email protected] ~]# dmsetup remove  sdb2

(7 ),Check the status of the logical device.

[[email protected] ~]# dmsetup statusvg0-swap: 0 4194304 linearvg0-root: 0 41943040 linearvg0-usr: 0 20971520 linearvg0-var: 0 41943040 linear

(8) reformat the disk/dev/sdb2

[[email protected] ~]# mke2fs -t ext4 /dev/sdb2mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks655776 inodes, 2622611 blocks131130 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=268854886481 block groups32768 blocks per group, 32768 fragments per group8096 inodes per groupSuperblock backups stored on blocks:        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Writing inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 32 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.

(9 ),The/dev/sdb2 device is successfully formatted.

[[email protected] ~]# echo $?0

Summary:

If the operation logic device, such as partitioning format disk and PV, fails. If the device is not mounted. Use DMSetup status to view the status of the logical device. If any operated logical device is online, use [DMSetup Remove device] to remove it. It is generally not a problem to operate the logical device again.


This article is from the "Linux" blog, please be sure to keep this source http://9528du.blog.51cto.com/8979089/1444987

What should I do if I cannot create a file system or create a PV?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.