为vmware创建的ubuntu虚机增加硬盘
1.关闭虚机,按照vmware的界面向导增加一块硬盘:
2.启动虚机,后fdisk -l可以看到/dev/sdb:
root@odl_ubuntu:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5bfb031a
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5bfb031a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 39942143 39940096 19G 83 Linux
/dev/sda2 39944190 41940991 1996802 975M 5 Extended
/dev/sda5 39944192 41940991 1996800 975M 82 Linux swap / Solaris
/dev/sda1 * 2048 39942143 39940096 19G 83 Linux
/dev/sda2 39944190 41940991 1996802 975M 5 Extended
/dev/sda5 39944192 41940991 1996800 975M 82 Linux swap / Solaris
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
3.用fdisk格式化并挂载sdb:
依次输入fdisk /dev/sdb------n------p------回车------回车------回车------w,完成新增磁盘的创建:
root@odl_ubuntu:~# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x3f116e45.
Created a new DOS disklabel with disk identifier 0x3f116e45.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):
Created a new partition 1 of type 'Linux' and of size 20 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
4.格式化这个新分区:
fdisk -l看到/dev/sdb1:
root@odl_ubuntu:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5bfb031a
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5bfb031a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 39942143 39940096 19G 83 Linux
/dev/sda2 39944190 41940991 1996802 975M 5 Extended
/dev/sda5 39944192 41940991 1996800 975M 82 Linux swap / Solaris
/dev/sda1 * 2048 39942143 39940096 19G 83 Linux
/dev/sda2 39944190 41940991 1996802 975M 5 Extended
/dev/sda5 39944192 41940991 1996800 975M 82 Linux swap / Solaris
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3f116e45
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 41943039 41940992 20G 83 Linux
/dev/sdb1 2048 41943039 41940992 20G 83 Linux
用mkfs进行格式化:
root@odl_ubuntu:~# mkfs -t ext4 -c /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 93ec8613-a5a5-4743-b304-5f1598492c3f
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 93ec8613-a5a5-4743-b304-5f1598492c3f
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Checking for bad blocks (read-only test): done
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
5.挂载:
root@odl_ubuntu:~# mount /dev/sdb1 /mnt
然后用df -TH查看:
root@odl_ubuntu:~# df -TH
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.1G 0 1.1G 0% /dev
tmpfs tmpfs 208M 6.5M 202M 4% /run
/dev/sda1 ext4 20G 19G 618M 97% /
tmpfs tmpfs 1.1G 193k 1.1G 1% /dev/shm
tmpfs tmpfs 5.3M 4.1k 5.3M 1% /run/lock
tmpfs tmpfs 1.1G 0 1.1G 0% /sys/fs/cgroup
tmpfs tmpfs 208M 25k 208M 1% /run/user/109
tmpfs tmpfs 208M 0 208M 0% /run/user/0
/dev/sdb1 ext4 22G 47M 20G 1% /mnt
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.1G 0 1.1G 0% /dev
tmpfs tmpfs 208M 6.5M 202M 4% /run
/dev/sda1 ext4 20G 19G 618M 97% /
tmpfs tmpfs 1.1G 193k 1.1G 1% /dev/shm
tmpfs tmpfs 5.3M 4.1k 5.3M 1% /run/lock
tmpfs tmpfs 1.1G 0 1.1G 0% /sys/fs/cgroup
tmpfs tmpfs 208M 25k 208M 1% /run/user/109
tmpfs tmpfs 208M 0 208M 0% /run/user/0
/dev/sdb1 ext4 22G 47M 20G 1% /mnt
6.自动挂载:
如果想系统启动时自动挂载,请修改/etc/fstab,在最后增加:
/dev/sdb1 /mnt ext4 defaults 1 2