partitioning disk

yoni·2023년 4월 14일

Linux

목록 보기
9/16

fdisk & gdisk

scsi type의 1GB 디스크 2개 추가

SATA/SAS/SCSI - /dev/sd
IDE - /dev/hd

Virtual Disk - /dev/vd__

@@VM으로 실습
> scsi type의 1GB 디스크 2개 추가
[root@localhost etc]# lsblk
NAME        MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda           8:0    0   1G  0 disk 				-- this one!!
sdb           8:16   0   1G  0 disk 				-- this one!!
vda         252:0    0  20G  0 disk 
├─vda1      252:1    0   1G  0 part /boot
└─vda2      252:2    0  19G  0 part 
  ├─cl-root 253:0    0  17G  0 lvm  /
  └─cl-swap 253:1    0   2G  0 lvm  [SWAP]


fdisk

partition type

  • primary (0 primary, 0 extended, 4 free) partition
  • extended partition => logical partition 생성
[root@localhost etc]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0x280ab957.

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
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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): p

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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: dos
Disk identifier: 0x280ab957

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-2097151, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +300M
Partition 1 of type Linux and of size 300 MiB is set

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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: dos
Disk identifier: 0x280ab957

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      616447      307200   83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (616448-2097151, default 616448): 
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): +400M
Partition 2 of type Linux and of size 400 MiB is set

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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: dos
Disk identifier: 0x280ab957

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      616447      307200   83  Linux
/dev/sda2          616448     1435647      409600   83  Linux

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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: dos
Disk identifier: 0x280ab957

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      616447      307200   83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
Partition number (2-4, default 2): 2
First sector (616448-2097151, default 616448): 
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): 
Using default value 2097151
Partition 2 of type Extended and of size 723 MiB is set

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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: dos
Disk identifier: 0x280ab957

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      616447      307200   83  Linux
/dev/sda2          616448     2097151      740352    5  Extended

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (618496-2097151, default 618496): 
Using default value 618496
Last sector, +sectors or +size{K,M,G} (618496-2097151, default 2097151): +200M
Partition 5 of type Linux and of size 200 MiB is set

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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: dos
Disk identifier: 0x280ab957

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      616447      307200   83  Linux
/dev/sda2          616448     2097151      740352    5  Extended
/dev/sda5          618496     1028095      204800   83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (1030144-2097151, default 1030144): 
Using default value 1030144
Last sector, +sectors or +size{K,M,G} (1030144-2097151, default 2097151): +400M
Partition 6 of type Linux and of size 400 MiB is set

Command (m for help): p

Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 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: dos
Disk identifier: 0x280ab957

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      616447      307200   83  Linux
/dev/sda2          616448     2097151      740352    5  Extended
/dev/sda5          618496     1028095      204800   83  Linux
/dev/sda6         1030144     1849343      409600   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


> lsblk 로 파티션 생성됨을 확인
[root@localhost etc]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0    1G  0 disk 
├─sda1        8:1    0  300M  0 part 
├─sda2        8:2    0    1K  0 part 
├─sda5        8:5    0  200M  0 part 
└─sda6        8:6    0  400M  0 part 
sdb           8:16   0    1G  0 disk 
vda         252:0    0   20G  0 disk 
├─vda1      252:1    0    1G  0 part /boot
└─vda2      252:2    0   19G  0 part 
  ├─cl-root 253:0    0   17G  0 lvm  /
  └─cl-swap 253:1    0    2G  0 lvm  [SWAP]

parted

[root@localhost etc]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): ?
b	back up GPT data to a file
c	change a partition's name
d	delete a partition
i	show detailed information on a partition
l	list known partition types
n	add a new partition
o	create a new empty GUID partition table (GPT)
p	print the partition table
q	quit without saving changes
r	recovery and transformation options (experts only)
s	sort partitions
t	change a partition's type code
v	verify disk
w	write table to disk and exit
x	extra functionality (experts only)
?	print this menu

Command (? for help): q
[root@localhost etc]# clear

[root@localhost etc]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
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
(parted) p                                                                
Error: /dev/sdb: unrecognised disk label
Model: QEMU QEMU HARDDISK (scsi)                                          
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
(parted) mkpart                                                           
Error: /dev/sdb: unrecognised disk label
(parted) mkpart primary 0% 300M
Error: /dev/sdb: unrecognised disk label
(parted) mklabel msdos
(parted) p                                                                
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End  Size  Type  File system  Flags

