Showing posts with label lvm. Show all posts
Showing posts with label lvm. Show all posts

Monday, September 12, 2011

Linux Mint 11 "Katya" on VAIO P - VPCP115KG Part 5 (Experimental)

Aligning Filesystems
As the erase block size has been identified, in order to align with it, the previous partitions / volumes configuration are reconfigured.


Proposed Disk Layout
Partition / Volume Size Remark
/dev/vg00/lv00 9216MB / partition in LV (576 LE)
/dev/sda1 256MB /boot partition
/dev/vg00/lv01 1024MB swap partition (64 LE)
/dev/vg00/ev00 16GB encrypted 16GB partition in LV (1000 LE)
/dev/vg00/lv02 32224MB /data partition in LV (3072 LE)
free space
144 LE free space for snapshot


Factory CHS & Partition Table
I don't bother with the default CHS, instead I create a /boot partition after the first 16MB erase block, both the size of sda1 & sda2 are divisible by 16.
# sfdisk -luM /dev/sda
 
Disk /dev/sda: 7783 cylinders, 255 heads, 63 sectors/track
Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start   End    MiB    #blocks   Id  System
/dev/sda1   *    16    271    256     262144   83  Linux
/dev/sda2       272  61055  60784   62242816   8e  Linux LVM
/dev/sda3         0      -      0          0    0  Empty
/dev/sda4         0      -      0          0    0  Empty

# sfdisk -luS /dev/sda
Disk /dev/sda: 7783 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sda1   *     32768    557055     524288  83  Linux
/dev/sda2        557056 125042687  124485632  8e  Linux LVM
/dev/sda3             0         -          0   0  Empty
/dev/sda4             0         -          0   0  Empty



Partitioning
Create a LVM physical volume:
# lvm pvcreate --dataalignment 16384k /dev/sda2
Confirm if the PV is properly aligned:
# pvs -o +pe_start
  PV         VG   Fmt  Attr PSize  PFree 1st PE
  /dev/sda2  vg00 lvm2 a-   59.34g 2.25g  16.00m 

Create a LVM volume group:
# lvm vgcreate -s 16 vg00 /dev/sda2
Confirm the PE size of the logical volume:
# lvm vgdisplay /dev/vg00 | grep 'PE Size'
  PE Size               16.00 MiB 

Create a / volume (576 LE x 16):
# lvm lvcreate -n lv00 -L 9216 /dev/vg00
Create a swap volume (64 LE x 16):
# lvm lvcreate -n lv01 -L 1024 /dev/vg00
Create a volume for LUKS (1000 LE x 16):
# lvm lvcreate -n ev00 -L 16000 vg00
Create a volume for /data (2014 LE):
# lvm lvcreate -n lv02 -l 2014 /dev/vg00

Create an ext4 /boot partition:
# mkfs.ext4 -E stripe-width=16384 -b 1024 /dev/sda1
Create an ext4 / volume:
# mkfs.ext4 -E stripe-width=4096 -b 4096 /dev/vg00/lv00
Activate swap partition:
# mkswap /dev/vg00/lv01
Create an ext4 LUKS volume (refer to Part 1 on how to create it):
# mkfs.ext4 -E stripe-width=4096 -b 4096 /dev/mapper/ev00
Create an ext4 /data volume:
# mkfs.ext4 -E stripe-width=4096 -b 4096 /dev/vg00/lv02


Restore
Refer to Part 2 on how to restore the data as well as the boot loader, when necessary.


I/O Scheduler

Edit /etc/rc.local and add the lines highlighted in blue below:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

echo deadline > /sys/block/sda/queue/scheduler
echo 1 > /sys/block/sda/queue/iosched/fifo_batch

exit 0





Everything should be aligned to 16MB erase block, hopefully.




Thursday, August 25, 2011

Linux Mint 11 "Katya" on VAIO P - VPCP115KG Part 2

Backup
I use an USB hard disk cradle to store backup dump files. The hard disk is formatted in ext4 filesystem.
Prerequisite is to install dump utility first:
$ su -
# apt-get install dump


Let's create a snapshot:
# lvcreate -l 563 -s -n lv99.fss /dev/vg00/lv00
Start backing up / filesystem (assume the USB disk is mounted under /media/backup):
# dump 0uf /media/backup/20110822-vpcp115kg-lv00.dmp /dev/vg00/lv99.fss
When it completes, delete the snapshot:
# lvremove -f /dev/vg00/lv99.fss


The / backup takes 6 minutes 42 seconds.

Let's create a backup of /boot partition:
# dump 0uf /media/backup/20110822-vpcp115kg-boot.dmp /dev/sda1


The /boot backup takes 2 seconds.

The first backup we used snapshot, the second backup we did not use, actually we cannot use snapshot because /boot partition is not a logical volume. We use snapshot because we want a solid backup that we can restore it later. Since / filesystem is an active partition (try umount it), using dump might not guaranty a successful restore (the restore might be fine, actually), but the OS might have problem due to file inconsistency. On the other hand, /boot partition is not considered active, you can try umount it after the OS is up. Or umount it before taking backup.


