Use the Fdisk command and the Partprobe command under Linux to create a new partition and format it without rebooting the system

Source: Internet
Author: User

Due to the need for work, I have been learning Linux for some time recently. Learn a new knowledge, I like to find a book or a learning video system learning, so that the new knowledge of learning has a systematic and comprehensive understanding and understanding. So before the study, did not have a bird brother's private food as a reference book, began the system of learning Linux.

According to Brother Bird's suggestion, when the virtual machine is installed, an empty capacity is reserved to practice the partition usage. So when the Linux system partition is installed on the virtual machine, only a 4G capacity is mounted to the root directory "/", and only one 2G swap partition is divided. There is also a 14G capacity that is not assigned.

When learning Disk Management, use FDISK to continue partitioning the remaining capacity. It is found that the partition cannot be overloaded by Partprobe after the partition has been created.

The operation is as follows:

1. Use Fdisk to create a new partition

(。。。。 The partition operation record is not saved, and after executing W, the following information appears

disk/dev/sda:21.5 GB, 21474836480 bytes
255 heads, Sectors/track, 2610 cylinders
Units = cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/o size (minimum/optimal): Bytes/ Bytes
Disk identifier:0x000b604c Device Boot Start End Blocks Id System
/dev/sda1 * 1 523 4194304, Linux
P Artition 1 does not end on cylinder boundary.
/dev/sda2 523 784 2097152 for Linux Swap/solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 784 2610 14672345 5 Extended
/dev/sda5 784 1421 5121671 Linuxcommand (M for help): W
The partition tabl E has been altered! Calling IOCTL () to re-read partition table. Warning:re-reading the partition table failed with error 16: The device or resource is busy.
The kernel still uses the old table. The new table would be used in
the next reboot or after you run Partprobe (8) or KPARTX (8)
Syncing disks.

Save new partition, prompt "device or resource Busy", at that time on the/DEV/SDA hard disk operation, thought that the hint is normal phenomenon, so ignored, continue the next step.

2. Avoid restarting the system by partprobe the partition table

[Email protected]/]# Partprobe
Warning:WARNING:the kernel failed to re-read the partition table ON/DEV/SDA (device or resource busy). As a result, it may not be reflect all of the your changes until after reboot.
Warning: Cannot open/dev/sr0 (read-only file system) in read-write mode. /dev/sr0 has been opened as read-only.
Warning: Cannot open/dev/sr0 (read-only file system) in read-write mode. /dev/sr0 has been opened as read-only.
Error: Invalid partition table-/dev/sr0 a recursive partition appears.

Overloaded partitions appear in the above information, when the warning prompt "device or resource busy, need to restart the system for the changes to take effect" directly ignored, thought to be a normal phenomenon. However, for the error message "Error: Invalid partition table-/dev/sr0 a recursive partition appears. "It was a little dazed, but since I was prompted with" Invalid partition table ", I checked the partition information.

3. Use the Fdisk-l command to view the partition information

[Email protected]/]# fdisk-l
disk/dev/sda:21.5 GB, 21474836480 bytes
255 heads, Sectors/track, 2610 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x000b604c Device Boot Start End Blocks Id System
/DEV/SDA1 * 1 523 4194304 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 523 784 2097152, Linux Swap/solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 784 2610 14672345 5 Extended
/dev/sda5 784 1421 5121671-up Linux

View the partition information, normal, and the newly created extended partition/dev/sda3 and logical partition/DEV/SDA5 are all in. The newly created partition/DEV/SDA5 is then formatted directly.

4. Format the new logical partition/DEV/SDA5

[Email protected]/]# mkfs-t EXT3/DEV/SDA5
MKE2FS 1.41.12 (17-may-2010)
Unable to make stat call to/DEV/SDA5---not have that file or directory
The device apparently does not exist; Did you specify it correctly?

When formatting, you are prompted to "do not have that file or directory." This is strange, the operation is according to the reference books step by step, how can not do? So Baidu Linux under the new partition some information, hope can find similar errors, learn from the solution. There was a similar mistake in finding a lap, but no solution was given.

The process of re-parsing the new partition and overloading the partitioned table, for "device or resource busy" prompt, because it was on the/DEV/SDA this hard disk operation, the prompt "device or resource busy" should be normal, reboot should be OK. But after reboot, still can't find/dev/sda5, but fdisk-l view is there. Therefore, it is suspected that the partition table is overloaded with "Error: Invalid partition table-/dev/sr0 appears recursive partition." "error message caused?"

Check out sr0 under/dev

