Showing posts with label resize. Show all posts
Showing posts with label resize. Show all posts

2012-12-30

Migrate /home in Ubuntu

Sadly Ubuntu does not have LVM enabled in the default install, as this whole issue would be solved with a simple pvmigrate and lvresize...

My /home (which is on a separate /dev/sda5 partition) is filling up.
The availability of Steam on Linux gave it the final blow: it's time to bring in another partition.
As I don't want to commit a whole partition to /home, I've mounted /dev/sdc2 as /space and I'm going to create a symlink to an home subdirectory.

First, boot Ubuntu in rescue mode and select root shell.

Mount all filesystems

#mount -a

note that mounted filesystem won't be visible with a df, but you should cat /proc/mounts to see them
Set proper permission to the new partition

#chown root:root /space
#chmod 755 /space

Then create the new home and copy the old one

#mkdir /space/home
#cp -a /home/* /space/home/

Mount / read/write as we'll need to modify the fstab

#mount / -o rw,remount
#vi /etc/fstab

Comment the old /home
Remove the old home mount point and create the new symlink

#umount /home
#rmdir /home
#ls -s /space/home /home

Reboot

2012-05-18

Replacing a mechanical HD with an SSD

My home PC is aging... It's 6 years old now, and while this confirms the goodness of the choices I've made when I built it, this also means that the XP installation has gathered so many stuff that it's now slow as hell.
A full boot takes now as much as 4'20":
30" from startup to the login screen of Windows XP
3'40" to quiesce all disk activities.
At that point, 40 more seconds are necessary from login to complete disk stop. Trying to launch any program before the disk settles out, just results in more thrashing and an even slower startup.
So I've bought a Crucial m4 SSD to see if this upgrade can make a difference.

This was the starting configuration:
I have 2 HDs in my PC, one for the OS and one for the data.
The OS is multiboot, so I have one partition for XP and one for Ubuntu.
The remaining disk space is for Windows program files partition.



On the second unit there are the swap partitions for Windows and Linux, the Documents and Settings partition, the /home filesystem and some spare space for Windows.

The purpose of this layout is to allow concurrent access to OS and swap, OS and user files, applications and user data.

The first step was copying the content of the first disk onto the new ssd.
I connected the new disk to an empty SATA connector and booted into Parted Magic.
Using GParted I initialized the new disk with Device -> Create Partition Table, then it was just a copy/paste work between the old partition on /dev/sda and the new disk seen as /dev/sdc
The Crucial M4 is just 119GiB while my old disk was 153, so I needed to shrink the sda3 partition to make it fit.
After copying the /dev/sda1 partition I needed to set the "boot" flag on it on the new disk to make it bootable.

GParted copied all partitions but left a standard Windows MBR, so grub was gone and linux didn't boot.
To restore the grub MBR I've followed this excellent guide, and linux was back in action.
Windows booted but wasn't in good shape either:

I logged in and the whole desktop froze with only the wallpaper displayed, but no start button, taskbar or icons.
It just hung there forever.
I rebooted in safe mode by pressing F8 and choosing "Safe mode with command prompt".
A popup went up, saying that windows had found new hardware and the drivers had been installed.
One more reboot and Windows was fine with the new disk.

Now a complete boot takes as low as 19 seconds, and no more disk thrashing after loggin on: the Start menu is immediately available and responsive.

The last step was setting noatime in /etc/fstab to reduce writing on the SSD.

So, here it is, by comparison with a traditional 3.5" HD, the little Crucial M4


2011-12-04

Expanding the C drive of a VM

This was tested on Windows 2003 R2

Here's a VM that need its C drive expanded:


Edit VM Setting and set the new VMDK size (this can be done online).


Rescan disks, and you'll see extra free space at the end of the partition.


Now boot into Parted Magic.
Select the first partition, click Resize and set the new size.


You will have to select Apply to actually do the resize.

Reboot into Windows.
CHKDSK will run automatically and finally you will have your expanded C drive.

Shrinking the root filesystem

The default install of RedHat 5 fills the entire disk with the root filesystem: this may backfire later during machine lifetime.
Here's a way to resize the root filesystem.
Note that while the size increase can be done online, as of RedHat 5, size reduction must be performed in rescue mode.

Here's a tipical installation:

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      7.7G  3.1G  4.3G  42% /
/dev/sda1              99M   19M   75M  21% /boot
tmpfs                 502M     0  502M   0% /dev/shm

# vgdisplay -v
    Finding all volume groups
    Finding volume group "VolGroup00"
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.88 GB
  PE Size               32.00 MB
  Total PE              316
  Alloc PE / Size       316 / 9.88 GB
  Free  PE / Size       0 / 0
  VG UUID               CJqD4r-kRQM-Cj9e-XwOr-6dn8-TkPH-MfTTyZ

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                d4iToX-8m0c-jf9s-sMMN-VDpO-brE8-4kWhf2
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                7.91 GB
  Current LE             253
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                kEzo7d-AHuv-xiPD-3Qbo-v8yY-6w1D-DFMIwN
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.97 GB
  Current LE             63
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Physical volumes ---
  PV Name               /dev/sda2
  PV UUID               7bPvQd-H8yE-v00N-asPT-WQ92-6oCS-bBh6nj
  PV Status             allocatable
  Total PE / Free PE    316 / 0

