将XenServer系统盘上的未分配空间利用起来

时间:2021-07-09 04:05:09

  刚申请的用于XenServer虚拟化测试服务器已于昨天到手,基本存储配置为:

  • 1 × 三星960 EVO 250G M.2 NVMe PCI-E固态硬盘,计划安装XenServer系统
  • 6 × 西部数据 SATA 3.0 6Gb/s 2T机械硬盘,计划组装RAID

  XenServer安装完成后,发现操作系统的用量很少,50G都不到,那么还有近200G的空间是可以使用的。关键这是一块M.2 PCI-E的固态硬盘啊,并非普通的固态硬盘,读写速度是常规SSD的10倍。

# fdisk -l /dev/nvme0n1
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase.
Use at your own discretion.

Disk /dev/nvme0n1: 250.1 GB, 250059350016 bytes, 488397168 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 label type: gpt

# Start End Size Type Name
1 46139392 83888127 18G Microsoft basic
2 8390656 46139391 18G Microsoft basic
3 83888128 84936703 512M BIOS boot parti
5 2048 8390655 4G Microsoft basic
6 84936704 87033855 1G Linux swap

  京东上关于“三星960 EVO 250G”固态硬盘的参数说明:

  将XenServer系统盘上的未分配空间利用起来

  反正是台虚拟化测试机器,硬盘又有那么高的读写速度,这部分闲置的空间可不能浪费啊,要好好利用,最简单的就是做文件共享。

  还有一点,通过fdisk -l命令查看到的M2 SSD硬盘的分区格式是GPT,并非传统的MBR分区模式。在Linux下,fdisk工具不支持GPT,得使用另一个GUN发布的强大分区工具parted。

# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted

  选择要操作的M2 SSD硬盘:

(parted) select /dev/nvme0n1                                             
Using /dev/nvme0n1

  查看磁盘的分区表信息及未分配磁盘空间,可以看到,该SSD磁盘还有205G的空间未分配,这也正是我想要利用的一部分空间。

(parted) print free
Model: Unknown (unknown)
Disk /dev/nvme0n1: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: pmbr_boot

Number Start End Size File system Name Flags
17.4kB 1049kB 1031kB Free Space
5 1049kB 4296MB 4295MB ext3
2 4296MB 23.6GB 19.3GB
1 23.6GB 43.0GB 19.3GB ext3
3 43.0GB 43.5GB 537MB bios_grub, legacy_boot
6 43.5GB 44.6GB 1074MB linux-swap(v1)
44.6GB 250GB 205GB Free Space

  创建一个文件系统为ext3格式的主分区,并把剩余空闲空间全部分给该分区。注意结尾处是“-1s”,表示要划分空间的结尾是磁盘的最后一个扇区。过程中parted工具会自动调整扇区分配信息,输入“Yes”表示同意,如果输入的是“No”,则会忽略创建分区。若是要创建指定空间的新分区,例如要创建100GB的分区,则命令为:mkpart primary ext3 44.6GB 144.6GB

(parted) mkpart primary ext3 44.6GB -1s
Warning: You requested a partition from 44.6GB to 250GB (sectors 87109375..488397167).
The closest location we can manage is 44.6GB to 250GB (sectors 87033856..488397134).
Is this still acceptable to you?
Yes/No? Yes

(parted) print free
Model: Unknown (unknown)
Disk /dev/nvme0n1: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: pmbr_boot

Number Start End Size File system Name Flags
17.4kB 1049kB 1031kB Free Space
5 1049kB 4296MB 4295MB ext3
2 4296MB 23.6GB 19.3GB
1 23.6GB 43.0GB 19.3GB ext3
3 43.0GB 43.5GB 537MB bios_grub, legacy_boot
6 43.5GB 44.6GB 1074MB linux-swap(v1)
4 44.6GB 250GB 205GB ext3 primary

  新分区创建完后,就可以退出parted分区操作了,然后再对新分区进行格式化:

(parted) quit                                                             
Information: You may need to update /etc/fstab.

  新分区格式化。这里要注意分区的编号,其组成格式为:磁盘路径+小写字母p+要格式化的GPT分区编号。

# mkfs.ext3 /dev/nvme0n1p4
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
12550144 inodes, 50170409 blocks
2508520 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1532 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

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

  查看分区情况:

# fdisk -l /dev/nvme0n1
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase.
Use at your own discretion.

Disk /dev/nvme0n1: 250.1 GB, 250059350016 bytes, 488397168 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 label type: gpt

# Start End Size Type Name
1 46139392 83888127 18G Microsoft basic
2 8390656 46139391 18G Microsoft basic
3 83888128 84936703 512M BIOS boot parti
4 87033856 488397134 191.4G Microsoft basic primary
5 2048 8390655 4G Microsoft basic
6 84936704 87033855 1G Linux swap

  最后就是挂载分区了:

# mkdir -p /nfs0252
# mount -t ext3 /dev/nvme0n1p4 /nfs0252
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 320M 0 320M 0% /dev
tmpfs 330M 72K 330M 1% /dev/shm
tmpfs 330M 924K 329M 1% /run
tmpfs 330M 0 330M 0% /sys/fs/cgroup
/dev/nvme0n1p1 18G 1.7G 16G 10% /
xenstore 330M 0 330M 0% /var/lib/xenstored
/dev/loop0 55M 55M 0 100% /var/xen/xc-install
/dev/nvme0n1p5 3.9G 13M 3.7G 1% /var/log
tmpfs 66M 0 66M 0% /run/user/0
/dev/nvme0n1p4 189G 60M 179G 1% /nfs0252

  设置开机自动挂载:

# vi /etc/fstab,新增挂载配置:
/dev/nvme0n1p4 /nfs0252 ext3 defaults 0 0