[Email protected] dev]# LS-LH | grep sr0
lrwxrwxrwx. 1 root root 3 August 5 00:12 CDROM-sr0
lrwxrwxrwx. 1 root root 3 August 5 00:12 CDRW-sr0
lrwxrwxrwx. 1 root root 3 August 5 00:12 DVD-Sr0
lrwxrwxrwx. 1 root root 3 August 5 00:12 DVDRW-sr0
lrwxrwxrwx. 1 root root 3 August 5 00:12 scd0-sr0
BRW-RW----. 1 root cdrom 11, 0 August 5 00:12 sr0

From the above results, SR0 is the optical drive device, Baidu/dev/sr0 This device, also is the optical drive. So tube it overloaded partition table failed due to "Error: Invalid partition table-/dev/sr0 appears recursive partition. "caused by the first to remove the optical drive to say, anyway, is on the virtual machine."

After removing the optical drive device on the virtual machine, reboot the system, re-create the partition, and re-execute the partprobe command overloaded partition table, error message "Error: Invalid partition table-/dev/sr0 a recursive partition appears. "No, just a warning prompt" device or resource busy "is still in. In this case, the new logical partition is directly formatted/DEV/SDA5 "There is no file or directory." So restart the system, and then format the/DEV/SDA5, this time success.

That is, the new partition format failed before, because the virtual machine's optical drive/DEV/SR0 device caused the partition table recursion. In addition, because it operates on the same hard disk, the system must be restarted for the newly created partition to be written to the partition table.

The bird's private dish, said to reserve a piece of capacity for the division exercise, how did bird brother success?

Then found some Linux disk Management related videos and materials, discovered that they use Fdisk new partition is used by the multi-disk implementation. And then go back to see the bird Brother's private food, found that the hard disk reserved by/DEV/HDC, then bird Brother's environment must also have/DEV/HDA and/dev/hdb, then the bird Brother Test is on the basis of how fast hard disk completed.

Then I will assign a hard disk to the virtual machine to try. The system is then shut down and a 5G of virtual disk space is allocated to the system on the virtual machine. Re-boot into the system to the new disk space to partition, format and so on.

Step or the same as above, partition, overloaded partition table, view partition, format, here no longer follow the steps, directly give the completed Operation record.

[Email protected] ~]# fdisk-l

disk/dev/sda:21.5 GB, 21474836480 bytes
255 heads, Sectors/track, 2610 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x000b604c

Device Boot Start End Blocks Id System
/DEV/SDA1 * 1 523 4194304 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 523 784 2097152, Linux Swap/solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 784 2610 14672345 5 Extended
/dev/sda5 784 2610 14672313+-up Linux

disk/dev/sdb:5368 MB, 5368709120 bytes
255 heads, Sectors/track, 652 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x00000000

[Email protected] ~]# Fdisk/dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF Disklabel
Building a new DOS disklabel with disk identifier 0x851e79cc.
Changes'll remain in memory only, until the decide to write them.
After that, of course, the previous content won ' t is recoverable.

Warning:invalid flag 0x0000 of partition Table 4 would be a 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): P

disk/dev/sdb:5368 MB, 5368709120 bytes
255 heads, Sectors/track, 652 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x851e79cc

Device Boot Start End Blocks Id System

Command (M for help): N
Command Action
E Extended
P primary partition (1-4)
P
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using Default value 1
Last cylinder, +cylinders or +size{k,m,g} (1-652, default 652):
Using Default value 652

Command (M for help): P

disk/dev/sdb:5368 MB, 5368709120 bytes
255 heads, Sectors/track, 652 cylinders
Units = Cylinders of 16065 * 8225280 bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x851e79cc

Device Boot Start End Blocks Id System
/DEV/SDB1 1 652 5237158+ Linux

Command (M for help): W
The partition table has been altered!

Calling IOCTL () to re-read partition table.
Syncing disks.
[Email protected] ~]# Partprobe/dev/sdb
[Email protected] ~]# mkfs-t EXT4/DEV/SDB1
MKE2FS 1.41.12 (17-may-2010)
File System label = Operating system: Linux block Size =4096 (log=2) chunked size =4096 (log=2) stride=0 blocks, Stripe width=0 blocks327680 inodes, 1309289 blocks65464 blocks (5.00%) reserved for the Super user
First Data Block =0maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes pe R groupsuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing Inode table: complete
Creating Journal (32768 blocks): complete
Writing Superblocks and FileSystem accounting information: Complete
This filesystem would be automatically checked every-mounts or180 days, whichever comes first.
Use Tune2fs-c or-i to override.

This time there is no warning or error message either for the new partition or for the overloaded partition table. Successful implementation without rebooting the system to add the hard disk and new hard disk to partition, format and so on.

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.