无聊的我,给我的大菊花瘦肉机加了一块320G的新硬盘准备玩PT,由于需要重新分区和挂载,so才会有了这篇文章。
//blog.lsza.net/archives/364.html N270小主机运行Centos 6.5
首先需要将硬盘连接到瘦客户机(废话),然后开机启动查看blos信息是否有硬盘,如果没有检查硬盘线、电源线是否安装妥当,如有信息则可进行下一步。
[[email protected] ~]# fdisk -l //查看当前磁盘信息,就会发现最下面显示新加入的硬盘不是有效分区,如下:
Disk /dev/sda: 15.4 GB, 15434883072 bytes
255 heads, 63 sectors/track, 1876 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: 0x3899193a
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 157 1048576 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 157 1877 13817856 83 Linux
Disk /dev/sdb: 320.1 GB, 320072933376 bytes //新硬盘320GB
255 heads, 63 sectors/track, 38913 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: 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. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
//这一步可以不做,就是可以通过输入 h 查看帮助信息
Command (m for help): h
h: unknown command
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 //输入 n,新建分区
Command action
e extended //新建逻辑分区
p primary partition (1-4) //新建主分区
p //输入 p,建立主分区
Partition number (1-4): 1 //一共可以分4个主分区,输入 1,建立第一个主分区
First cylinder (1-38913, default 1): //选择该分区的起始磁盘数,如无特殊需求强烈建议选择默认,也就是默认用1 来分区(直接按回车)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-38913, default 38913):
//定义该分区的大小,如果按默认(直接回车),就是使用全部可用存储空间;如果要分成一个 1G 的空间,输入 +1024m 即可
Using default value 38913
Command (m for help): w //写入分区信息,其实就是保存分区信息
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]# fdisk -l //查看刚刚分成的分区,内容如下,注意最后一行的信息:
Disk /dev/sda: 15.4 GB, 15434883072 bytes
255 heads, 63 sectors/track, 1876 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: 0x3899193a
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 157 1048576 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 157 1877 13817856 83 Linux
Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 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: 0x0b8e75a7
Device Boot Start End Blocks Id System
/dev/sdb1 1 38913 312568641 83 Linux
//划线部分,就是分区,格式化时要写正确
[[email protected] ~]# mkfs -t ext3 /dev/sdb1 //对分区使用 ext3 格式化,如果建立了多个分区,显示 /dev/sdb2、/dev/sdb3 等,以此类推,重复输入这条命令,就可以进行其它分区的格式化操作了。
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19537920 inodes, 78142160 blocks
3907108 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
2385 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, 7962624, 11239424, 20480000, 23887872, 71663616
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]# fdisk -l //再次查看硬盘信息
Disk /dev/sda: 15.4 GB, 15434883072 bytes
255 heads, 63 sectors/track, 1876 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: 0x3899193a
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 157 1048576 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 157 1877 13817856 83 Linux
Disk /dev/sdb: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 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: 0x0b8e75a7
Device Boot Start End Blocks Id System
/dev/sdb1 1 38913 312568641 83 Linux
[[email protected] ~]# mkdir /data //新建挂载目录
[[email protected] ~]# mount /dev/sdb1 /data //挂载这块新硬盘
[[email protected] ~]# df -hl //查看分区大小是否和我们预定的一样
Filesystem(文件系统) Size(容量) Used(已用) Avail(可用) Use%(已用%) Mounted on(挂载点)
/dev/sda3 13G 8.6G 3.8G 70% /
tmpfs 498M 0 498M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sdb1 294G 191M 279G 1% /data //最后这一行是新硬盘的相关信息
[[email protected] ~]# vi /etc/fstab //编辑 /etc/fstab 文件,设置系统启动后自动挂载硬盘,最后一行为添加的相关内容
#
# /etc/fstab
# Created by anaconda on Sat Sep 3 20:23:37 2016
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=e54870b6-5fbc-40e2-8f72-d35e7ed218fc / ext4 defaults 1 1
UUID=d9bd5749-7b49-44cf-9e03-8988566e57bb /boot ext4 defaults 1 2
UUID=a97dfc22-c51c-4fa8-8460-6db380358e58 swap swap defaults 0 0
/dev/sdb1 /data ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[[email protected] ~]# df -h //再次查看硬盘信息,最后一行为新添加的硬盘信息
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 13G 8.6G 3.8G 70% /
tmpfs 498M 0 498M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sdb1 294G 191M 279G 1% /data
[[email protected] ~]# reboot //重新启动系统
[[email protected] ~]# df -h //查看硬盘信息;同时,检查我们添加硬盘、挂载硬盘、系统启动后自动挂载硬盘这一系列的操作是否正确,如果出现了最后一行,则我们的操作就是正确的
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 13G 8.6G 3.8G 70% /
tmpfs 498M 0 498M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sdb1 294G 191M 279G 1% /data