Moving a system off to a usb disk
There are cases where you don't want to bring a laptop with you, but still want to have your data or, even better, your system and configuration. It is actually not so difficult to do if you are using LVM. With my setup, it was quite straightforward. So, if you happen to have a similar setup (2 partitions : one for /boot
, and the other one for the LVM physical volume), here are the steps to do the same (assuming the usb disk is /dev/sda, the laptop disk /dev/hda, the LVM volume group vg, and you're using grub as a bootloader).
- Create equivalent partitions on the usb disk. In my case, the usb disk happens to be much bigger, so the LVM physical volume is going to be more than half free).
- Create an LVM physical volume on the second partition:
/sbin/pvcreate /dev/sda2
- Extend the existing volume group with the new physical volume:
/sbin/vgextend vg /dev/sda2
- Move all data from the laptop disk to the usb disk:
/sbin/pvmove -v /dev/hda2
- Now you have plenty of time during the pvmove, create a new filesystem for
/boot
in the first partition:
/sbin/mkfs.ext3 /dev/sda1
- Copy the current
/boot
files to the new filesystem:
mount /dev/sda1 /mnt
cp -a /boot/. /mnt
umount /mnt - As you will want to mount the new
/boot
at boot time, edit/etc/fstab
to replace the device for the/boot
entry by the new device. Since you probably don't know in advance what the device will be (you may use the disk on any computer, possibly with a SATA disk that will be onsda
), it is preferred to use the UUID of the filesystem to mount it. Get it with:
dumpe2fs -h /dev/sda1 | grep UUID
Then replace the device name (in my case
/dev/hda1
) withUUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
At this point (well, you obviously still need to wait for the pvmove
to end), you can reboot right now. Your boot loader setup will use your old /boot
partition and the kernel will use the root filesystem on the usb disk.
Be aware of a few things, though.
- Your initrd image (which you must have, if you have your root partition under LVM) must include everything that is necessary to load usb devices before mounting the root partition
- Current mkinitramfs in Debian has a quite annoying bug, that makes impossible to have an LVM root partition on an usb disk: most of the time, the usb disk is detected after initialization of LVM. If that happens to you, you're not screwed: you can add
break=mount
to the kernel command line, and while you have a shell prompt, wait for the usb disk to come up and just exit the shell, it will continue the boot scripts and initialize LVM properly. On a recent enough initramfs, you can also specifyrootdelay=10
, replacing 10 with the number of seconds you want the boot to be delayed to wait for usb devices.
(mkinitramfs in Debian does)
You still need to do two things to finish your setup, now:
- Remove the laptop disk physical volume from the volume group:
vgreduce vg /dev/hda2
- Setup grub on the usb disk, so that you can boot off the disk directly if the BIOS supports it:
/usr/sbin/grub
grub> root (hd1,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup --prefix=/grub (hd1)
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd1)"... 15 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/menu.lst"... succeeded
Done.
grub> quit
You probably won't have to change the menu.lst file, because it must already be using
hd0
, which will be what grub sees for the usb disk when booting off it. Also note your usb disk might not be hd1 under grub, depending on the number of disks on your system.
Now you can have any computer run your system, booting off the usb disk. It had the nice side effect that my laptop is much faster now, as the internal disk is an old 4200 rpm disk, vs. 7200 rpm for the usb disk...
You may also want to try to remove the Xorg configuration file (/etc/X11/xorg.conf
) so that the video driver and resolution are not hardcoded ; recent enough Xorg do runtime detection, and that worked pretty well on the two laptops I booted with the usb disk.
2007-12-16 16:54:20+0900
Both comments and pings are currently closed.