The physical volume is full, with 0 free extents.

We are going to reduce / size to 6GB.
Boot in rescue mode

boot: linux rescue

Skip existing installation detection.
Activate existing volume groups:

# lvm vgscan
# lvm vgchange -ay /dev/VolGroup00

Run a filesystem check before resizing:

# e2fsck -f /dev/VolGroup00/LogVol00

Set the filesystem size a litte less than required, so the resizing of the underlying logical volume won't cut short the filesystem itself.

# resize2fs /dev/VolGroup00/LogVol00 5G

Resize the logical volume to the target size.

# lvm lvresize -L 6G /dev/VolGroup00/LogVol00

Now resize again the filesystem without giving any size, so it will fill up the logical volume.

# resize2fs /dev/VolGroup00/LogVol00

Reboot back into the system.
You can see the new / size:

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      5.9G  3.1G  2.7G  54% /
/dev/sda1              99M   19M   75M  21% /boot
tmpfs                 502M     0  502M   0% /dev/shm

# vgdisplay -v
    Finding all volume groups
    Finding volume group "VolGroup00"
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.88 GB
  PE Size               32.00 MB
  Total PE              316
  Alloc PE / Size       255 / 7.97 GB
  Free  PE / Size       61 / 1.91 GB
  VG UUID               CJqD4r-kRQM-Cj9e-XwOr-6dn8-TkPH-MfTTyZ

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                d4iToX-8m0c-jf9s-sMMN-VDpO-brE8-4kWhf2
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                6.00 GB
  Current LE             192
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                kEzo7d-AHuv-xiPD-3Qbo-v8yY-6w1D-DFMIwN
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.97 GB
  Current LE             63
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Physical volumes ---
  PV Name               /dev/sda2
  PV UUID               7bPvQd-H8yE-v00N-asPT-WQ92-6oCS-bBh6nj
  PV Status             allocatable
  Total PE / Free PE    316 / 61

And the physical volume now has some spare space left.

2011-11-27

Boot disk transplant

Bare hands, MacGyver-style, boot disk transplant.

I've used a network attached linux machine as a temporary storage, but a local USB disk will do as fine.
The new disk should be as least as big as the old one.

First take note of the original disk configuration.
You will need the partition table:

# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1305    10377990   8e  Linux LVM

The volume group configuration (note the PE and the LE sizes)

# vgdisplay -v
    Finding all volume groups
  /dev/hda: open failed: No medium found
    Finding volume group "VolGroup00"
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.88 GB
  PE Size               32.00 MB
  Total PE              316
  Alloc PE / Size       316 / 9.88 GB
  Free  PE / Size       0 / 0
  VG UUID               CJqD4r-kRQM-Cj9e-XwOr-6dn8-TkPH-MfTTyZ

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                d4iToX-8m0c-jf9s-sMMN-VDpO-brE8-4kWhf2
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                7.91 GB
  Current LE             253
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                kEzo7d-AHuv-xiPD-3Qbo-v8yY-6w1D-DFMIwN
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.97 GB
  Current LE             63
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Physical volumes ---
  PV Name               /dev/sda2
  PV UUID               7bPvQd-H8yE-v00N-asPT-WQ92-6oCS-bBh6nj
  PV Status             allocatable
  Total PE / Free PE    316 / 0

And the fstab:

# cat /mnt/sysimage/etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

you will have to rebuild the logical volumes that belong to the transplanting disk

Boot the machine in rescue mode to do a full backup

boot: linux rescue

Start the network interface and do not mount any filesystem.
Backup the filesystems on /dev/sda and send them to the second machine via network.

#gzip -1 </dev/VolGroup00/LogVol00 | ssh user@secondmachine "cat >root.gz"
#gzip -1 </dev/sda1 | ssh user@secondmachine "cat >boot.gz"

Turn off the first machine, remove the old hd and put the new one.
Reboot again into linux rescue, with networking and without searching for existing installations.

Use fdisk to rebuild the same layout, with identical partitions, cylinder boundaries and partition Id (8e for LVM)
Now rebuild the LVM

#lvm pvcreate /dev/sda2

Note the PE size:

#lvm vgcreate -s 32M VolGroup00 /dev/sda2

and the LV size

#lvm lvcreate -l 253 -n LogVol00 VolGroup00
#lvm lvcreate -l 63 -n LogVol01 VolGroup00

Rebuild the swap partition

#mkswap /dev/VolGroup00/LogVol01

and write back the previous backups:

#ssh user@secondmachine "cat boot.gz" | gzip -d > /dev/sda1
#ssh user@secondmachine "cat root.gz" | gzip -d > /dev/VolGroup00/LogVol00

Reboot once again in rescue mode

#chroot /mnt/sysimage 
#grub-install /dev/sda

And finally reboot with your new disk.
Note that if the new disk is bigger than the old one, you will have some unpartitioned space left.
You can partition it with fdisk, pvcreate, and add it to LVM.