(parted) mklabel gpt                                                      
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you
want to continue?
Yes/No? yes                                                               
(parted) p                                                                
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary 301M 100%                                         
(parted) p                                                                
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End     Size   File system  Name     Flags
 1      301MB  1073MB  772MB               primary

(parted) mkpart primary 0% 300M
(parted) p
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size   File system  Name     Flags
 2      1049kB  300MB   299MB               primary
 1      301MB   1073MB  772MB               primary

(parted) rm 1                                                             
(parted) p                                                                
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 2      1049kB  300MB  299MB               primary

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

[root@localhost etc]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0    1G  0 disk 
├─sda1        8:1    0  300M  0 part 
├─sda2        8:2    0    1K  0 part 
├─sda5        8:5    0  200M  0 part 
└─sda6        8:6    0  400M  0 part 
sdb           8:16   0    1G  0 disk 
└─sdb2        8:18   0  285M  0 part 
vda         252:0    0   20G  0 disk 
├─vda1      252:1    0    1G  0 part /boot
└─vda2      252:2    0   19G  0 part 
  ├─cl-root 253:0    0   17G  0 lvm  /
  └─cl-swap 253:1    0    2G  0 lvm  [SWAP]
[root@localhost etc]# lsblk -f
NAME        FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                  
├─sda1                                                               
├─sda2                                                               
├─sda5                                                               
└─sda6                                                               
sdb                                                                  
└─sdb2                                                               
vda                                                                  
├─vda1      xfs               0cab009d-2c67-4dc9-a881-c5efde97ed56   /boot
└─vda2      LVM2_member       CFDwnt-NM58-A0Gj-sTQy-iCPE-EsRc-iqIAyb 
  ├─cl-root xfs               999a2a08-42a2-4cbc-a52c-3544d87d2897   /
  └─cl-swap swap              faab5b3c-984a-4a82-a139-92d1b706f013   [SWAP]
[root@localhost etc]# mkfs -t xfs /dev/sda1
meta-data=/dev/sda1              isize=512    agcount=4, agsize=19200 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=76800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost etc]# mkfs -t ext4 /dev/sda5
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

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

[root@localhost etc]# lsblk -f
NAME        FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                  
├─sda1      xfs               243550a7-03de-42be-a6f4-726a8ea2a6ce   
├─sda2                                                               
├─sda5      ext4              571a7ee6-2340-4337-8741-10aae94af0fb   
└─sda6                                                               
sdb                                                                  
└─sdb2                                                               
vda                                                                  
├─vda1      xfs               0cab009d-2c67-4dc9-a881-c5efde97ed56   /boot
└─vda2      LVM2_member       CFDwnt-NM58-A0Gj-sTQy-iCPE-EsRc-iqIAyb 
  ├─cl-root xfs               999a2a08-42a2-4cbc-a52c-3544d87d2897   /
  └─cl-swap swap              faab5b3c-984a-4a82-a139-92d1b706f013   [SWAP]

mount

[root@localhost etc]# mkdir /white /black
[root@localhost etc]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0    1G  0 disk 
├─sda1        8:1    0  300M  0 part 
├─sda2        8:2    0    1K  0 part 
├─sda5        8:5    0  200M  0 part 
└─sda6        8:6    0  400M  0 part 
sdb           8:16   0    1G  0 disk 
└─sdb2        8:18   0  285M  0 part 
vda         252:0    0   20G  0 disk 
├─vda1      252:1    0    1G  0 part /boot
└─vda2      252:2    0   19G  0 part 
  ├─cl-root 253:0    0   17G  0 lvm  /
  └─cl-swap 253:1    0    2G  0 lvm  [SWAP]