Restore
To restore the / filesystem due to whatever reasons:
- Boot Katya using the boot media (the USB flash drive) with active network connection.


When Katya is ready, connect the backup media (assume it is mounted under /media/backup), then open a gnome-terminal:
$ sudo su -
# apt-get install lvm2 dump
Activate logical volume lv00:
# lvm lvchange -a y /dev/vg00/lv00
Wipe logical volume lv00:
# mkfs.ext4 /dev/vg00/lv00
# mkdir -p /media/lv00
# mount /dev/vg00/lv00 /media/lv00


Start restoring / filesystem:
# cd /media/lv00
# restore rvf /media/backup/20110822-vpcp115kg-lv00.dmp
When the restore completes (it takes about 10 minutes):
# sync
# rm restoresymtable
# cd /
# umount /media/lv00
Run a filesystem check against logical volume lv00:
# fsck /dev/vg00/lv00


Ignore this step if it is required to restore /boot filesystem, otherwise just issue the following two commands and stop.
# umount /media/backup
# init 6

Retrieve the UUID of /dev/sda1:
# blkid | grep '/dev/sda1'
/dev/sda1: UUID="e80248bf-2417-4d66-a104-b8dce0e34c71" TYPE="ext4"
To restore the /boot filesystem:
# mkfs.ext4 /dev/sda1
# mkdir -p /media/sda1
# mount /dev/sda1 /media/sda1
Start restoring /boot filesystem:
# cd /media/sda1
# restore rvf /media/backup/20110822-vpcp115kg-boot.dmp
When the restore completes (it takes about 20 seconds):
# sync
# rm restoresymtable
# cd /
# umount /media/sda1

Disconnect the USB backup media:
# umount /media/backup
Since /dev/sda1 was wiped previously, need to re-install GRUB2:
# mount /dev/vg00/lv00 /media
# mount /dev/sda1 /media/boot
# grub-install --root-directory=/media /dev/sda --force
# sync

Assign the old UUID to /dev/sda1:
# tune2fs /dev/sda1 -U e80248bf-2417-4d66-a104-b8dce0e34c71

Umount restored filesystems
# umount /media/boot
# umount /media
Run a filesystem check against /dev/sda1:
# fsck /dev/sda1
Deactivate logical volume lv00:
# lvm lvchange -a n /dev/vg00/lv00
# init 6


If you re-install GRUB2 previously, run the following command after reboot:
# update-grub

The OS is back to the previous stage of the last backup.


Intel EMGD (GMA500 driver)
There are four commands to enter (for more information, please refer to the instructions found in Ubuntu wiki "Poulsbo" 2.1):
# add-apt-repository ppa:gma500/emgd
# apt-get update
# apt-get install xorg-emgd emgd-dkms emgd-xorg-conf
# emgd-xorg-conf


Don't reboot yet, copy the configuration from this page and save it as /usr/share/X11/xorg.conf.d/10-emgd.conf, then go ahead to reboot:
# init 6


Once it is rebooted, Compiz can be activated!


Brightness Function Keys Fix
Install emgdbl package:
# apt-get install emgdbl


Edit the following line in /etc/default/grub (added settings are highlighted in blue):
GRUB_CMDLINE_LINUX="acpi_osi=Linux acpi_backlight=video mem=1920mb"


Append the following line in /etc/modprobe.d/blacklist.conf:
blacklist poulsbo

Append the following line in /etc/initramfs-tools/modules:
emgdbl


Generate a new initramfs image:
# cd /boot
# cp -p initrd.img-2.6.38-11-generic initrd.img-2.6.38-11-generic.20110825
# mkinitramfs -o initrd.img-2.6.38-11-generic

# init 6

After reboot, the F5 & F6 keys are resumed.


Other Little Hacks
Disable tty2 - tty6 by editing /etc/init/tty[2-6].conf:
Comment the following line:
#start on runlevel [23]


Disable the following services from Startup Applications Preference in Control Panel:
- Bluetooth Manager
- Dropbox
- GNOME Login Sound
- GSettings Data Conversion
- mintWelcome
- Personal File Sharing
- PulseAudio Sound System KDE Routing Policy
- Visual Assistance
- Zeltgelst Datahub


In Keyboard Shortcuts, assign Launch web browser action to the "WEB" key. Once it is assigned, the default browser will be launched when you press the "WEB" key in Gnome.




Linux Mint 11 "Katya" on VAIO P - VPCP115KG Part 1

Hardware Specification
VAIO P - VPCP115KG


Boot Media
Use Startup Disk Creator from another Linux node to make a bootable USB flash drive. A 1GB USB flash drive is good enough. The disc image is linuxmint11-gnome-dvd-32bit.iso.

In case the flash drive boots with error message "vesamenu.c32 not a com32r image", run the following commands from the node (replace the text highlighted in red colour accordingly):

# cp -r /usr/lib/syslinux/vesamenu.c32 /media/20AD-F9B9/syslinux/
# syslinux /dev/sdc1



