Linux

將新分區添加到 Centos 硬碟

  • July 4, 2013

我的硬碟目前有(我相信)2個分區;啟動(sda1)和其他一切(sda2?)。一些硬碟驅動器也被用作交換記憶體,但我真的不明白這會如何影響事情。伺服器是物理的,我有一個 LiveCD。

如何向硬碟驅動器添加新分區(1 MB,ext3),並使 sda2 更小以容納新分區?

對於 lvm、/dev/mapper 以及 dm-0 和 dm-1 如何應用的任何其他評論將不勝感激,但不是必需的。

謝謝

[root@desktop ~]# mount
/dev/mapper/vg_desktop-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 

[root@desktop ~]# fdisk -l /dev/sda

Disk /dev/sda: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00056f9a

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64      182402  1464625152   8e  Linux LVM

[root@desktop ~]# lvdisplay
 --- Logical volume ---
 LV Path                /dev/vg_desktop/lv_root
 LV Name                lv_root
 VG Name                vg_desktop
 LV UUID                DhBjdq-0UJR-dJjx-bgH6-adGJ-TL43-8DrZR7
 LV Write Access        read/write
 LV Creation host, time desktop.xxx.com, 2013-07-01 04:10:19 -0700
 LV Status              available
 # open                 1
 LV Size                1.36 TiB
 Current LE             356082
 Segments               1
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     1024
 Block device           253:0

 --- Logical volume ---
 LV Path                /dev/vg_desktop/lv_swap
 LV Name                lv_swap
 VG Name                vg_desktop
 LV UUID                mNpyae-UtdA-MzJR-bbEc-D9OA-VPn8-ECMpbq
 LV Write Access        read/write
 LV Creation host, time desktop.xxx.com, 2013-07-01 04:13:25 -0700
 LV Status              available
 # open                 1
 LV Size                5.83 GiB
 Current LE             1492
 Segments               1
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     1024
 Block device           253:1

[root@desktop mapper]# ls -l /dev/mapper
total 0
crw-rw----. 1 root root 10, 58 Jul  4 00:37 control
lrwxrwxrwx. 1 root root      7 Jul  4 00:37 vg_desktop-lv_root -> ../dm-0
lrwxrwxrwx. 1 root root      7 Jul  4 00:37 vg_desktop-lv_swap -> ../dm-1
[root@desktop mapper]#

您需要縮小現有組,lvreduce以便為新卷騰出空間。然後,您可以使用:

lvcreate -L 3G -n <lvname> vg_desktop其中 3G 是您想要的音量大小。然後:

mkfs -t ext3 /dev/vg_desktop/<lvname>格式化它。最後,用mount -t ext3 /dev/vg_desktop/<lvname> /mnt/somedir.

引用自:https://serverfault.com/questions/520869