[root@localhost etc]# lsblk -f
NAME        FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                  
├─sda1      xfs               243550a7-03de-42be-a6f4-726a8ea2a6ce   
├─sda2                                                               
├─sda5      ext4              571a7ee6-2340-4337-8741-10aae94af0fb   
└─sda6                                                               
sdb                                                                  
└─sdb2                                                               
vda                                                                  
├─vda1      xfs               0cab009d-2c67-4dc9-a881-c5efde97ed56   /boot
└─vda2      LVM2_member       CFDwnt-NM58-A0Gj-sTQy-iCPE-EsRc-iqIAyb 
  ├─cl-root xfs               999a2a08-42a2-4cbc-a52c-3544d87d2897   /
  └─cl-swap swap              faab5b3c-984a-4a82-a139-92d1b706f013   [SWAP]
[root@localhost etc]# mount /dev/sda1 /white
[root@localhost etc]# mount /dev/sda5 /black

[root@localhost etc]# lsblk -f
NAME        FSTYPE      LABEL UUID                                   MOUNTPOINT
sda                                                                  
├─sda1      xfs               243550a7-03de-42be-a6f4-726a8ea2a6ce   /white
├─sda2                                                               
├─sda5      ext4              571a7ee6-2340-4337-8741-10aae94af0fb   /black
└─sda6                                                               
sdb                                                                  
└─sdb2                                                               
vda                                                                  
├─vda1      xfs               0cab009d-2c67-4dc9-a881-c5efde97ed56   /boot
└─vda2      LVM2_member       CFDwnt-NM58-A0Gj-sTQy-iCPE-EsRc-iqIAyb 
  ├─cl-root xfs               999a2a08-42a2-4cbc-a52c-3544d87d2897   /
  └─cl-swap swap              faab5b3c-984a-4a82-a139-92d1b706f013   [SWAP]
  
> lsblk -f와 동일하게 확인 가능
[root@localhost etc]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   17G  4.7G   13G  28% /
devtmpfs             2.0G     0  2.0G   0% /dev
tmpfs                2.0G  144K  2.0G   1% /dev/shm
tmpfs                2.0G  9.0M  2.0G   1% /run
tmpfs                2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/vda1           1014M  157M  858M  16% /boot
tmpfs                396M  4.0K  396M   1% /run/user/42
tmpfs                396M   20K  396M   1% /run/user/0
tmpfs                396M     0  396M   0% /run/user/1001
tmpfs                396M     0  396M   0% /run/user/1000
/dev/sda1            297M   16M  282M   6% /white
/dev/sda5            190M  1.6M  175M   1% /black




[root@localhost etc]# vi /etc/fstab
  #
  # /etc/fstab
  # Created by anaconda on Thu Apr 13 10:19:58 2023
  #
  # 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
  #
  /dev/mapper/cl-root     /                       xfs     defaults        0 0
  UUID=0cab009d-2c67-4dc9-a881-c5efde97ed56 /boot                   xfs     defaults        0 0
  /dev/mapper/cl-swap     swap                    swap    defaults        0 0
  /dev/sda1               /white                  xfs     defaults        0 0
  /dev/sda5               /black                  ext4    defaults        0 1
  ~                                                                               
~                                                                               
~            
[root@localhost etc]# mount -a 
[root@localhost etc]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   17G  4.7G   13G  28% /
devtmpfs             2.0G     0  2.0G   0% /dev
tmpfs                2.0G  144K  2.0G   1% /dev/shm
tmpfs                2.0G  9.0M  2.0G   1% /run
tmpfs                2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/vda1           1014M  157M  858M  16% /boot
tmpfs                396M  4.0K  396M   1% /run/user/42
tmpfs                396M   20K  396M   1% /run/user/0
tmpfs                396M     0  396M   0% /run/user/1001
tmpfs                396M     0  396M   0% /run/user/1000
/dev/sda1            297M   16M  282M   6% /white
/dev/sda5            190M  1.6M  175M   1% /black


[root@localhost ~]# reboot

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   17G  4.7G   13G  28% /
devtmpfs             2.0G     0  2.0G   0% /dev
tmpfs                2.0G  160K  2.0G   1% /dev/shm
tmpfs                2.0G  8.9M  2.0G   1% /run
tmpfs                2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/vda1           1014M  157M  858M  16% /boot
/dev/sda1            297M   16M  282M   6% /white
/dev/sda5            190M  1.6M  175M   1% /black
tmpfs                396M  8.0K  396M   1% /run/user/42
tmpfs                396M   12K  396M   1% /run/user/0

profile
study log

0개의 댓글