Scenario Description: My host is Windows 7, virtual machine is wmware, which is installed in the linux-ubuntu10.04 version.
The disk partition of the virtual machine is not enough and you want to resize it.
1) First, go to Linux in the VM and run sudo fdisk-L to list the disks.
Disk/Dev/SDA:10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track,1305Cylinders # It can be seen that the SDA hard disk has 10 GB and 1306 channels, and 1 ~ 653 and 654 ~ 1306 unused
# If you have multiple hard disks, SDB, SDC, etc.
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00087bbc
Device boot start end blocks ID system
/Dev/sda1*1 618 4959232 83 Linux
Partition 1 does not end on cylinder boundary.
/Dev/sda2 618653280577 5 extended
Partition 2 does not end on cylinder boundary.
/Dev/sda5 618 653 280576 82 Linux swap/Solaris
# We can see that
1) 1 ~ 653 channels, 1306-653 = 653 channels are not used, 5G has been partitioned, and 5G has not been partitioned.
In reality, my virtual machine file is 5 GB by default. I just resized the disk to 10 Gb, and 5 GB is still partitioned.
2) The existing 5G is divided into three zones, except one of which is an extended partition (which is used to mount other logical partitions ), there are also two partitions. One is a LINUX partition and the other is a Linux swap (SWAP partition)
2) view the disk usage and mounting status of the existing Partition
Root @ Ubuntu:/home/Nemo # DF-H
Filesystem size used avail use % mounted on
/Dev/sda1 4.7G 4.1g 410 m 91%/
None 119 M 248 K 119 M 1%/dev
None 123 m 164 K 123 m 1%/dev/SHM
None 123 m 296 K 123 m 1%/var/run
None 123 m 0 123 m 0%/var/lock
None 123 m 0 123 m 0%/lib/init/RW
We can see that the existing 5g partition has basically been used. The/dev/sda1 partition is mounted to the "/" root directory, with 9% of the remaining capacity left.
2) start to partition the remaining 5g disks and mount a directory for them.
Root @ Ubuntu:/home/Nemo # fdisk/dev/SDA
Warning: DOS-compatible mode is deprecated. It's stronugly recommended
Switch off the mode (command 'C') and change display units
Sectors (command 'U ').
Command (M for help): m
Command action
A toggle a bootable flag
B edit BSD disklabel
C toggle the DOS compatibility flag
D delete a partition
L List known partition types
M print this menu
N Add a new partition
O create a new empty DOS partition table
P print the Partition Table
Q quit without saving changes
S create a new empty sun disklabel
T change a partition's System ID
U change display/entry units
V verify the Partition Table
W write table to disk and exit
X extra functionality (experts only)
Command (M for help): p
Disk/dev/SDA: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00087bbc
Device boot start end blocks ID system
/Dev/sda1*1 618 4959232 83 Linux
Partition 1 does not end on cylinder boundary.
/Dev/sda2 618 653 280577 5 extended
Partition 2 does not end on cylinder boundary.
/Dev/sda5 618 653 280576 82 Linux swap/Solaris
Command (M for help): n
Command action
L logical (5 or over)
P primary partition (1-4)
L
No free sectors available # The above extended partitions have been used up.
Command (M for help): n
Command action
L logical (5 or over)
P primary partition (1-4)
Primary partition # enter the full name: Primary partition. directly input P to the print command.
Partition Number (1-4): 2
Partition 2 is already defined. Delete it before re-adding it.
Command (M for help): n
Command action
L logical (5 or over)
P primary partition (1-4)
Primary partition 3
Partition Number (1-4): 3
First cylinder (653-1305, default 653 ):
Using default value 653
Last cylinder, + cylinders or + size {K, M, g} (653-1305, default 1305 ):
Using default value 1305 # all unused partitions that are left by pressing the Enter key all the way.
Command (M for help): p
Disk/dev/SDA: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes
Sector size (logical/physical): 512 bytes/512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x00087bbc
Device boot start end blocks ID system
/Dev/sda1*1 618 4959232 83 Linux
Partition 1 does not end on cylinder boundary.
/Dev/sda2 618 653 280577 5 extended
Partition 2 does not end on cylinder boundary.
/Dev/sda3 653 1305 5240556 + 83 Linux
/Dev/sda5 618 653 280576 82 Linux swap/Solaris
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
The next reboot or after you run partprobe (8) or kpartx (8)
Syncing disks.
Root @ Ubuntu:/home/Nemo #
Note,
1) Although the new partition can be seen through fdisk-L, the partition table can only be written after the restart. For example, if you want to create a PV (physical volume), the system will prompt that the partition cannot be found:
After the system is restarted, the new partition can be used normally:
Root @ Ubuntu:/home/Nemo # reboot #
2) The new partition must be formatted before it can be mounted. Otherwise, the message "Mount: You must specify the filesystem type" is displayed.
Root @ Ubuntu: // # mkfs. ext4/dev/sda3# Note: The symbols between mkfs and ext4 are "." Instead of spaces.
3) you can mount a partition to an existing non-empty directory.However, after mounting, the contents in this directory will be unavailable. We want to mount it to/home, so back up/home first and then mount it,Copy it back after mounting.
CD/
MV/home/home2
Mkdir/home
Mount/dev/sda3/home
CP/home2/*/home/
OK ..
4) Check the result to view the Mount directory of each partition and the disk usage of the partition.
Root @ Ubuntu:/home # DF-th
Filesystem type size used avail use % mounted on
/Dev/sda1 ext4 4.7G 4.1g 410 m 91%/
None devtmpfs 119 M 252 K 119 M 1%/dev
None tmpfs 123 m 88 K 123 m 1%/dev/SHM
None tmpfs 123 m 296 K 123 m 1%/var/run
None tmpfs 123 m 0 123 m 0%/var/lock
None tmpfs 123 m 0 123 m 0%/lib/init/RW
/Dev/sda3 ext4 5.0g 138 m 4.6g 3%/home #==========> the remaining 4.6g, you can rest assured!
2. A partition is mounted to an existing Directory. The directory cannot be empty, but the contents in the directory are unavailable. This is also true for mounting file systems created by other operating systems.
Appendix:
1)
Refer to the following articles: partition tools in Linux
Http://bbs.bccn.net/thread-214078-1-1.html
2)
Root @ Ubuntu:/# Du -- Max-depth = 1-H
View disk usage of the current directory