本博客包含以下内容:
(1)硬盘分区。
(2)查看分区列表。
(3)分区格式化。
(4)查看分区的UUID。
(5)挂载分区。
(6)查看挂载的分区。
正文如下:
1. 硬盘分区
使用fdisk工具完成硬盘分区工作。
sudo fdisk /dev/sdb
n:创建新分区。可以选择创建主分区或者扩展分区。如果选择创建扩展分区,创建之后还可以在此扩展分区上创建一个逻辑分区。
sudo 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 0x753c5a76.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1):
Using default value 1
First sector (2048-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Using default value 83886079
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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
Disk identifier: 0x753c5a76
Device Boot Start End Blocks Id System
/dev/sdb1 2048 83886079 41942016 5 Extended
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): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-83886079, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-83886079, default 83886079): 20G
Value out of range.
Last sector, +sectors or +size{K,M,G} (4096-83886079, default 83886079): +20G
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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
Disk identifier: 0x753c5a76
Device Boot Start End Blocks Id System
/dev/sdb1 2048 83886079 41942016 5 Extended
/dev/sdb5 4096 41947135 20971520 83 Linux
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (41949184-83886079, default 41949184):
Using default value 41949184
Last sector, +sectors or +size{K,M,G} (41949184-83886079, default 83886079):
Using default value 83886079
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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
Disk identifier: 0x753c5a76
Device Boot Start End Blocks Id System
/dev/sdb1 2048 83886079 41942016 5 Extended
/dev/sdb5 4096 41947135 20971520 83 Linux
/dev/sdb6 41949184 83886079 20968448 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2. 查看分区列表
[d@192.168.197.102:~]$sudo fdisk -lu
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 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
Disk identifier: 0x0008050b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 33554431 16776192 83 Linux
/dev/sda2 33556478 41940991 4192257 5 Extended
/dev/sda5 33556480 41940991 4192256 82 Linux swap / Solaris
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
171 heads, 5 sectors/track, 98112 cylinders, total 83886080 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
Disk identifier: 0x753c5a76
Device Boot Start End Blocks Id System
/dev/sdb1 2048 83886079 41942016 5 Extended
/dev/sdb5 4096 41947135 20971520 83 Linux
/dev/sdb6 41949184 83886079 20968448 83 Linux
3. 分区格式化
使用mkfs.ext4工具可以将一个分区格式化为EXT4分区。
[d@192.168.197.102:~]$sudo mkfs.ext4 /dev/sdb5
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
4. 查看分区的UUID
[d@192.168.197.102:~]$sudo ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Sep 4 14:48 359c7630-8dc3-4e96-bdac-982909970ad2 -> ../../sda1
lrwxrwxrwx 1 root root 10 Sep 4 15:06 7cb4024c-1fd0-4ae9-b28b-fb0a00bb4076 -> ../../sdb5
lrwxrwxrwx 1 root root 10 Sep 4 14:48 cc0e4a8d-1d3e-4c52-8e9c-d4e531267f3c -> ../../sda5
lrwxrwxrwx 1 root root 10 Sep 4 15:06 f6bdd2d0-8b3a-4681-af4a-070c177e2da1 -> ../../sdb6
5. 挂载分区
(1)人工挂载分区
sudo mount -t ext4 /dev/sdb5 /u01
(2)系统启动时自动挂载分区。
编辑/etc/fstab文件,每个需要挂载的分区添加一行内容:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=359c7630-8dc3-4e96-bdac-982909970ad2 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=cc0e4a8d-1d3e-4c52-8e9c-d4e531267f3c none swap sw 0 0
#/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
UUID=7cb4024c-1fd0-4ae9-b28b-fb0a00bb4076 /oracle ext4 defaults 0 1
UUID=f6bdd2d0-8b3a-4681-af4a-070c177e2da1 /partition2 ext4 defaults 0 1
执行sudo mount /oracle和sudo mount /partition2,可以人工挂载这两个新的分区。
重新启动系统,可以看到/dev/sdb5和/dev/sdb6两个分区已经自动挂载成功了。
6. 查看挂载的分区
sudo mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
/dev/sdb6 on /partition2 type ext4 (rw)
/dev/sdb5 on /oracle type ext4 (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)