Partitioning #1
This laptop comes with one 64GB SSD and 2GB memory.
Partition Size Remark
/dev/vg00/lv00 9000MB / partition in LV
/dev/sda1 100MB /boot partition
/dev/vg00/lv01 1024MB swap partition
/dev/vg00/ev00 16GB encrypted 16GB partition in LV
/dev/vg00/lv02 8070 LE /data partition in LV
free space
563 PE free space for snapshot

LV - Logical Volume
LE - Logical Extents
PE - Physical Extents


Once Katya is booted from the flash drive with network available, run the following commands to install lvm:
$ sudo su -
# apt-get install lvm2


Create a 100MB /boot partition:
# fdisk /dev/sda (n; p; 1; <default>; +100M)
Use rest of the disk for LVM (continue from the previous command):
(n; p; 2; <default>; <default>; w)

Create physical volume:
# lvm pvcreate /dev/sda2
Create volume group vg00:
# lvm vgcreate vg00 /dev/sda2
Create logical volume group lv00, i.e. / partition:
# lvm lvcreate -n lv00 -L 9000 vg00
Create logical volume group lv01, i.e. swap partition:
# lvm lvcreate -n lv01 -L 1024 vg00
Create ext4 filesystem:
# mkfs.ext4 /dev/sda1
# mkfs.ext4 /dev/vg00/lv00
Create a swap area:
# mkswap /dev/vg00/lv01


When Katya is installed, will continue to add the encrypted partition and /data partition.


Installation
Launch Install Linux Mint icon from the desktop, follow the instructions and assign /, /boot and swap partition appropriately. When the installation finishes, click 'Continue testing' button.

Open a gnome-terminal and install lvm2 before reboot:
$ sudo su -
# mkdir /mnt/lv00
# mount /dev/vg00/lv00 /mnt/lv00
# mount /dev/sda1 /mnt/lv00/boot
# chroot /mnt/lv00
# mount -t proc proc /proc
# mount -t sysfs sysfs /sys
# apt install lvm2
# sync
# exit
# umount /mnt/lv00
# init 6

Once the node is rebooted, Katya is ready, login and launch Update Manager, when all updated packages are installed, reboot the node and prepare to create the other two volumes.



LUKS Volume
Create an encrypted LV:
$ su -
# lvm lvcreate -n ev00 -L 16G vg00
Next command takes 8 to 9 hours to finish:
# dd if=/dev/urandom of=/dev/vg00/ev00
Create a passphrase using cryptsetup, follow instructions from the command:
# cryptsetup --verify-passphrase --key-size 256 luksFormat /dev/vg00/ev00
Open the LUKS volume:
# cryptsetup luksOpen /dev/vg00/ev00 ev00
Create ext4 filesystem:
# mkfs.ext4 /dev/mapper/ev00

Up to this point, the encrypted volume ev00 is created, going forward to access the volume (let's say, under /media/ev00), run the following commands:
# cryptsetup luksOpen /dev/vg00/ev00 ev00
# mount -o acl,noatime /dev/mapper/ev00 /media/ev00
The parameter acl gives us more control over traditional u:g:o ownership. acl package needs to be installed explicitly:
# apt-get install acl
To use ACL, issue the following command (replace the username field highlighted in blue colour):
# setfacl -R -m u:ninja:rwx /media/ev00
The parameter noatime can speed up the read/write disk access with an acceptable trade-off - Access timestamps are not updated when a file is read. In other words, it extends the lifespan of your SSD.



Partitioning #2
Create /data volume, and why is it 8070 LE?
The reason to use LVM is to facilitate snapshot of any active partition, i.e. / partition. In order to have a solid / partition snapshot, one quarter (20% to 25%, more precisely) of free space equals to the size of / partition is required. When we created logical volume lv00, a 9GB volume was allocated, its LE is 2250:
# lvm lvdisplay /dev/vg00/lv00 | grep 'LE'
  Current LE             2250


Therefore 563 LE (2250 / 4 = 562.5) has to be reserved for snapshot (PE and LE are interchangeable). To figure out how much free PE is available from volume group vg00, we can run the following command:
# lvm vgdisplay /dev/vg00 | grep -e 'Free'
  Free  PE / Size       8633 / 33.72 GiB


8377 - 563 = 7814, that is how the value gets calculated. Let's create /data volume:
# lvm lvcreate -name lv02 -l 8070 vg00
# mkfs.ext4 /dev/vg00/lv02
# mkdir /data


To start using /data volume:
# mount -o acl,noatime /dev/vg00/lv02 /data
Apply ACL:
# setfacl -R -m u:ninja:rwx /data


Add the new created volume in /etc/fstab and apply other parameters (all changes are highlighted in blue colour):
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system>       <mount point> <type> <options>                 <dump>  <pass>
proc                  /proc         proc   nodev,noexec,nosuid       0       0
/dev/mapper/vg00-lv00 /             ext4   errors=remount-ro,noatime 0       1
/dev/sda1             /boot         ext4   defaults,noatime          0       2
/dev/mapper/vg00-lv02 /data         ext4   defaults,noatime,acl      0       2
/dev/mapper/vg00-lv01 none          swap   sw                        0       0
tmpfs                 /tmp          tmpfs  mode=1777                 0       0


Please note a tmpfs is also created and mounted under /tmp.

Next, reboot the system.