Part 3: Configure local storage
1) List, create, delete, and set partition type for primary, extended, and logical partitions.
* fdisk or parted. fdisk is better for me ;)
* fdisk -l /dev/sda (show/list)
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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
[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x00002249
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 1045 7875584 8e Linux LVM
* fdisk /dev/sda(device) then do create, delete whatever
* for disks > 2TB -> use parted, then mklabel gpt, then can set default unit to TB -> 'unit TB'
then do partitions by "mkpart ..." in parted!
2) Create and remove physical volumes, assign physical volumes to volume groups, and create and delete logical volumes.
* for my examples in vbox on rhel I will go on sdb(4gb) + sdc(1gb) + sdd (1gb)
* main thing ;)
PV (physical volumes) (storage devices like /dev/sdb1 or /dev/hda1 ...)
VG (volume groups) (grouped storage devices, lets say that in group we can connect sdb1 and hda1 and as result got more place)
LV (logical volumes) (our partitions :) where we can store our data ;) )
* create PV
pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd (yes! can be used sdd ;) )
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdd" successfully created
* remove PV (at next example I will add sdd to show how to extend that PV ;) )
[root@localhost ~]# pvremove /dev/sdd
Labels on physical volume "/dev/sdd" successfully wiped
* display PV
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name MyName
PV Size 2.00 GiB / not usable 3.32 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 511
Free PE 511
Allocated PE 0
PV UUID rp0Dj3-KO1P-47FL-5XnE-5IVK-cV4m-9vFHIs
--- Physical volume ---
PV Name /dev/sdc1
VG Name MyName
PV Size 1019.72 MiB / not usable 3.72 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 254
Free PE 254
Allocated PE 0
PV UUID rsWkWp-wnOh-YoZ6-DDbj-ywZC-zByc-Yo7Oca
* create VG
[root@localhost ~]# vgcreate MyName /dev/sdb1 /dev/sdc1
Volume group "MyName" successfully created
* delete VG
[root@localhost ~]# vgremove -v MyName
Using volume group(s) on command line
Finding volume group "MyName"
Archiving volume group "MyName" metadata (seqno 1).
Removing physical volume "/dev/sdb1" from volume group "MyName"
Removing physical volume "/dev/sdc1" from volume group "MyName"
Volume group "MyName" successfully removed
* reduce VG
[root@localhost ~]# vgreduce -v MyName /dev/sdc1
Finding volume group "MyName"
Using physical volume(s) on command line
Archiving volume group "MyName" metadata (seqno 1).
Removing "/dev/sdc1" from volume group "MyName"
Creating volume group backup "/etc/lvm/backup/MyName" (seqno 2).
Removed "/dev/sdc1" from volume group "MyName"
New vg size is 2.00 GiB
* extend VG
[root@localhost ~]# vgextend -v MyName /dev/sdc1
Checking for volume group "MyName"
Archiving volume group "MyName" metadata (seqno 2).
Wiping cache of LVM-capable devices
Adding physical volume '/dev/sdc1' to volume group 'MyName'
Volume group "MyName" will be extended by 1 new physical volumes
Creating volume group backup "/etc/lvm/backup/MyName" (seqno 3).
Volume group "MyName" successfully extended
New extended size is ~3GB (2 + 1)
* change vg status by hand
vgchange -a y (activate all)
vgchange -n y (deactivate all)
* create LV (lvcreate -L SIZE -n NAME WHERE)
lvcreate -L 512M -n data MyName
[root@localhost ~]# lvcreate -L 512M -n data MyName
Logical volume "data" created
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/MyName/data
LV Name data
VG Name MyName
LV UUID SAIzgv-J0hv-V0vs-KLIv-9fsS-eT1I-ORhQ6M
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2013-04-20 01:24:31 +0200
LV Status available
# open 0
LV Size 512.00 MiB
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
* extend LV
[root@localhost ~]# lvextend -v -L +512M /dev/MyName/data
Finding volume group MyName
Archiving volume group "MyName" metadata (seqno 4).
Extending logical volume data to 1.00 GiB
Found volume group "MyName"
Found volume group "MyName"
Loading MyName-data table (253:2)
Suspending MyName-data (253:2) with device flush
Found volume group "MyName"
Resuming MyName-data (253:2)
Creating volume group backup "/etc/lvm/backup/MyName" (seqno 5).
Logical volume data successfully resized
* another extend ;) (prepare small lv and then resize it to 100% of free on VG)
[root@localhost ~]# lvcreate -L 512M -n test MyName
Logical volume "test" created
[root@localhost ~]# lvextend -l 100%FREE /dev/MyName/test
Extending logical volume test to 1.49 GiB
Logical volume test successfully resized
* remove lv
[root@localhost ~]# lvremove /dev/MyName/test
Do you really want to remove active logical volume test? [y/n]: y
Logical volume "test" successfully removed
*** RESIZE fs system when resize LV ***
a) mkfs.ext4 /dev/MyName/data
mkfs.ext4 /dev/MyName/test
b) mkdir /XXX/
mkdir /XXX/data
mkdir /XXX/test
c) mount /dev/MyName/data /XXX/data
mount /dev/MyName/test /XXX/test
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
6.5G 1.1G 5.1G 18% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/sda1 485M 30M 430M 7% /boot
/dev/mapper/MyName-data
1008M 34M 924M 4% /XXX/data
/dev/mapper/MyName-test
504M 17M 462M 4% /XXX/test
d) lets add some data to test (128m)
[root@localhost ~]# lvextend -v -L +128M /dev/MyName/test
Finding volume group MyName
Archiving volume group "MyName" metadata (seqno 9).
Extending logical volume test to 640.00 MiB
e) resize FS/ext4
[root@localhost ~]# resize2fs /dev/MyName/test
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/MyName/test is mounted on /XXX/test; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/MyName/test to 163840 (4k) blocks.
The filesystem on /dev/MyName/test is now 163840 blocks long.
f) final check using df -h command gives
/dev/mapper/MyName-test
630M 17M 582M 3% /XXX/test
was 504, now is 630 ;)
3) Create and configure LUKS-encrypted partitions and logical volumes to prompt for password and mount a decrypted file system at boot
* one small partition for crypted data ;) sdd1 has 256M
* add some random data to partition (it can be also LVM ;)) (for 256M it take some time ...)
dd if=/dev/urandom of=/dev/sdd1
dd: writing to `/dev/sdd1': No space left on device
546148+0 records in
546147+0 records out
279627264 bytes (280 MB) copied, 75.4289 s, 3.7 MB/s
* cryptsetup luksFormat /dev/sdd1 (prepare luks format)
[root@localhost ~]# cryptsetup luksFormat /dev/sdd1
WARNING!
========
This will overwrite data on /dev/sdd1 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
* add label for partition
cryptsetup luksOpen /dev/sdd1 mydata
Enter passphrase for /dev/sdd1: (enter passsword)
* preare filesystem on mydata (BUT USE LABELED DEVICE under /dev/mapper!!! CAN'T USE /dev/sdd1!!!!!)
[root@localhost ~]# mkfs.ext4 /dev/mapper/mydata
* mount it somewhere and copy some data
mount /dev/mapper/mydata /media/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/mydata 257M 11M 234M 5% /media
* preparing for automount in redhat system (remember about >>, because it can be some lines in /etc/crypttab!)
echo "mydata /dev/sdd1" >> /etc/crypttab
mkdir /media/mydata
echo "/dev/mapper/mydata /media/mydata ext4 defaults 1 1" >> /etc/fstab
reboot system to check it or if not need, mount -a
after reboot it should ask for password :D
* another option for that automount using UUID
[root@localhost ~]# blkid /dev/mapper/mydata
/dev/mapper/mydata: UUID="96871128-21c3-4591-9632-973097cad8b5" TYPE="ext4"
and that UUID goes to FSTAB!
take UUID from sdd1
[root@localhost ~]# blkid /dev/sdd1
/dev/sdd1: UUID="6051a2a2-37c6-456c-ad72-ea00edbbf442" TYPE="crypto_LUKS"
and that UUID goes to CRYPTTAB!!!
echo "mydata UUID=6051a2a2-37c6-456c-ad72-ea00edbbf442" >> /etc/crypttab
mkdir /media/mydata
echo "UUID=96871128-21c3-4591-9632-973097cad8b5 /media/mydata ext4 defaults 1 1" >> /etc/fstab
4) Configure systems to mount file systems at boot by Universally Unique ID (UUID) or label.
* blkid
[root@localhost ~]# blkid
/dev/sda1: UUID="ca799f51-2805-43d2-a1aa-07c92d1d121d" TYPE="ext4"
/dev/sda2: UUID="bhUaaD-z1Sy-IijR-oC3H-Fhpw-Zfwf-OYmUTJ" TYPE="LVM2_member"
/dev/sdd1: UUID="6051a2a2-37c6-456c-ad72-ea00edbbf442" TYPE="crypto_LUKS"
/dev/mapper/VolGroup-lv_root: UUID="26e56548-0361-47a3-be1f-8d33f2f593df" TYPE="ext4"
/dev/mapper/VolGroup-lv_swap: UUID="9101544f-78c0-448b-96d6-7a0c1c77623e" TYPE="swap"
/dev/mapper/mydata: UUID="96871128-21c3-4591-9632-973097cad8b5" TYPE="ext4"
then in /etc/fstab something like this
UUID=96871128-21c3-4591-9632-973097cad8b5 /media/mydata ext4 defaults 1 1
* label option in 2 steps
mkfs.ext4 /dev/sdd2
e2label /dev/sdd2 MyLabel02
check it ;)
[root@localhost ~]# blkid /dev/sdd2
/dev/sdd2: LABEL="MyLabel02" UUID="41c9e8d1-edc1-4fa5-90ff-3678618bed63" TYPE="ext4"
* or label option in 1 step
mkfs.ext4 -L MyLabel /dev/sdd2
and check it ;)
[root@localhost ~]# blkid /dev/sdd2
/dev/sdd2: LABEL="MyLabel" UUID="2c8dc3db-87e5-465e-8c71-0fbbe0ab582c" TYPE="ext4"
then in /etc/fstab add something like this
LABEL=MyLabel /mynew_data ext4 defaults 1 2
then mount -a; mount to check mounted /mynew_data
result: /dev/sdd2 on /mynew_data type ext4 (rw)
5) Add new partitions and logical volumes, and swap to a system non-destructively.
* fdisk -cu /dev/disk, partitions, like swap, linux, lvm whatever
* do pg/vg/lv, whatever
* mkswap /dev/device; swapon /dev/device
* check swaps -> swapon -s
Brak komentarzy:
Prześlij komentarz